ATLAS Offline Software
Loading...
Searching...
No Matches
DetectorDescription/Identifier/src/ExpandedIdentifier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7#include <cstdio>
8#include <cstring>
9#include <iomanip>
10#include <iostream>
11#include <charconv>
12#include <stdexcept>
13#include <ranges>
14
15static std::string
16show_vector (const ExpandedIdentifier::element_vector& v, const std::string & sep="/"){
17 if (v.empty()) return {};
18 std::string result = std::to_string(v.front());
19 for (auto value : v | std::views::drop(1)){
20 result+= sep + std::to_string(value);
21 }
22 return result;
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 return show_vector(m_fields);
57}
58
59void
61 std::cout<< "["<< show_vector (m_fields,".") <<"]";
62}
63
64std::ostream & operator << (std::ostream &out, const ExpandedIdentifier & x){
65 out<<std::string(x);
66 return out;
67}
68
69
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 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