ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::AuxSpec Struct Reference

#include <BitSpec.h>

Collaboration diagram for GlobalSim::AuxSpec:

Static Public Member Functions

static constexpr std::size_t parseNumber (std::string_view str, std::size_t &pos, std::size_t end)
static constexpr AuxSpec parse (std::string_view spec)

Public Attributes

std::string_view name {}
std::uint64_t mask {}
std::size_t shift {}
bool has_mask {}

Detailed Description

Definition at line 41 of file BitSpec.h.

Member Function Documentation

◆ parse()

constexpr AuxSpec GlobalSim::AuxSpec::parse ( std::string_view spec)
inlinestaticconstexpr

Definition at line 62 of file BitSpec.h.

62 {
63 const auto open = spec.find('[');
64
65 // No mask specification.
66 if (open == std::string_view::npos) {
67 return {
68 spec,
69 std::numeric_limits<std::uint64_t>::max(),
70 0,
71 false
72 };
73 }
74
75 // Expected: name[lo:hi] or name[bit]
76 const auto colon = spec.find(':', open + 1);
77 const auto close = spec.find(']', open + 1);
78
79 if (close == std::string_view::npos ||close != spec.size() - 1) {
80 throw std::invalid_argument("Invalid AuxSpec");
81 }
82
83 std::size_t pos = open + 1;
84 const std::size_t lo = parseNumber(spec, pos, colon == std::string_view::npos ? close : colon);
85
86 std::size_t hi = lo;
87
88 if (colon != std::string_view::npos) {
89 // Range: [lo:hi]
90 if (colon == open + 1 || colon + 1 == close) {
91 throw std::invalid_argument("Invalid AuxSpec range");
92 }
93 pos = colon + 1;
94 hi = parseNumber(spec, pos, close);
95 }
96
97 if (pos != close || lo > hi || hi >= 64)
98 throw std::invalid_argument("Invalid bit range");
99
100 const std::size_t width = hi - lo + 1;
101
102 const std::uint64_t mask =
103 width == 64
104 ? std::numeric_limits<std::uint64_t>::max()
105 : ((std::uint64_t{1} << width) - 1) << lo;
106
107 return {
108 spec.substr(0, open),
109 mask,
110 lo,
111 true
112 };
113 }
const double width
@ open
Definition BinningType.h:40
std::uint64_t mask
Definition BitSpec.h:43
static constexpr std::size_t parseNumber(std::string_view str, std::size_t &pos, std::size_t end)
Definition BitSpec.h:47

◆ parseNumber()

constexpr std::size_t GlobalSim::AuxSpec::parseNumber ( std::string_view str,
std::size_t & pos,
std::size_t end )
inlinestaticconstexpr

Definition at line 47 of file BitSpec.h.

47 {
48 std::size_t value{};
49 const auto [ptr, ec] = std::from_chars(
50 str.data() + pos,
51 str.data() + end,
52 value
53 );
54
55 if (ec != std::errc{})
56 throw std::invalid_argument("Expected number");
57
58 pos = ptr - str.data();
59 return value;
60 }
void * ptr(T *p)
Definition SGImplSvc.cxx:75

Member Data Documentation

◆ has_mask

bool GlobalSim::AuxSpec::has_mask {}

Definition at line 45 of file BitSpec.h.

45{};

◆ mask

std::uint64_t GlobalSim::AuxSpec::mask {}

Definition at line 43 of file BitSpec.h.

43{};

◆ name

std::string_view GlobalSim::AuxSpec::name {}

Definition at line 42 of file BitSpec.h.

42{};

◆ shift

std::size_t GlobalSim::AuxSpec::shift {}

Definition at line 44 of file BitSpec.h.

44{};

The documentation for this struct was generated from the following file: