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
16static std::string
17show_vector (const ExpandedIdentifier::element_vector& v, const std::string & sep="/"){
18 if (v.empty()) return {};
19 std::string result = std::to_string(v.front());
20 for (auto value : v | std::views::drop(1)){
21 result+= sep + std::to_string(value);
22 }
23 return result;
24}
25
26
28 set (text);
29}
30
31
32void
33ExpandedIdentifier::set (const std::string& text){
34 clear ();
35 if (text.empty()) return;
36 const char *start = text.c_str();
37 const char *last = start+text.size();
38 static constexpr auto ok=std::errc{};
39 int v{};
40 bool foundNumber{};
41 for (const char * p=start;p<last;++p){
42 auto [ptr,ec] = std::from_chars(p, last,v);
43 p=ptr;
44 if (ec != ok) continue;
45 add ((element_type) v);
46 foundNumber = true;
47 }
48 if (not foundNumber){
49 const std::string msg = "ExpandedIdentifier::set: '"+ text + "' is not a valid input string.";
50 throw std::invalid_argument(msg);
51 }
52}
53
54
55
56ExpandedIdentifier::operator std::string () const{
57 return show_vector(m_fields);
58}
59
60void
61ExpandedIdentifier::show (std::ostream & out) const{
62 out<< "["<< show_vector (m_fields,".") <<"]";
63}
64
65void
66ExpandedIdentifier::show (MsgStream & out) const{
67 out<< "["<< show_vector (m_fields,".") <<"]";
68}
69
70std::ostream & operator << (std::ostream &out, const ExpandedIdentifier & x){
71 out<<std::string(x);
72 return out;
73}
74
75
static std::string show_vector(const ExpandedIdentifier::element_vector &v, const std::string &sep="/")
std::ostream & operator<<(std::ostream &out, const ExpandedIdentifier &x)
#define x
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.
boost::container::small_vector< element_type, 12 > element_vector
void clear()
Erase all fields.
MsgStream & msg
Definition testRead.cxx:32