TypeInfo.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "TypeInfo.hh"
18 //#include "TypeInfo.ih"
19 
20 // Custom includes
21 #include <cxxabi.h>
22 #include <malloc.h>
23 
24 //#include "TypeInfo.mpp"
25 #define prefix_
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 prefix_ std::string senf::prettyName(std::type_info const & type)
29 {
30  char const * mangled = type.name();
31  int status (0);
32  char * demangled ( abi::__cxa_demangle(mangled, 0, 0, &status) );
33  std::string name (demangled ? demangled : mangled);
34  if (demangled)
35  ::free(demangled);
36  return name;
37 }
38 
39 prefix_ std::string senf::prettyBaseName(std::type_info const & type)
40 {
41  std::string name (prettyName(type));
42  std::string::size_type e (name.find('<'));
43  if (e == std::string::npos) e = name.size();
44  std::string::size_type b (name.rfind(':', e));
45  if (b == std::string::npos) b = 0; else ++b;
46  return name.substr(b,e-b);
47 }
48 
49 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 #undef prefix_
51 //#include "TypeInfo.mpp"
52 
53 
54 // Local Variables:
55 // mode: c++
56 // fill-column: 100
57 // c-file-style: "senf"
58 // indent-tabs-mode: nil
59 // ispell-local-dictionary: "american"
60 // compile-command: "scons -u test"
61 // comment-column: 40
62 // End:
std::string prettyBaseName(std::type_info const &type)
Try to return readable type name without namespace or template arguments.
Definition: TypeInfo.cc:39
std::string prettyName(std::type_info const &type)
Try to return readable type for given type_info.
Definition: TypeInfo.cc:28
TypeInfo public header.
#define prefix_
Definition: TypeInfo.cc:25
unspecified_keyword_type name