File indexing completed on 2024-04-06 12:01:20
0001 #include "CommonTools/Utils/interface/returnType.h"
0002
0003 #include "FWCore/Reflection/interface/FunctionWithDict.h"
0004 #include "FWCore/Reflection/interface/TypeWithDict.h"
0005
0006 #include <algorithm>
0007 #include <cstring>
0008 #include <string>
0009 #include <vector>
0010
0011 using namespace reco::method;
0012 using namespace std;
0013
0014 namespace reco {
0015
0016 edm::TypeWithDict returnType(const edm::FunctionWithDict& func) { return func.finalReturnType(); }
0017
0018 TypeCode returnTypeCode(const edm::FunctionWithDict& func) { return typeCode(returnType(func)); }
0019
0020
0021 static const std::vector<std::pair<char const* const, method::TypeCode> > retTypeVec{
0022 {"bool", boolType},
0023 {"char", charType},
0024 {"double", doubleType},
0025 {"float", floatType},
0026 {"int", intType},
0027 {"long", longType},
0028 {"long int", longType},
0029 {"short", shortType},
0030 {"short int", shortType},
0031 {"size_t", uLongType},
0032 {"unsigned char", uCharType},
0033 {"unsigned int", uIntType},
0034 {"unsigned long", uLongType},
0035 {"unsigned long int", uLongType},
0036 {"unsigned short", uShortType},
0037 {"unsigned short int", uShortType}};
0038
0039 TypeCode typeCode(const edm::TypeWithDict& t) {
0040 typedef std::pair<const char* const, method::TypeCode> Values;
0041 std::string name = t.name();
0042 auto f = std::equal_range(
0043 retTypeVec.begin(),
0044 retTypeVec.end(),
0045 Values{name.c_str(), enumType},
0046 [](const Values& iLHS, const Values& iRHS) -> bool { return std::strcmp(iLHS.first, iRHS.first) < 0; });
0047 if (f.first == f.second) {
0048 return t.isEnum() ? enumType : invalid;
0049 }
0050 return f.first->second;
0051 }
0052
0053 }