CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
21  ~Demangle() { if (demangle) free((void*)demangle); }
22 
23 private:
24 
25  char * demangle;
26 };
27 
28 
29 template<class T>
30 inline std::string className(const T&t) {
31  return std::string(Demangle(typeid(t).name())());
32 }
33 
34 template<class T>
35 class ClassName {
36 public:
37  static const std::string & name() {
38  static const std::string ln(Demangle(typeid(T).name())());
39  return ln;
40  }
41 };
42 
43 #endif // UTILITIES_GENERAL_CLASSNAME_H
std::string firstNonNumeric(const char *sc)
Definition: ClassName.h:8
const char * operator()() const
Definition: ClassName.h:19
static const std::string & name()
Definition: ClassName.h:37
~Demangle()
Definition: ClassName.h:21
Demangle(const char *sc)
Definition: ClassName.cc:5
char * demangle
Definition: ClassName.h:25
long double T
std::string className(const T &t)
Definition: ClassName.h:30