Scarab  v3.9.1
Project 8 C++ Utility Library
typename.cc
Go to the documentation of this file.
1 /*
2  * typename.cc
3  *
4  * Created on: Feb 10, 2016
5  * Author: nsoblath
6  */
7 
8 #define SCARAB_API_EXPORTS
9 
10 #include "typename.hh"
11 
12 #ifdef __GNUG__
13 #include <cstdlib>
14 #include <memory>
15 #include <cxxabi.h>
16 #endif
17 
18 
19 namespace scarab
20 {
21 
22 #ifdef __GNUG__
23 #ifdef USE_CPP11
24 
25  std::string demangle( const char* a_name )
26  {
27 
28  int t_status = -4; // some arbitrary value to eliminate the compiler warning
29 
30  std::unique_ptr< char, void(*)( void* ) > res( abi::__cxa_demangle( a_name, NULL, NULL, &t_status ), std::free );
31 
32  return ( t_status==0 ) ? res.get() : a_name ;
33  }
34 
35 #else // USE_CPP11
36 
37  struct handle
38  {
39  char* f_ptr;
40  handle( char* a_ptr ) : f_ptr( a_ptr ) {}
41  ~handle() { std::free( f_ptr ); }
42  };
43 
44 
45  std::string demangle( const char* a_name )
46  {
47 
48  int t_status = -4; // some arbitrary value to eliminate the compiler warning
49 
50  handle result( abi::__cxa_demangle( a_name, NULL, NULL, &t_status ) );
51 
52  return ( t_status==0 ) ? result.f_ptr : a_name ;
53  }
54 
55 #endif // USE_CPP11
56 
57 #else // __GNUG__
58 
59  // does nothing if not g++
60  std::string demangle( const char* a_name ) {
61  return a_name;
62  }
63 
64 #endif // __GNUG__
65 
66 }
std::string demangle(const char *a_name)
Definition: typename.cc:60