ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include <stdexcept>
8#include <format>
9#include <iostream>
10
11
12IdDictField::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.
21
22
23
24bool IdDictField::verify() const {
25 return(true);
26}
27
28const 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
35void
36IdDictField::add_label(std::unique_ptr<const IdDictLabel> label) {
37 m_labels.push_back(std::move(label));
38}
39
40void
44
45size_t
47 return m_labels.size();
48}
49
50const std::string&
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
61IdDictField::get_label_value(const std::string& name) const {
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
84 m_labels.clear();
85}
size_t get_label_number() const
const std::string & get_label(size_t index) const
std::string m_name
Definition IdDictField.h:60
const IdDictLabel & label(size_t index) const
Definition IdDictField.h:81
void set_index(size_t index)
bool verify() const
IdDictField & operator=(IdDictField &&)
ExpandedIdentifier::element_type get_label_value(const std::string &name) const
const std::string & name() const
Definition IdDictField.h:67
std::vector< std::unique_ptr< const IdDictLabel > > m_labels
Definition IdDictField.h:61
IdDictField(const std::string &name)
size_t m_index
Definition IdDictField.h:62
const IdDictLabel * find_label(const std::string &name) const
void add_label(std::unique_ptr< const IdDictLabel > label)
Definition index.py:1