CMS 3D CMS Logo

ClassName.h
Go to the documentation of this file.
1 #ifndef UTILITIES_GENERAL_CLASSNAME_H
2 #define UTILITIES_GENERAL_CLASSNAME_H
3 //
4 #include <typeinfo>
5 #include <string>
6 #include <cstdlib>
7 
8 inline std::string firstNonNumeric(const char* sc) {
9  std::string s(sc);
10  size_t pos = s.find_first_not_of("0123456789");
11  s.erase(0, pos);
12  return s;
13 }
14 
15 class Demangle {
16 public:
17  Demangle(const char* sc);
18 
19  const char* operator()() const { return demangle; }
20 
22  if (demangle)
23  free((void*)demangle);
24  }
25 
26 private:
27  char* demangle;
28 };
29 
30 template <class T>
31 inline std::string className(const T& t) {
32  return std::string(Demangle(typeid(t).name())());
33 }
34 
35 template <class T>
36 class ClassName {
37 public:
38  static const std::string& name() {
39  static const std::string ln(Demangle(typeid(T).name())());
40  return ln;
41  }
42 };
43 
44 #endif // UTILITIES_GENERAL_CLASSNAME_H
std::string firstNonNumeric(const char *sc)
Definition: ClassName.h:8
static const std::string & name()
Definition: ClassName.h:38
~Demangle()
Definition: ClassName.h:21
Demangle(const char *sc)
Definition: ClassName.cc:5
const char * operator()() const
Definition: ClassName.h:19
char * demangle
Definition: ClassName.h:27
long double T
std::string className(const T &t)
Definition: ClassName.h:31