File indexing completed on 2024-04-06 12:04:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <string>
0015
0016
0017 #include "DataFormats/FWLite/interface/format_type_name.h"
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 static const std::string s_symbolDemangled[] = {"::", "_", ",", " ", "&", "*", "<", ">"};
0028 static const std::string s_symbolMangled[] = {"_1", "_2", "_3", "_4", "_7", "_8", "_9", "_0"};
0029 static const unsigned int s_symbolToMangledSize = sizeof(s_symbolDemangled) / sizeof(std::string);
0030
0031 namespace fwlite {
0032
0033 void staticAssert() {
0034 static_assert(sizeof(s_symbolMangled) == sizeof(s_symbolDemangled), "Arrays are not the same size.");
0035 }
0036
0037
0038 std::string format_type_to_mangled(const std::string& iType) {
0039 std::string returnValue;
0040 returnValue.append(static_cast<std::string::size_type>(iType.size() * 2), ' ');
0041 std::string::size_type fromIndex = 0;
0042 std::string::size_type toIndex = 0;
0043 size_t sIndex = 0;
0044 for (; fromIndex < iType.size(); ++fromIndex) {
0045 bool foundMatch = false;
0046 for (sIndex = 0; sIndex < s_symbolToMangledSize;) {
0047 const std::string& symbol = s_symbolDemangled[sIndex];
0048 if (iType.substr(fromIndex, symbol.size()) == symbol) {
0049 foundMatch = true;
0050 break;
0051 }
0052 ++sIndex;
0053 }
0054 if (!foundMatch) {
0055 returnValue[toIndex] = iType[fromIndex];
0056 ++toIndex;
0057 } else {
0058 const std::string& mangled = s_symbolMangled[sIndex];
0059 returnValue.replace(toIndex, mangled.size(), mangled);
0060 toIndex += mangled.size();
0061 fromIndex += s_symbolDemangled[sIndex].size() - 1;
0062 }
0063 }
0064 returnValue.resize(toIndex);
0065 return returnValue;
0066 }
0067
0068
0069 std::string unformat_mangled_to_type(const std::string& iMangled) {
0070 std::string returnValue;
0071 returnValue.append(static_cast<std::string::size_type>(iMangled.size() * 2), ' ');
0072 std::string::size_type fromIndex = 0;
0073 std::string::size_type toIndex = 0;
0074 size_t sIndex = 0;
0075 for (; fromIndex < iMangled.size(); ++fromIndex) {
0076 bool foundMatch = false;
0077 for (sIndex = 0; sIndex < s_symbolToMangledSize;) {
0078 const std::string& mangled = s_symbolMangled[sIndex];
0079 if (iMangled.substr(fromIndex, mangled.size()) == mangled) {
0080 foundMatch = true;
0081 break;
0082 }
0083 ++sIndex;
0084 }
0085 if (!foundMatch) {
0086 returnValue[toIndex] = iMangled[fromIndex];
0087 ++toIndex;
0088 } else {
0089 const std::string& symbol = s_symbolDemangled[sIndex];
0090 returnValue.replace(toIndex, symbol.size(), symbol);
0091 toIndex += symbol.size();
0092 fromIndex += s_symbolMangled[sIndex].size() - 1;
0093 }
0094 }
0095 returnValue.resize(toIndex);
0096 return returnValue;
0097 }
0098
0099 }