ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
Identifier
src
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "
Identifier/ExpandedIdentifier.h
"
7
#include "GaudiKernel/MsgStream.h"
8
#include <cstdio>
9
#include <cstring>
10
#include <iomanip>
11
#include <iostream>
12
#include <charconv>
13
#include <stdexcept>
14
#include <ranges>
15
16
template
<
typename
Stream,
typename
CHAR>
17
static
void
stream_vector
(Stream& out,
const
ExpandedIdentifier::element_vector
& v, CHAR sep) {
18
if
(v.empty())
return
;
19
20
out << v.front();
21
for
(
auto
value : v | std::views::drop(1)) {
22
out << sep << value;
23
}
24
}
25
26
ExpandedIdentifier::ExpandedIdentifier
(
const
std::string& text){
27
set
(text);
28
}
29
30
31
void
32
ExpandedIdentifier::set
(
const
std::string& text){
33
clear
();
34
if
(text.empty())
return
;
35
const
char
*start = text.c_str();
36
const
char
*last = start+text.size();
37
static
constexpr
auto
ok=std::errc{};
38
int
v{};
39
bool
foundNumber{};
40
for
(
const
char
* p=start;p<last;++p){
41
auto
[ptr,ec] = std::from_chars(p, last,v);
42
p=ptr;
43
if
(ec != ok)
continue
;
44
add
((
element_type
) v);
45
foundNumber =
true
;
46
}
47
if
(not foundNumber){
48
const
std::string
msg
=
"ExpandedIdentifier::set: '"
+ text +
"' is not a valid input string."
;
49
throw
std::invalid_argument(
msg
);
50
}
51
}
52
53
54
55
ExpandedIdentifier::operator std::string ()
const
{
56
// If a string is explicitly requested, we use stringstream to generate it
57
std::ostringstream oss;
58
stream_vector
(oss,
m_fields
,
'/'
);
59
return
oss.str();
60
}
61
62
void
63
ExpandedIdentifier::show
(std::ostream & out)
const
{
64
out <<
'['
;
65
stream_vector
(out,
m_fields
,
'.'
);
66
out <<
']'
;
67
}
68
69
void
70
ExpandedIdentifier::show
(MsgStream & out)
const
{
71
out <<
'['
;
72
stream_vector
(out,
m_fields
,
'.'
);
73
out <<
']'
;
74
}
75
76
std::ostream &
operator <<
(std::ostream &out,
const
ExpandedIdentifier
&
id
) {
77
stream_vector
(out,
id
.
m_fields
,
'/'
);
78
return
out;
79
}
ExpandedIdentifier.h
operator<<
std::ostream & operator<<(std::ostream &out, const ExpandedIdentifier &id)
Definition
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:76
stream_vector
static void stream_vector(Stream &out, const ExpandedIdentifier::element_vector &v, CHAR sep)
Definition
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:17
ExpandedIdentifier::show
void show(std::ostream &out) const
Display detail to ostream.
Definition
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:63
ExpandedIdentifier::m_fields
element_vector m_fields
Definition
DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:168
ExpandedIdentifier::set
void set(const std::string &text)
build from a textual description
Definition
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx:32
ExpandedIdentifier::ExpandedIdentifier
ExpandedIdentifier()=default
ExpandedIdentifier::add
void add(element_type value)
Append a value into a new field.
ExpandedIdentifier::clear
void clear()
Erase all fields.
ExpandedIdentifier::element_type
int element_type
Definition
DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:109
ExpandedIdentifier::element_vector
CxxUtils::inplace_vector< element_type, 12 > element_vector
Definition
DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:110
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0