ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
16template <typename Stream, typename CHAR>
17static 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
27 set (text);
28}
29
30
31void
32ExpandedIdentifier::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
55ExpandedIdentifier::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
62void
63ExpandedIdentifier::show (std::ostream & out) const {
64 out << '[';
65 stream_vector(out, m_fields, '.');
66 out << ']';
67}
68
69void
70ExpandedIdentifier::show (MsgStream & out) const {
71 out << '[';
72 stream_vector(out, m_fields, '.');
73 out << ']';
74}
75
76std::ostream & operator << (std::ostream &out, const ExpandedIdentifier& id) {
77 stream_vector(out, id.m_fields, '/');
78 return out;
79}
std::ostream & operator<<(std::ostream &out, const ExpandedIdentifier &id)
static void stream_vector(Stream &out, const ExpandedIdentifier::element_vector &v, CHAR sep)
void show(std::ostream &out) const
Display detail to ostream.
void set(const std::string &text)
build from a textual description
ExpandedIdentifier()=default
void add(element_type value)
Append a value into a new field.
void clear()
Erase all fields.
CxxUtils::inplace_vector< element_type, 12 > element_vector
MsgStream & msg
Definition testRead.cxx:32