|
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_TypeName_hpp 00025 #define util_TypeName_hpp 00026 00027 #include <complex> 00028 #include <vector> 00029 #include <string> 00030 #include <typeinfo> 00031 00032 namespace phdmesh { 00033 00034 template< typename T > 00035 struct TypeName { 00036 static std::string value() { return std::string( typeid(T).name() ); } 00037 }; 00038 00039 //---------------------------------------------------------------------- 00040 00041 #define GENERATE_SIMPLE_TYPE_NAME_VALUE( T ) \ 00042 template<> struct TypeName< T > { \ 00043 static std::string value() { return std::string( # T ); } \ 00044 } 00045 00046 GENERATE_SIMPLE_TYPE_NAME_VALUE( void ); 00047 GENERATE_SIMPLE_TYPE_NAME_VALUE( char ); 00048 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned char ); 00049 GENERATE_SIMPLE_TYPE_NAME_VALUE( short ); 00050 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned short ); 00051 GENERATE_SIMPLE_TYPE_NAME_VALUE( int ); 00052 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned int ); 00053 GENERATE_SIMPLE_TYPE_NAME_VALUE( long ); 00054 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned long ); 00055 GENERATE_SIMPLE_TYPE_NAME_VALUE( float ); 00056 GENERATE_SIMPLE_TYPE_NAME_VALUE( double ); 00057 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::complex<float> ); 00058 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::complex<double> ); 00059 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::string ); 00060 00061 //---------------------------------------------------------------------- 00062 00063 template< typename T > 00064 struct TypeName< const T > 00065 { 00066 static std::string value() 00067 { return std::string( "const ").append( TypeName<T>::value() ); } 00068 }; 00069 00070 template< typename T > 00071 struct TypeName< T * > 00072 { 00073 static std::string value() 00074 { return std::string( TypeName<T>::value() ).append( " *" ); } 00075 }; 00076 00077 template< typename T > 00078 struct TypeName< T & > 00079 { 00080 static std::string value() 00081 { return std::string( TypeName<T>::value() ).append( " &" ); } 00082 }; 00083 00084 //---------------------------------------------------------------------- 00085 00086 std::string type_name_array( const std::string & , unsigned ); 00087 00088 template< typename T , unsigned N > 00089 struct TypeName< T[N] > 00090 { 00091 static std::string value() 00092 { return type_name_array( TypeName<T>::value() , N ); } 00093 }; 00094 00095 template< typename T > 00096 std::string type_name_array( unsigned n ) 00097 { return type_name_array( TypeName<T>::value() , n ); } 00098 00099 //---------------------------------------------------------------------- 00100 00101 std::string type_name_vector( const std::string & , unsigned = 0 ); 00102 00103 template< typename T > 00104 struct TypeName< std::vector<T> > 00105 { 00106 static std::string value() 00107 { return type_name_vector( TypeName<T>::value() ); } 00108 }; 00109 00110 template< typename T > 00111 std::string type_name_vector( unsigned n = 0 ) 00112 { return type_name_vector( TypeName<T>::value() , n ); } 00113 00114 //---------------------------------------------------------------------- 00115 00116 } // namespace phdmesh 00117 00118 #endif /* util_TypeName_hpp */ 00119
1.7.4