Dune Core Modules (2.4.1)

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 template <class T>
23 std::string className ( T &t )
24 {
25 std::string className = typeid( t ).name();
26#if HAVE_CXA_DEMANGLE
27 int status;
28 char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
29 if( demangled )
30 {
31 className = demangled;
32 std::free( demangled );
33 }
34#endif // #if HAVE_CXA_DEMANGLE
35 return className;
36 }
37
39 template <class T>
40 std::string className ()
41 {
42 std::string className = typeid( T ).name();
43#if HAVE_CXA_DEMANGLE
44 int status;
45 char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
46 if( demangled )
47 {
48 className = demangled;
49 std::free( demangled );
50 }
51#endif // #if HAVE_CXA_DEMANGLE
52 return className;
53 }
54
55} // namespace Dune
56
57#endif // DUNE_CLASSNAME_HH
Dune namespace.
Definition: alignment.hh:10
std::string className(T &t)
Provide the demangled class name of a given object as a string.
Definition: classname.hh:23
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)