Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_TypeNameTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef _TEUCHOS_TYPE_NAME_TRAITS_HPP_
11 #define _TEUCHOS_TYPE_NAME_TRAITS_HPP_
12 
18 // mfh 30 Jan 2013: Thanks to Jim Willenbring for reporting this, and
19 // to Mike Glass and Paul Lin for updating the fix for dealing with a
20 // bug in IBM's XL C++ compiler. The update was necessary due to a
21 // relapse of the bug in a newer version of the compiler.
22 //
23 // If you don't have this update, you can fix the problem by defining
24 // the macro TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM when compiling anything
25 // that includes this header file. If you have the current version of
26 // this file, then you don't need to do anything.
27 #if defined(__IBMCPP__) && ( __IBMCPP__ < 900 || __IBMCPP__ == 1210 )
28 # define TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
29 #endif
30 
31 #include <typeinfo>
32 
33 #include "Teuchos_ConfigDefs.hpp"
34 
35 namespace Teuchos {
36 
37 
45 TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName( const std::string &mangledName );
46 
47 
52 template<typename T>
54 public:
56  static std::string name()
57  {
58  return demangleName(typeid(T).name());
59  }
61 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
62  static std::string concreteName( const T& t )
63 #else
64  // the IBM compilers on AIX have a problem with const
65  static std::string concreteName( T t )
66 #endif
67  {
68  return demangleName(typeid(t).name());
69  }
70 };
71 
72 
82 template<typename T>
83 std::string typeName( const T &t )
84 {
85  typedef typename std::remove_const_t<T> ncT;
86 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
88 #else
89  // You can't pass general objects to AIX by value as above. This means that
90  // you will not get the concrete name printed on AIX but that is life on
91  // such compilers.
93 #endif
94 }
95 
96 
105 template<typename T>
106 std::string concreteTypeName( const T &t )
107 {
108  typedef typename std::remove_const_t<T> ncT;
110 }
111 
112 
113 #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \
114 template<> \
115 class TypeNameTraits<TYPE> { \
116 public: \
117  static std::string name() { return (#TYPE); } \
118  static std::string concreteName(const TYPE&) { return name(); } \
119 } \
120 
133 
134 #ifdef HAVE_TEUCHOSCORE_QUADMATH
136 #endif // HAVE_TEUCHOSCORE_QUADMATH
137 
138 #ifdef HAVE_TEUCHOS_LONG_DOUBLE
140 #endif // HAVE_TEUCHOS_LONG_DOUBLE
141 
142 template<typename T>
144 public:
145  typedef T* T_ptr;
146  static std::string name() { return TypeNameTraits<T>::name() + "*"; }
147  static std::string concreteName(T_ptr) { return name(); }
148 };
149 
150 
151 template<>
153 public:
154  static std::string name() { return "string"; }
155  static std::string concreteName(const std::string&)
156  { return name(); }
157 };
158 
159 
160 template<>
162 public:
163  static std::string name() { return "void*"; }
164  static std::string concreteName(const std::string&) { return name(); }
165 };
166 
167 // mfh 31 Jul 2012: Specialization for "void" will hopefully fix
168 // compile errors on Windows, such as the following:
169 //
170 // http://testing.sandia.gov/cdash/viewBuildError.php?buildid=611137
171 //
172 // I'm imitating the specialization of void* above.
173 template<>
175 public:
176  static std::string name() { return "void"; }
177  static std::string concreteName(const std::string&) { return name(); }
178 };
179 
180 
181 #ifdef HAVE_TEUCHOS_COMPLEX
182 
183 
184 template<typename T>
185 class TEUCHOSCORE_LIB_DLL_EXPORT TypeNameTraits<std::complex<T> > {
186 public:
187  static std::string name()
188  { return "complex<"+TypeNameTraits<T>::name()+">"; }
189  static std::string concreteName(const std::complex<T>&)
190  { return name(); }
191 };
192 
193 
194 #endif // HAVE_TEUCHOS_COMPLEX
195 
196 
197 
198 } // namespace Teuchos
199 
200 
201 #endif // _TEUCHOS_TYPE_NAME_TRAITS_HPP_
static std::string concreteName(const T &t)
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName(const std::string &mangledName)
Demangle a C++ name if valid.
static std::string concreteName(T_ptr)
static std::string concreteName(const std::string &)
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
static std::string concreteName(const std::string &)
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object...
#define TEUCHOSCORE_LIB_DLL_EXPORT
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(bool)
Default traits class that just returns typeid(T).name().
static std::string concreteName(const std::string &)