Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Zero.hpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00020 #include<ImLib3D/Image3D.hpp>
00021 
00022 #ifndef _Zero_hpp
00023 #define _Zero_hpp
00024 
00025 #include<ImLib3D/Complex.hpp>
00026 #include<ImLib3D/Vect3D.hpp>
00027 #include<ImLib3D/Vect2D.hpp>
00028 #include<boost/type_traits.hpp>
00029 
00031 template<typename T,bool isArithmetic=boost::is_arithmetic<T>::value >
00032 struct SetZero
00033 {
00034     static bool Set(T &v,bool fail=true){v=0;return true;}
00035 };
00036 
00037 template<typename T>
00038 struct SetZero<T,false>
00039 {
00040     static bool Set(T &v,bool fail=true)
00041     {
00042         if(fail)
00043         {
00044             ThrowError("SetZero failed for type %s. Please overload the templated struct SetZero function for this template type. Look at %s for an example",TypeName<T>(),__FILE__);
00045         }
00046         return false;
00047     }
00048 };
00049 
00050 template<> struct SetZero<complexf,false> { static bool Set(complexf &v,bool fail=true){v=0;return true;} };
00051 template<> struct SetZero<complexd,false> { static bool Set(complexd &v,bool fail=true){v=0;return true;} };
00052 template<> struct SetZero<Vect3Df ,false> { static bool Set(Vect3Df  &v,bool fail=true){v=0;return true;} };
00053 template<> struct SetZero<Vect3Di ,false> { static bool Set(Vect3Di  &v,bool fail=true){v=0;return true;} };
00054 template<> struct SetZero<Vect2Df ,false> { static bool Set(Vect3Df  &v,bool fail=true){v=0;return true;} };
00055 template<> struct SetZero<Vect2Di ,false> { static bool Set(Vect3Di  &v,bool fail=true){v=0;return true;} };
00056 
00057 template<typename T>
00058 T Zero()
00059 {
00060     T res;
00061     SetZero<T>::Set(res);
00062     return res;
00063 }
00064 
00065 #endif // _Zero_hpp

Generated on Fri Jun 17 13:36:10 2005 for ImLib3D by  doxygen 1.4.2