ATLAS Offline Software
Loading...
Searching...
No Matches
Identifier.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/Identifier.h"
7#include "GaudiKernel/MsgStream.h"
8#include <charconv>
9#include <iostream>
10
11
12template <typename Stream>
13void streamIdentifier(Stream& os, unsigned long long id) {
14 //This is faster than std::format and uses no allocations.
15 //Please don't switch to std::format without performance checks
16 char buf[32];
17 buf[0] = '0';
18 buf[1] = 'x';
19 auto [ptr, ec] = std::to_chars(buf + 2, buf + sizeof(buf), id, 16);
20
21 os << std::string_view(buf, ptr);
22}
23
24
25void Identifier::set (std::string_view id){
26 const auto start = id.data();
27 const auto end = start + id.size();
28 static constexpr int base = 16;
29 //add 2 to start to get past the Ox prefix.
30 const auto [p,ec] = std::from_chars(start+2, end, m_id, base);
31 if (ec != std::errc()){
32 throw std::runtime_error("Number was not parsed in Identifier::set");
33 }
34}
35
36
37std::string Identifier::getString() const {
38 //This is faster than std::format when checked
39 //Please don't switch to std::format without performance checks
40 char buf[32];
41 buf[0] = '0';
42 buf[1] = 'x';
43 auto [ptr, ec] = std::to_chars(buf + 2, buf + sizeof(buf), m_id, 16);
44 return std::string(buf, ptr);
45}
46
47void Identifier::show(std::ostream& out) const {
49}
50
51void Identifier::show(MsgStream& out) const {
53}
54
55MsgStream& operator<<(MsgStream& f, const Identifier& id) {
56 streamIdentifier(f, id.get_compact());
57 return f;
58}
59
60std::ostream& operator<<(std::ostream& os, const Identifier& id) {
61 streamIdentifier(os, id.get_compact());
62 return os;
63}
64
void streamIdentifier(Stream &os, unsigned long long id)
MsgStream & operator<<(MsgStream &f, const Identifier &id)
std::string getString() const
Provide a string form of the identifier - hexadecimal.
void show(std::ostream &out) const
Print out in hex form.
void set(std::string_view id)
build from a string form - hexadecimal
std::string base
Definition hcg.cxx:83