00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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