CMS 3D CMS Logo

format_type_name.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWLite
4 // Class : format_type_name
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Thu Dec 3 16:52:50 CST 2009
11 //
12 
13 // system include files
14 #include <string>
15 
16 // user include files
18 
19 //
20 // constants, enums and typedefs
21 //
22 
23 //
24 // static data member definitions
25 //
26 
27 static const std::string s_symbolDemangled[] = {"::",
28  "_" ,
29  "," ,
30  " " ,
31  "&" ,
32  "*" ,
33  "<" ,
34  ">"
35  };
36 static const std::string s_symbolMangled[] = {"_1",
37  "_2",
38  "_3",
39  "_4",
40  "_7",
41  "_8",
42  "_9",
43  "_0"
44  };
45 static const unsigned int s_symbolToMangledSize = sizeof(s_symbolDemangled)/sizeof(std::string);
46 
47 namespace fwlite {
48 
49  void staticAssert() {
50  static_assert(sizeof(s_symbolMangled) == sizeof(s_symbolDemangled),"Arrays are not the same size.");
51  }
52 
55  std::string returnValue;
56  returnValue.append(static_cast<std::string::size_type>(iType.size()*2),' ');
57  std::string::size_type fromIndex=0;
58  std::string::size_type toIndex=0;
59  size_t sIndex=0;
60  for(;fromIndex<iType.size();++fromIndex) {
61  bool foundMatch = false;
62  for(sIndex=0;sIndex<s_symbolToMangledSize;) {
63  const std::string& symbol = s_symbolDemangled[sIndex];
64  if(iType.substr(fromIndex,symbol.size())==symbol) {
65  foundMatch = true;
66  break;
67  }
68  ++sIndex;
69  }
70  if(!foundMatch) {
71  returnValue[toIndex]=iType[fromIndex];
72  ++toIndex;
73  } else {
74  const std::string& mangled=s_symbolMangled[sIndex];
75  returnValue.replace(toIndex,mangled.size(),mangled);
76  toIndex += mangled.size();
77  fromIndex += s_symbolDemangled[sIndex].size()-1;
78  }
79  }
80  returnValue.resize(toIndex);
81  return returnValue;
82  }
83 
86  std::string returnValue;
87  returnValue.append(static_cast<std::string::size_type>(iMangled.size()*2),' ');
88  std::string::size_type fromIndex=0;
89  std::string::size_type toIndex=0;
90  size_t sIndex=0;
91  for(;fromIndex<iMangled.size();++fromIndex) {
92  bool foundMatch = false;
93  for(sIndex=0;sIndex<s_symbolToMangledSize;) {
94  const std::string& mangled = s_symbolMangled[sIndex];
95  if(iMangled.substr(fromIndex,mangled.size())==mangled) {
96  foundMatch = true;
97  break;
98  }
99  ++sIndex;
100  }
101  if(!foundMatch) {
102  returnValue[toIndex]=iMangled[fromIndex];
103  ++toIndex;
104  } else {
105  const std::string& symbol=s_symbolDemangled[sIndex];
106  returnValue.replace(toIndex,symbol.size(),symbol);
107  toIndex += symbol.size();
108  fromIndex += s_symbolMangled[sIndex].size()-1;
109  }
110  }
111  returnValue.resize(toIndex);
112  return returnValue;
113  }
114 
115 }
void staticAssert()
uint16_t size_type
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
static const std::string s_symbolDemangled[]
static const std::string s_symbolMangled[]
static const unsigned int s_symbolToMangledSize