Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
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
49
50
#include "
Teuchos_ConstTypeTraits.hpp
"
51
52
// mfh 30 Jan 2013: Thanks to Jim Willenbring for reporting this, and
53
// to Mike Glass and Paul Lin for updating the fix for dealing with a
54
// bug in IBM's XL C++ compiler. The update was necessary due to a
55
// relapse of the bug in a newer version of the compiler.
56
//
57
// If you don't have this update, you can fix the problem by defining
58
// the macro TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM when compiling anything
59
// that includes this header file. If you have the current version of
60
// this file, then you don't need to do anything.
61
#if defined(__IBMCPP__) && ( __IBMCPP__ < 900 || __IBMCPP__ == 1210 )
62
# define TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
63
#endif
64
65
#include <typeinfo>
66
67
namespace
Teuchos
{
68
69
77
TEUCHOSCORE_LIB_DLL_EXPORT
std::string
demangleName
(
const
std::string &mangledName );
78
79
84
template
<
typename
T>
85
class
TypeNameTraits
{
86
public
:
88
static
std::string
name
()
89
{
90
return
demangleName
(
typeid
(T).
name
());
91
}
92
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
ConstTypeTraits<T>::NonConstType
ncT;
118
#ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
119
return
TypeNameTraits<ncT>::concreteName
(t);
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
ConstTypeTraits<T>::NonConstType
ncT;
141
return
TypeNameTraits<ncT>::concreteName
(t);
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
153
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
bool
);
154
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
char
);
155
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
signed
char
);
156
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
unsigned
char
);
157
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
short
int
);
158
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
int
);
159
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
long
int
);
160
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
unsigned
short
int
);
161
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
unsigned
int
);
162
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
unsigned
long
int
);
163
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
float
);
164
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
double
);
165
166
#ifdef HAVE_TEUCHOSCORE_QUADMATH
167
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(__float128);
168
#endif
// HAVE_TEUCHOSCORE_QUADMATH
169
170
#ifdef HAVE_TEUCHOS_LONG_DOUBLE
171
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
(
long
double
);
172
#endif
// HAVE_TEUCHOS_LONG_DOUBLE
173
174
template
<
typename
T>
175
class
TEUCHOSCORE_LIB_DLL_EXPORT
TypeNameTraits
<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
<>
184
class
TEUCHOSCORE_LIB_DLL_EXPORT
TypeNameTraits
<
std
::string> {
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
<>
193
class
TEUCHOSCORE_LIB_DLL_EXPORT
TypeNameTraits
<void*> {
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
<>
206
class
TEUCHOSCORE_LIB_DLL_EXPORT
TypeNameTraits
<void> {
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_
Teuchos_ConstTypeTraits.hpp
TEUCHOSCORE_LIB_DLL_EXPORT
#define TEUCHOSCORE_LIB_DLL_EXPORT
Definition
Teuchos_DLLExportMacro.h:9
TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION
#define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE)
Definition
Teuchos_TypeNameTraits.hpp:145
Teuchos::ConstTypeTraits::NonConstType
UnConst< T >::Result NonConstType
Definition
Teuchos_ConstTypeTraits.hpp:69
Teuchos::TypeNameTraits< T * >::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:178
Teuchos::TypeNameTraits< T * >::T_ptr
T * T_ptr
Definition
Teuchos_TypeNameTraits.hpp:177
Teuchos::TypeNameTraits< T * >::concreteName
static std::string concreteName(T_ptr)
Definition
Teuchos_TypeNameTraits.hpp:179
Teuchos::TypeNameTraits< std::string >::concreteName
static std::string concreteName(const std::string &)
Definition
Teuchos_TypeNameTraits.hpp:187
Teuchos::TypeNameTraits< std::string >::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:186
Teuchos::TypeNameTraits< void >::concreteName
static std::string concreteName(const std::string &)
Definition
Teuchos_TypeNameTraits.hpp:209
Teuchos::TypeNameTraits< void >::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:208
Teuchos::TypeNameTraits< void * >::concreteName
static std::string concreteName(const std::string &)
Definition
Teuchos_TypeNameTraits.hpp:196
Teuchos::TypeNameTraits< void * >::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:195
Teuchos::TypeNameTraits
Default traits class that just returns typeid(T).name().
Definition
Teuchos_TypeNameTraits.hpp:85
Teuchos::TypeNameTraits::concreteName
static std::string concreteName(const T &t)
Definition
Teuchos_TypeNameTraits.hpp:94
Teuchos::TypeNameTraits::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:88
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::typeName
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Definition
Teuchos_TypeNameTraits.hpp:115
Teuchos::concreteTypeName
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object.
Definition
Teuchos_TypeNameTraits.hpp:138
Teuchos::demangleName
TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName(const std::string &mangledName)
Demangle a C++ name if valid.
Definition
Teuchos_TypeNameTraits.cpp:53
std
Definition
DefaultMpiComm_TagTests.cpp:51
Generated by
1.17.0