DUNE-FEM (unstable)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_CLASSNAME_HH
6#define DUNE_CLASSNAME_HH
7
13#include <cstdlib>
14#include <memory>
15#include <string>
16#include <typeinfo>
17#include <type_traits>
18
19#if __has_include(<cxxabi.h>) && !DISABLE_CXA_DEMANGLE
20#define HAVE_CXA_DEMANGLE 1
21#include <cxxabi.h>
22#endif // #if HAVE_CXA_DEMANGLE
23
24namespace Dune {
25
26 namespace Impl {
27
28 inline std::string demangle(std::string name)
29 {
30#if HAVE_CXA_DEMANGLE
31 int status;
32 std::unique_ptr<char, void(*)(void*)>
33 demangled(abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status),
34 std::free);
35 if( demangled )
36 name = demangled.get();
37#endif // #if HAVE_CXA_DEMANGLE
38 return name;
39 }
40 }
41
43 /*
44 * \ingroup CxxUtilities
45 */
46 template <class T>
47 std::string className ()
48 {
49 typedef typename std::remove_reference<T>::type TR;
50 std::string className = Impl::demangle( typeid( TR ).name() );
51 if (std::is_const<TR>::value)
52 className += " const";
53 if (std::is_volatile<TR>::value)
54 className += " volatile";
55 if (std::is_lvalue_reference<T>::value)
56 className += "&";
57 else if (std::is_rvalue_reference<T>::value)
58 className += "&&";
59 return className;
60 }
61
63 /*
64 * \ingroup CxxUtilities
65 */
66 template <class T>
67 std::string className ( T&& v)
68 {
69 typedef typename std::remove_reference<T>::type TR;
70 std::string className = Impl::demangle( typeid(v).name() );
71 if (std::is_const<TR>::value)
72 className += " const";
73 if (std::is_volatile<TR>::value)
74 className += " volatile";
75 return className;
76 }
77} // namespace Dune
78
79#endif // DUNE_CLASSNAME_HH
Dune namespace.
Definition: alignedallocator.hh:13
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:47
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)