File indexing completed on 2023-03-17 11:26:46
0001 #ifndef UTILITIES_GENERAL_CLASSNAME_H
0002 #define UTILITIES_GENERAL_CLASSNAME_H
0003
0004 #include <typeinfo>
0005 #include <string>
0006 #include <cstdlib>
0007
0008 inline std::string firstNonNumeric(const char* sc) {
0009 std::string s(sc);
0010 size_t pos = s.find_first_not_of("0123456789");
0011 s.erase(0, pos);
0012 return s;
0013 }
0014
0015 class Demangle {
0016 public:
0017 Demangle(const char* sc);
0018
0019 const char* operator()() const { return demangle; }
0020
0021 ~Demangle() {
0022 if (demangle)
0023 free((void*)demangle);
0024 }
0025
0026 private:
0027 char* demangle;
0028 };
0029
0030 template <class T>
0031 inline std::string className(const T& t) {
0032 return std::string(Demangle(typeid(t).name())());
0033 }
0034
0035 template <class T>
0036 class ClassName {
0037 public:
0038 static const std::string& name() {
0039 static const std::string ln(Demangle(typeid(T).name())());
0040 return ln;
0041 }
0042 };
0043
0044 #endif