demangle_util.h
Go to the documentation of this file.
1 #ifndef DEMANGLE_UTIL_H
2 #define DEMANGLE_UTIL_H
3 
4 #include <string>
5 
6 
7 #if defined( __clang__ ) && defined( __has_include )
8 # if __has_include(<cxxabi.h>)
9 # define HAS_CXXABI_H
10 # endif
11 #elif defined( __GLIBCXX__ ) || defined( __GLIBCPP__ )
12 # define HAS_CXXABI_H
13 #endif
14 
15 #if defined( HAS_CXXABI_H )
16 # include <cxxabi.h>
17 # include <cstdlib>
18 # include <cstddef>
19 #endif
20 
21 namespace BT
22 {
23 
24 inline char const * demangle_alloc( char const * name ) noexcept;
25 inline void demangle_free( char const * name ) noexcept;
26 
28 {
29 private:
30  char const * m_p;
31 
32 public:
33  explicit scoped_demangled_name( char const * name ) noexcept :
34  m_p( demangle_alloc( name ) )
35  {
36  }
37 
39  {
40  demangle_free( m_p );
41  }
42 
43  char const * get() const noexcept
44  {
45  return m_p;
46  }
47 
50 };
51 
52 
53 #if defined( HAS_CXXABI_H )
54 
55 inline char const * demangle_alloc( char const * name ) noexcept
56 {
57  int status = 0;
58  std::size_t size = 0;
59  return abi::__cxa_demangle( name, NULL, &size, &status );
60 }
61 
62 inline void demangle_free( char const * name ) noexcept
63 {
64  std::free( const_cast< char* >( name ) );
65 }
66 
67 inline std::string demangle( char const * name )
68 {
69  scoped_demangled_name demangled_name( name );
70  char const * const p = demangled_name.get();
71  if( p )
72  {
73  return p;
74  }
75  else
76  {
77  return name;
78  }
79 }
80 
81 #else
82 
83 inline char const * demangle_alloc( char const * name ) noexcept
84 {
85  return name;
86 }
87 
88 inline void demangle_free( char const * ) noexcept
89 {
90 }
91 
92 inline std::string demangle( char const * name )
93 {
94  return name;
95 }
96 
97 #endif
98 
99 } // namespace BT
100 
101 #undef HAS_CXXABI_H
102 
103 #endif // DEMANGLE_UTIL_H
char const * get() const noexcept
Definition: demangle_util.h:43
scoped_demangled_name & operator=(scoped_demangled_name const &)=delete
scoped_demangled_name(char const *name) noexcept
Definition: demangle_util.h:33
std::string demangle(char const *name)
Definition: demangle_util.h:92
char const * demangle_alloc(char const *name) noexcept
Definition: demangle_util.h:83
~scoped_demangled_name() noexcept
Definition: demangle_util.h:38
void demangle_free(char const *name) noexcept
Definition: demangle_util.h:88


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sun Feb 3 2019 03:14:32