ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictMgr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5#include "IdDict/IdDictMgr.h"
9#include "src/Debugger.h"
10#include <fstream>
11#include <iostream>
12
13#include <stdio.h>
14#include <cstdlib>
15#include <atomic>
16#include <stdexcept>
17#include <format>
18
19
21{
22public:
23 static int build_id();
24};
25
26template <class T>
27class TypeId
28{
29public:
30 operator int () {
31 static const int i = TypeIdBuilder::build_id();
32
33 return(i);
34 }
35};
36
38 static std::atomic<int> i = 0;
39
40 i++;
41 return(i);
42}
43
51
52IdDictMgr::~IdDictMgr() = default;
53
54const std::string& IdDictMgr::tag() const {
55 return m_tag;
56}
57
58const std::string& IdDictMgr::DTD_version() const {
59 return m_DTD_version;
60}
61
63 return m_do_checks;
64}
65
66void
69 for (const auto& p : m_dictionaries) {
70 p.second->set_do_checks(do_checks);
71 }
72}
73
75 return m_do_neighbours;
76}
77
78void
81 for (const auto& p : m_dictionaries) {
82 p.second->set_do_neighbours(do_neighbours);
83 }
84}
85
86const std::string&
87IdDictMgr::find_metadata(const std::string& name) const {
88 metadata_map::const_iterator it = m_metadata.find(name);
89 static const std::string empty;
90 if (it != m_metadata.end()) return(it->second);
91 else return empty;
92}
93
94void
95IdDictMgr::add_metadata(const std::string& name, const std::string& value) {
96 if (!m_metadata.insert(metadata_map::value_type(name, value)).second) {
97 std::cout << "IdDictMgr::add_metadata> unable to add name/value " << name << "/" << value << std::endl;
98 }
99}
100
101void
105
106std::vector<const IdDictDictionary*> IdDictMgr::get_dictionaries () const
107{
108 std::vector<const IdDictDictionary*> out;
109 out.reserve (m_dictionaries.size());
110 for (const auto& p : m_dictionaries) {
111 out.push_back (p.second.get());
112 }
113 return out;
114}
115
116const IdDictDictionary* IdDictMgr::find_dictionary(const std::string& name) const {
117 auto it = m_dictionaries.find(name);
118 if (it == m_dictionaries.end()) return nullptr;
119 return it->second.get();
120}
121
123 auto it = m_dictionaries.find(name);
124 if (it == m_dictionaries.end()) return nullptr;
125 return it->second.get();
126}
127
128void IdDictMgr::add_dictionary(std::unique_ptr<IdDictDictionary> dictionary) {
129 if (dictionary == 0) return;
130
131 const std::string& name = dictionary->name();
132
133 m_dictionaries[name] = std::move(dictionary);
134
135 if (Debugger::debug()) {
136 dictionary_map::iterator it;
137
138 for (const auto& p : m_dictionaries) {
139 std::cout << "IdDictMgr::add_dictionary> d[" << p.first << "]=" << p.second.get() << std::endl;
140 }
141 }
142}
143
144void IdDictMgr::add_subdictionary_name(const std::string& name) {
145 m_subdictionary_names.insert(name);
146}
147
149 for (auto& p : m_dictionaries) {
150 // From mgr, only resolve refs for top-level dictionaries
151 IdDictDictionary& dictionary = *p.second;
152 if (m_subdictionary_names.find(dictionary.name()) != m_subdictionary_names.end()) continue;
153 dictionary.resolve_references(*this);
154 }
155}
156
157void IdDictMgr::generate_implementation(const std::string& tag) {
158 if (Debugger::debug()) {
159 std::cout << "IdDictMgr::generate_implementation>" << std::endl;
160 }
161
162 // Must reset the implementation for multiple passes, this resets
163 // the generated flags
165
167 m_tag = tag;
168 for (auto& p : m_dictionaries) {
169 // From mgr, only generate impl for top-level dictionaries
170 IdDictDictionary& dictionary = *p.second;
171 if (m_subdictionary_names.find(dictionary.name()) != m_subdictionary_names.end()) continue;
172 dictionary.generate_implementation(*this, tag);
173 }
175 }
176}
177
179 std::cout << "IdDictMgr::reset_implementation" << std::endl;
180
181
183 for (auto& p : m_dictionaries) {
184 // From mgr, only generate impl for top-level dictionaries
185 IdDictDictionary& dictionary = *p.second;
186 if (m_subdictionary_names.find(dictionary.name()) != m_subdictionary_names.end()) continue;
187 dictionary.reset_implementation();
188 }
190 }
191}
192
193bool IdDictMgr::verify() const {
194 for (auto& p : m_dictionaries) {
195 if (!p.second->verify()) return(false);
196 }
197
198 return(true);
199}
200
202 m_dictionaries.clear();
203 m_resolved_references = false;
205}
static const Attributes_t empty
static bool debug()
Definition Debugger.h:18
void add_dictionary(std::unique_ptr< IdDictDictionary > dictionary)
Fillers:
const std::string & tag() const
Version tag.
Definition IdDictMgr.cxx:54
void resolve_references()
Construct dictionary after parsing.
void set_DTD_version(const std::string &DTD_version)
void add_metadata(const std::string &name, const std::string &value)
Definition IdDictMgr.cxx:95
void set_do_neighbours(bool do_neighbours)
Definition IdDictMgr.cxx:79
bool verify() const
metadata_map m_metadata
Definition IdDictMgr.h:75
bool do_checks() const
Check whether or not to do checks for ids.
Definition IdDictMgr.cxx:62
bool do_neighbours() const
Check whether or not to init neighbours.
Definition IdDictMgr.cxx:74
void set_do_checks(bool do_checks)
Definition IdDictMgr.cxx:67
dictionary_vec get_dictionaries() const
Access to all dictionaries.
void generate_implementation(const std::string &tag="")
void add_subdictionary_name(const std::string &name)
std::set< std::string > m_subdictionary_names
Definition IdDictMgr.h:76
dictionary_map m_dictionaries
Definition IdDictMgr.h:74
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
const std::string & find_metadata(const std::string &name) const
Access to meta data, name/value pairs.
Definition IdDictMgr.cxx:87
void reset_implementation()
Reset of implementation.
void clear()
bool m_do_neighbours
Definition IdDictMgr.h:80
std::string m_tag
Definition IdDictMgr.h:73
const std::string & DTD_version() const
DTD version.
Definition IdDictMgr.cxx:58
bool m_generated_implementation
Definition IdDictMgr.h:78
bool m_do_checks
Definition IdDictMgr.h:79
bool m_resolved_references
Definition IdDictMgr.h:77
std::string m_DTD_version
Definition IdDictMgr.h:72
static int build_id()
Definition IdDictMgr.cxx:37