ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
IdDict
src
IdDictField.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/IdDictField.h
"
6
#include "
IdDict/IdDictLabel.h
"
7
#include <stdexcept>
8
#include <format>
9
#include <iostream>
10
11
12
IdDictField::IdDictField
(
const
std::string&
name
)
13
:
m_name
(
name
)
14
{
15
}
16
17
// Define these out-of-line so header doesn't need to include IdDictLabel.h.
18
IdDictField::IdDictField
(
IdDictField
&&) =
default
;
19
IdDictField::~IdDictField
() =
default
;
20
IdDictField
&
IdDictField::operator=
(
IdDictField
&&) =
default
;
21
22
23
24
bool
IdDictField::verify
()
const
{
25
return
(
true
);
26
}
27
28
const
IdDictLabel
*
IdDictField::find_label
(
const
std::string&
name
)
const
{
29
for
(
const
auto
& p :
m_labels
) {
30
if
(p && p->name() ==
name
)
return
p.get();
31
}
32
return
nullptr
;
33
}
34
35
void
36
IdDictField::add_label
(std::unique_ptr<const IdDictLabel>
label
) {
37
m_labels
.push_back(std::move(
label
));
38
}
39
40
void
41
IdDictField::set_index
(
size_t
index
){
42
m_index
=
index
;
43
}
44
45
size_t
46
IdDictField::get_label_number
()
const
{
47
return
m_labels
.size();
48
}
49
50
const
std::string&
51
IdDictField::get_label
(
size_t
index
)
const
{
52
try
{
53
return
m_labels
.at(
index
)->name();
54
}
catch
(std::out_of_range& e) {
55
throw
std::out_of_range(std::format(
"IdDictField::get_label : Attempt to access index {} in vector of size {}"
,
56
index
,
m_labels
.size()));
57
}
58
}
59
60
ExpandedIdentifier::element_type
61
IdDictField::get_label_value
(
const
std::string&
name
)
const
{
62
ExpandedIdentifier::element_type
value{0};
63
if
(std::ranges::find_if(
name
,[](
const
char
c){
return
!std::isdigit(c); }) !=
name
.end()) {
64
for
(
const
auto
&
label
:
m_labels
) {
65
if
(!
label
)
continue
;
66
if
(
label
->valued()) value =
label
->value();
67
if
(
label
->name() ==
name
) {
68
return
(value);
69
}
70
value++;
71
}
72
}
73
try
{
74
value = std::stoi(
name
);
75
return
value;
76
}
catch
(
const
std::invalid_argument& e) {
77
std::cerr <<
"Warning : label "
<<
name
<<
" not found: "
<<e.what() << std::endl;
78
}
79
80
return
(0);
81
}
82
83
void
IdDictField::clear
() {
84
m_labels
.clear();
85
}
IdDictField.h
IdDictLabel.h
ExpandedIdentifier::element_type
int element_type
Definition
DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:109
IdDictField
Definition
IdDictField.h:16
IdDictField::get_label_number
size_t get_label_number() const
Definition
IdDictField.cxx:46
IdDictField::get_label
const std::string & get_label(size_t index) const
Definition
IdDictField.cxx:51
IdDictField::m_name
std::string m_name
Definition
IdDictField.h:60
IdDictField::label
const IdDictLabel & label(size_t index) const
Definition
IdDictField.h:81
IdDictField::set_index
void set_index(size_t index)
Definition
IdDictField.cxx:41
IdDictField::verify
bool verify() const
Definition
IdDictField.cxx:24
IdDictField::clear
void clear()
Definition
IdDictField.cxx:83
IdDictField::~IdDictField
~IdDictField()
IdDictField::operator=
IdDictField & operator=(IdDictField &&)
IdDictField::get_label_value
ExpandedIdentifier::element_type get_label_value(const std::string &name) const
Definition
IdDictField.cxx:61
IdDictField::name
const std::string & name() const
Definition
IdDictField.h:67
IdDictField::m_labels
std::vector< std::unique_ptr< const IdDictLabel > > m_labels
Definition
IdDictField.h:61
IdDictField::IdDictField
IdDictField(const std::string &name)
Definition
IdDictField.cxx:12
IdDictField::m_index
size_t m_index
Definition
IdDictField.h:62
IdDictField::find_label
const IdDictLabel * find_label(const std::string &name) const
Definition
IdDictField.cxx:28
IdDictField::add_label
void add_label(std::unique_ptr< const IdDictLabel > label)
Definition
IdDictField.cxx:36
IdDictLabel
Definition
IdDictLabel.h:10
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0