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 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef _TEUCHOS_TYPE_NAME_TRAITS_HPP_
43 #define _TEUCHOS_TYPE_NAME_TRAITS_HPP_
44 
50 // mfh 30 Jan 2013: Thanks to Jim Willenbring for reporting this, and
51 // to Mike Glass and Paul Lin for updating the fix for dealing with a
52 // bug in IBM's XL C++ compiler. The update was necessary due to a
53 // relapse of the bug in a newer version of the compiler.
54 //
55 // If you don't have this update, you can fix the problem by defining
56 // the macro TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM when compiling anything
57 // that includes this header file. If you have the current version of
58 // this file, then you don't need to do anything.
59 #if defined(__IBMCPP__) && ( __IBMCPP__ < 900 || __IBMCPP__ == 1210 )
60 # define TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
61 #endif
62 
63 #include <typeinfo>
64 
65 #include "Teuchos_ConfigDefs.hpp"
66 
67 namespace Teuchos {
68 
69 
77 TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName( const std::string &mangledName );
78 
79 
84 template<typename T>
86 public:
88  static std::string name()
89  {
90  return demangleName(typeid(T).name());
91  }
93 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
94  static std::string concreteName( const T& t )
95 #else
96  // the IBM compilers on AIX have a problem with const
97  static std::string concreteName( T t )
98 #endif
99  {
100  return demangleName(typeid(t).name());
101  }
102 };
103 
104 
114 template<typename T>
115 std::string typeName( const T &t )
116 {
117  typedef typename std::remove_const_t<T> ncT;
118 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
120 #else
121  // You can't pass general objects to AIX by value as above. This means that
122  // you will not get the concrete name printed on AIX but that is life on
123  // such compilers.
124  return TypeNameTraits<ncT>::name();
125 #endif
126 }
127 
128 
137 template<typename T>
138 std::string concreteTypeName( const T &t )
139 {
140  typedef typename std::remove_const_t<T> ncT;
142 }
143 
144 
145 #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \
146 template<> \
147 class TypeNameTraits<TYPE> { \
148 public: \
149  static std::string name() { return (#TYPE); } \
150  static std::string concreteName(const TYPE&) { return name(); } \
151 } \
152 
165 
166 #ifdef HAVE_TEUCHOSCORE_QUADMATH
168 #endif // HAVE_TEUCHOSCORE_QUADMATH
169 
170 #ifdef HAVE_TEUCHOS_LONG_DOUBLE
172 #endif // HAVE_TEUCHOS_LONG_DOUBLE
173 
174 template<typename T>
176 public:
177  typedef T* T_ptr;
178  static std::string name() { return TypeNameTraits<T>::name() + "*"; }
179  static std::string concreteName(T_ptr) { return name(); }
180 };
181 
182 
183 template<>
185 public:
186  static std::string name() { return "string"; }
187  static std::string concreteName(const std::string&)
188  { return name(); }
189 };
190 
191 
192 template<>
194 public:
195  static std::string name() { return "void*"; }
196  static std::string concreteName(const std::string&) { return name(); }
197 };
198 
199 // mfh 31 Jul 2012: Specialization for "void" will hopefully fix
200 // compile errors on Windows, such as the following:
201 //
202 // http://testing.sandia.gov/cdash/viewBuildError.php?buildid=611137
203 //
204 // I'm imitating the specialization of void* above.
205 template<>
207 public:
208  static std::string name() { return "void"; }
209  static std::string concreteName(const std::string&) { return name(); }
210 };
211 
212 
213 #ifdef HAVE_TEUCHOS_COMPLEX
214 
215 
216 template<typename T>
217 class TEUCHOSCORE_LIB_DLL_EXPORT TypeNameTraits<std::complex<T> > {
218 public:
219  static std::string name()
220  { return "complex<"+TypeNameTraits<T>::name()+">"; }
221  static std::string concreteName(const std::complex<T>&)
222  { return name(); }
223 };
224 
225 
226 #endif // HAVE_TEUCHOS_COMPLEX
227 
228 
229 
230 } // namespace Teuchos
231 
232 
233 #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 &)