Dune Core Modules (2.6.0)

classname.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_CLASSNAME_HH
4#define DUNE_CLASSNAME_HH
5
11#include <cstdlib>
12#include <string>
13#include <typeinfo>
14
15#if HAVE_CXA_DEMANGLE
16#include <cxxabi.h>
17#endif // #if HAVE_CXA_DEMANGLE
18
19namespace Dune {
20
22 /*
23 * \ingroup CxxUtilities
24 */
25 template <class T>
26 std::string className ()
27 {
28 typedef typename std::remove_reference<T>::type TR;
29 std::string className = typeid( TR ).name();
30#if HAVE_CXA_DEMANGLE
31 int status;
32 char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
33 if( demangled )
34 {
35 className = demangled;
36 std::free( demangled );
37 }
38#endif // #if HAVE_CXA_DEMANGLE
39 if (std::is_const<TR>::value)
40 className += " const";
41 if (std::is_volatile<TR>::value)
42 className += " volatile";
43 if (std::is_lvalue_reference<T>::value)
44 className += "&";
45 else if (std::is_rvalue_reference<T>::value)
46 className += "&&";
47 return className;
48 }
49
51 /*
52 * \ingroup CxxUtilities
53 */
54 template <class T>
55 std::string className ( T& )
56 {
57 return className<T>();
58 }
59} // namespace Dune
60
61#endif // DUNE_CLASSNAME_HH
Dune namespace.
Definition: alignedallocator.hh:10
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:26
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)