phdMesh  Version of the Day
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
TypeName.hpp
1 /*------------------------------------------------------------------------*/
2 /* phdMesh : Parallel Heterogneous Dynamic unstructured Mesh */
3 /* Copyright (2007) Sandia Corporation */
4 /* */
5 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
6 /* license for use of this work by or on behalf of the U.S. Government. */
7 /* */
8 /* This library is free software; you can redistribute it and/or modify */
9 /* it under the terms of the GNU Lesser General Public License as */
10 /* published by the Free Software Foundation; either version 2.1 of the */
11 /* License, or (at your option) any later version. */
12 /* */
13 /* This library is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
16 /* Lesser General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU Lesser General Public */
19 /* License along with this library; if not, write to the Free Software */
20 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 */
21 /* USA */
22 /*------------------------------------------------------------------------*/
23 
24 #ifndef util_TypeName_hpp
25 #define util_TypeName_hpp
26 
27 #include <complex>
28 #include <vector>
29 #include <string>
30 #include <typeinfo>
31 
32 namespace phdmesh {
33 
34 template< typename T >
35 struct TypeName {
36  static std::string value() { return std::string( typeid(T).name() ); }
37 };
38 
39 //----------------------------------------------------------------------
40 
41 #define GENERATE_SIMPLE_TYPE_NAME_VALUE( T ) \
42  template<> struct TypeName< T > { \
43  static std::string value() { return std::string( # T ); } \
44  }
45 
46 GENERATE_SIMPLE_TYPE_NAME_VALUE( void );
47 GENERATE_SIMPLE_TYPE_NAME_VALUE( char );
48 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned char );
49 GENERATE_SIMPLE_TYPE_NAME_VALUE( short );
50 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned short );
51 GENERATE_SIMPLE_TYPE_NAME_VALUE( int );
52 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned int );
53 GENERATE_SIMPLE_TYPE_NAME_VALUE( long );
54 GENERATE_SIMPLE_TYPE_NAME_VALUE( unsigned long );
55 GENERATE_SIMPLE_TYPE_NAME_VALUE( float );
56 GENERATE_SIMPLE_TYPE_NAME_VALUE( double );
57 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::complex<float> );
58 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::complex<double> );
59 GENERATE_SIMPLE_TYPE_NAME_VALUE( std::string );
60 
61 //----------------------------------------------------------------------
62 
63 template< typename T >
64 struct TypeName< const T >
65 {
66  static std::string value()
67  { return std::string( "const ").append( TypeName<T>::value() ); }
68 };
69 
70 template< typename T >
71 struct TypeName< T * >
72 {
73  static std::string value()
74  { return std::string( TypeName<T>::value() ).append( " *" ); }
75 };
76 
77 template< typename T >
78 struct TypeName< T & >
79 {
80  static std::string value()
81  { return std::string( TypeName<T>::value() ).append( " &" ); }
82 };
83 
84 //----------------------------------------------------------------------
85 
86 std::string type_name_array( const std::string & , unsigned );
87 
88 template< typename T , unsigned N >
89 struct TypeName< T[N] >
90 {
91  static std::string value()
92  { return type_name_array( TypeName<T>::value() , N ); }
93 };
94 
95 template< typename T >
96 std::string type_name_array( unsigned n )
97 { return type_name_array( TypeName<T>::value() , n ); }
98 
99 //----------------------------------------------------------------------
100 
101 std::string type_name_vector( const std::string & , unsigned = 0 );
102 
103 template< typename T >
104 struct TypeName< std::vector<T> >
105 {
106  static std::string value()
107  { return type_name_vector( TypeName<T>::value() ); }
108 };
109 
110 template< typename T >
111 std::string type_name_vector( unsigned n = 0 )
112 { return type_name_vector( TypeName<T>::value() , n ); }
113 
114 //----------------------------------------------------------------------
115 
116 } // namespace phdmesh
117 
118 #endif /* util_TypeName_hpp */
119