File indexing completed on 2024-04-06 12:18:23
0001 #ifndef defaultModuleLabel_h
0002 #define defaultModuleLabel_h
0003
0004
0005 #include <string>
0006
0007
0008 #include <boost/version.hpp>
0009 #if BOOST_VERSION < 105200
0010 #include <boost/units/detail/utility.hpp>
0011 #else
0012 #include <boost/core/demangle.hpp>
0013 #endif
0014
0015 template <typename T>
0016 std::string defaultModuleLabel() {
0017
0018 #if BOOST_VERSION < 105200
0019 std::string name = boost::units::detail::demangle(typeid(T).name());
0020 #else
0021 std::string name = boost::core::demangle(typeid(T).name());
0022 #endif
0023
0024
0025 unsigned int size = 0;
0026 for (char c : name)
0027 if (std::isalnum(c))
0028 ++size;
0029 std::string label;
0030 label.reserve(size);
0031
0032
0033
0034 bool new_token = false;
0035 for (char c : name) {
0036 if (std::isalnum(c)) {
0037 if (new_token)
0038 label.push_back((char)std::toupper(c));
0039 else
0040 label.push_back(c);
0041 new_token = false;
0042 } else {
0043 new_token = true;
0044 }
0045 }
0046
0047
0048
0049
0050 unsigned int ups = 0;
0051 for (char c : label)
0052 if (std::isupper(c))
0053 ++ups;
0054 else
0055 break;
0056 if (ups > 1 and ups != label.size())
0057 --ups;
0058 for (unsigned int i = 0; i < ups; ++i)
0059 label[i] = std::tolower(label[i]);
0060
0061 return label;
0062 }
0063
0064 #endif