CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
defaultModuleLabel.h
Go to the documentation of this file.
1 #ifndef defaultModuleLabel_h
2 #define defaultModuleLabel_h
3 
4 // C++ headers
5 #include <string>
6 
7 // boost headers
8 #include <boost/version.hpp>
9 #if BOOST_VERSION < 105200
10 #include <boost/units/detail/utility.hpp>
11 #else
12 #include <boost/core/demangle.hpp>
13 #endif
14 
15 template <typename T>
17  // start with the demangled name for T
18 #if BOOST_VERSION < 105200
19  std::string name = boost::units::detail::demangle(typeid(T).name());
20 #else
21  std::string name = boost::core::demangle(typeid(T).name());
22 #endif
23 
24  // expected size of the label
25  unsigned int size = 0;
26  for (char c: name)
27  if (std::isalnum(c)) ++size;
29  label.reserve(size);
30 
31  // tokenize the demangled name, keeping only alphanumeric characters,
32  // and convert the tokens to lowerCamelCase.
33  bool new_token = false;
34  for (char c: name) {
35  if (std::isalnum(c)) {
36  if (new_token)
37  label.push_back((char) std::toupper(c));
38  else
39  label.push_back(c);
40  new_token = false;
41  }
42  else {
43  new_token = true;
44  }
45  }
46 
47  // if the label is all uppercase, change it to all lowercase
48  // if the label starts with more than one uppercase letter, change n-1 to lowercase
49  // otherwise, change the first letter to lowercase
50  unsigned int ups = 0;
51  for (char c: label)
52  if (std::isupper(c))
53  ++ups;
54  else
55  break;
56  if (ups > 1 and ups != label.size())
57  --ups;
58  for (unsigned int i = 0; i < ups; ++i)
59  label[i] = std::tolower(label[i]);
60 
61  return label;
62 }
63 
64 #endif // defaultModuleLabel_h
std::string defaultModuleLabel()
int i
Definition: DBlmapReader.cc:9
long double T
tuple size
Write out results.