|
phdMesh Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* phdMesh : Parallel Heterogneous Dynamic unstructured Mesh */ 00003 /* Copyright (2007) Sandia Corporation */ 00004 /* */ 00005 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00006 /* license for use of this work by or on behalf of the U.S. Government. */ 00007 /* */ 00008 /* This library is free software; you can redistribute it and/or modify */ 00009 /* it under the terms of the GNU Lesser General Public License as */ 00010 /* published by the Free Software Foundation; either version 2.1 of the */ 00011 /* License, or (at your option) any later version. */ 00012 /* */ 00013 /* This library is distributed in the hope that it will be useful, */ 00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00016 /* Lesser General Public License for more details. */ 00017 /* */ 00018 /* You should have received a copy of the GNU Lesser General Public */ 00019 /* License along with this library; if not, write to the Free Software */ 00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */ 00021 /* USA */ 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 /* DOXYGEN_COMPILE */ 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 } // namespace phdmesh 00148 00149 #endif 00150
1.7.4