00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef util_NumericEnum_hpp
00025 #define util_NumericEnum_hpp
00026
00027 #include <complex>
00028 #include <util/Basics.hpp>
00029 #include <util/TypeList.hpp>
00030
00031 namespace phdmesh {
00032
00056 #ifndef DOXYGEN_COMPILE
00057
00058 typedef TypeList< void ,
00059 TypeList< signed char ,
00060 TypeList< unsigned char ,
00061 TypeList< signed short ,
00062 TypeList< unsigned short ,
00063 TypeList< signed int ,
00064 TypeList< unsigned int ,
00065 TypeList< signed long ,
00066 TypeList< unsigned long ,
00067 TypeList< float ,
00068 TypeList< double ,
00069 TypeList< std::complex<float> ,
00070 TypeList< std::complex<double> ,
00071
00072 TypeList< void * ,
00073 TypeList< signed char * ,
00074 TypeList< unsigned char * ,
00075 TypeList< signed short * ,
00076 TypeList< unsigned short * ,
00077 TypeList< signed int * ,
00078 TypeList< unsigned int * ,
00079 TypeList< signed long * ,
00080 TypeList< unsigned long * ,
00081 TypeList< float * ,
00082 TypeList< double * ,
00083 TypeList< std::complex<float> * ,
00084 TypeList< std::complex<double> * ,
00085
00086 TypeListEnd > > > > > > > > > > > > >
00087 > > > > > > > > > > > > > NumericTypeList ;
00088
00089 #endif
00090
00091 template<typename Type = void> struct NumericEnum ;
00092
00096 template<>
00097 struct NumericEnum<void> {
00098
00099 enum { length = TypeListLength<NumericTypeList>::value };
00100 enum { minimum = 1 };
00101 enum { maximum = length - 1 };
00102
00104 static const char * name( unsigned ordinal );
00105
00107 static unsigned size( unsigned ordinal );
00108
00109 enum { value = TypeListIndex< NumericTypeList , void>::value };
00110
00111 private:
00112
00113 enum { OK = StaticAssert< TypeListUnique<NumericTypeList>::value >::OK };
00114 };
00115
00117 template<typename Type>
00118 struct NumericEnum {
00119
00123 enum { value
00124 #ifndef DOXYGEN_COMPILE
00125 = TypeListIndex<NumericTypeList,Type>::value
00126 #endif
00127 };
00128
00129 private:
00130 enum { OK = StaticAssert<
00131 (0 < (int) value) &&
00132 ((int) value < (int) NumericEnum<void>::length) >::OK };
00133 };
00134
00136 template<unsigned Ordinal>
00137 struct NumericType {
00138 #ifndef DOXYGEN_COMPILE
00139 typedef typename TypeListAt< NumericTypeList , Ordinal >::type type ;
00140 #endif
00141 private:
00142 enum { OK = StaticAssert< Ordinal < NumericEnum<>::length >::OK };
00143 };
00144
00147 }
00148
00149 #endif
00150