demangle.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later OR BSD-3-Clause
2 /***************************************************************************
3  * Copyright (C) 2019 by Robert Middleton. *
4  * robert.middleton@rm5248.com *
5  * *
6  * This file is part of the dbus-cxx library. *
7  ***************************************************************************/
8 
9 #ifndef DBUSCXX_DEMANGLE_H
10 #define DBUSCXX_DEMANGLE_H
11 
12 #include <string>
13 #include <typeinfo>
15 
16 #if DBUS_CXX_HAS_CXXABI_H
17  #include <cxxabi.h>
18 #endif
19 
20 namespace DBus {
24 template <typename T>
25 std::string demangle() {
26 #if DBUS_CXX_HAS_CXA_DEMANGLE
27  int status;
28  T arg1;
29  char* demangled = abi::__cxa_demangle( typeid( arg1 ).name(), nullptr, nullptr, &status );
30  std::string arg1_name( demangled );
31  free( demangled );
32 
33  if( status < 0 ) {
34  arg1_name = typeid( T ).name();
35  }
36 
37 #else
38  std::string arg1_name = typeid( T ).name();
39 #endif
40 
41  return arg1_name;
42 }
43 
44 } /* namespace DBus */
45 
46 #endif
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
std::string demangle()
demangle the given type.
Definition: demangle.h:25