A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TypeName.cc
Go to the documentation of this file.
1 
2 #ifndef TYPE_NAME_CC
3 #define TYPE_NAME_CC
4 
5 #include <cstddef>
6 #include <iostream>
7 #include <vector>
8 #include <algorithm>
9 #include <iterator>
10 #include <memory>
11 #include <cstring>
12 #ifndef _MSC_VER
13 #include <cxxabi.h>
14 #endif
15 
16 namespace pdb {
17 
18 // helper for getTypeName bleow... from
19 // http://stackoverflow.com/questions/25103885/how-to-demangle-stdstring-as-stdstring
20 inline void filter(std::string& r, const char* b) {
21  const char* e = b;
22  for (; *e; ++e)
23  ;
24  const char* pb = "std::__1::";
25  const int pl = strlen(pb);
26  const char* pe = pb + pl;
27  while (true) {
28  const char* x = std::search(b, e, pb, pe);
29  r.append(b, x);
30  if (x == e)
31  break;
32  r += "std::";
33  b = x + pl;
34  }
35 }
36 
37 template <class T>
38 std::string getTypeName() {
39  std::unique_ptr<char, void (*)(void*)> own(
40 #ifndef _MSC_VER
41  __cxxabiv1::__cxa_demangle(typeid(T).name(), nullptr, nullptr, nullptr),
42 #else
43  nullptr,
44 #endif
45  std::free);
46 
47  std::string r;
48  if (own) {
49  filter(r, own.get());
50  } else {
51  r = typeid(T).name();
52  }
53  r.erase(remove_if(r.begin(), r.end(), ::isspace), r.end());
54  return r;
55 }
56 }
57 #endif
std::string getTypeName()
Definition: TypeName.cc:38
void filter(std::string &r, const char *b)
Definition: TypeName.cc:20