ATLAS Offline Software
Loading...
Searching...
No Matches
CLIDRegistry.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
3 */
4
7#include <unordered_map>
8#include <mutex>
9
10
12{
13public:
14 bool hasNewEntries() const;
15
17
18 const std::type_info* CLIDToTypeinfo (CLID clid) const;
19 CLID typeinfoToCLID (const std::type_info& ti) const;
20
21 bool addEntry (unsigned long clid,
22 const std::type_info& ti,
23 const char* typeName,
24 const std::string& typeInfoName);
25
26
27private:
28 typedef std::mutex mutex_t;
29 typedef std::lock_guard<mutex_t> lock_t;
31
33 size_t m_alreadyDone = 0;
34
35 typedef std::unordered_map<CLID, const std::type_info*> clid_ti_map_t;
37
38 typedef std::unordered_map<const std::type_info*, CLID> ti_clid_map_t;
40};
41
42
44{
45 lock_t lock (m_mutex);
46 return m_alreadyDone < m_vec.size();
47}
48
49
52{
53 lock_t lock (m_mutex);
54 size_t pos = m_alreadyDone;
55 m_alreadyDone = m_vec.size();
56 return CLIDRegistry::CLIDVector_t (m_vec.begin()+pos, m_vec.end());
57}
58
59
66const std::type_info* CLIDRegistryImpl::CLIDToTypeinfo (CLID clid) const
67{
68 lock_t lock (m_mutex);
69 auto i = m_clid_ti_map.find (clid);
70 if (i != m_clid_ti_map.end()) {
71 return i->second;
72 }
73 return nullptr;
74}
75
76
83CLID CLIDRegistryImpl::typeinfoToCLID (const std::type_info& ti) const
84{
85 lock_t lock (m_mutex);
86 auto i = m_ti_clid_map.find (&ti);
87 if (i != m_ti_clid_map.end()) {
88 return i->second;
89 }
90 return CLID_NULL;
91}
92
93
94bool CLIDRegistryImpl::addEntry (unsigned long clid,
95 const std::type_info& ti,
96 const char* typeName,
97 const std::string& typeInfoName)
98{
99 lock_t lock (m_mutex);
100 m_vec.emplace_back (clid, std::string(typeName), typeInfoName);
101 m_clid_ti_map[clid] = &ti;
102 m_ti_clid_map[&ti] = clid;
103 return true;
104}
105
106
107//***************************************************************************
108
109
110bool
115
118{
119 return impl().newEntries();
120}
121
122
124{
126 return reg;
127}
128
129
136const std::type_info* CLIDRegistry::CLIDToTypeinfo (CLID clid)
137{
138 return impl().CLIDToTypeinfo (clid);
139}
140
141
148CLID CLIDRegistry::typeinfoToCLID (const std::type_info& ti)
149{
150 return impl().typeinfoToCLID (ti);
151}
152
153
155bool CLIDRegistry::addEntry (unsigned long clid,
156 const std::type_info& ti,
157 const char* typeName,
158 const std::string& typeInfoName)
159{
160 return impl().addEntry (clid, ti, typeName, typeInfoName);
161}
162
a static registry of CLID->typeName entries.
uint32_t CLID
The Class ID type.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
const std::type_info * CLIDToTypeinfo(CLID clid) const
Return the type_info corresponding to a CLID.
bool addEntry(unsigned long clid, const std::type_info &ti, const char *typeName, const std::string &typeInfoName)
std::unordered_map< const std::type_info *, CLID > ti_clid_map_t
std::lock_guard< mutex_t > lock_t
CLID typeinfoToCLID(const std::type_info &ti) const
Return the CLID corresponding to a type_info.
ti_clid_map_t m_ti_clid_map
bool hasNewEntries() const
CLIDRegistry::CLIDVector_t newEntries()
CLIDRegistry::CLIDVector_t m_vec
std::unordered_map< CLID, const std::type_info * > clid_ti_map_t
clid_ti_map_t m_clid_ti_map
static bool addEntry(const std::type_info &ti, const char *typeName, const std::string &typeInfoName)
to be called by the CLASS_DEFS
static CLIDRegistryImpl & impl()
static CLID typeinfoToCLID(const std::type_info &ti)
Return the CLID corresponding to a type_info.
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
std::vector< tuple_t > CLIDVector_t
static bool hasNewEntries()
registry accessors (used by ClassIDSvc)
static CLIDVector_t newEntries()
returns an iterator range over the entries added since last time newEntries was called