File indexing completed on 2023-03-17 11:03:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <cstring>
0015 #include "oneapi/tbb/concurrent_unordered_map.h"
0016
0017
0018 #include "FWCore/Utilities/interface/typelookup.h"
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 namespace {
0029 struct StringEqual {
0030 bool operator()(const char* iLHS, const char* iRHS) const { return (std::strcmp(iLHS, iRHS) == 0); }
0031 };
0032
0033
0034
0035
0036
0037 template <unsigned u, unsigned long long ull>
0038 struct select_size_t_constant {
0039
0040
0041 static constexpr size_t value = (size_t)((sizeof(size_t) == sizeof(u)) ? u : ull);
0042 };
0043
0044 constexpr size_t hash_multiplier = select_size_t_constant<2654435769U, 11400714819323198485ULL>::value;
0045
0046 struct StringHash {
0047 inline size_t operator()(const char* s) const {
0048 size_t h = 0;
0049 for (const char* c = s; *c; ++c)
0050 h = static_cast<size_t>(*c) ^ (h * hash_multiplier);
0051 return h;
0052 }
0053 };
0054
0055
0056
0057 using TypeNameToValueMap =
0058 oneapi::tbb::concurrent_unordered_map<const char*, const std::type_info*, StringHash, StringEqual>;
0059
0060 TypeNameToValueMap& typeNameToValueMap() {
0061 static TypeNameToValueMap s_map;
0062 return s_map;
0063 }
0064 }
0065
0066 edm::typelookup::NameRegistrar::NameRegistrar(const char* iTypeName, const std::type_info& iInfo) {
0067 typeNameToValueMap().insert(std::pair<const char*, const std::type_info*>(iTypeName, &iInfo));
0068 }
0069
0070 std::pair<const char*, const std::type_info*> edm::typelookup::findType(const char* iTypeName) {
0071 auto itFind = typeNameToValueMap().find(iTypeName);
0072
0073 if (itFind == typeNameToValueMap().end()) {
0074 return std::make_pair(static_cast<const char*>(nullptr), static_cast<std::type_info*>(nullptr));
0075 }
0076
0077 return (*itFind);
0078 }