Go to the documentation of this file.00001 #ifndef UTILITIES_GENERAL_CLASSNAME_H
00002 #define UTILITIES_GENERAL_CLASSNAME_H
00003
00004 #include <typeinfo>
00005 #include <string>
00006 #include <cstdlib>
00007
00008 inline std::string firstNonNumeric(const char * sc) {
00009 std::string s(sc);
00010 size_t pos = s.find_first_not_of("0123456789");
00011 s.erase(0,pos);
00012 return s;
00013 }
00014
00015 class Demangle {
00016 public:
00017 Demangle(const char * sc);
00018
00019 const char * operator()() const { return demangle;}
00020
00021 ~Demangle() { if (demangle) free((void*)demangle); }
00022
00023 private:
00024
00025 char * demangle;
00026 };
00027
00028
00029 template<class T>
00030 inline std::string className(const T&t) {
00031 return std::string(Demangle(typeid(t).name())());
00032 }
00033
00034 template<class T>
00035 class ClassName {
00036 public:
00037 static const std::string & name() {
00038 static const std::string ln(Demangle(typeid(T).name())());
00039 return ln;
00040 }
00041 };
00042
00043 #endif // UTILITIES_GENERAL_CLASSNAME_H