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 73 of file BitSpec.h.

Member Function Documentation

◆ parse()

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

Definition at line 94 of file BitSpec.h.

94 {
95 const auto open = spec.find('[');
96
97 // No mask specification.
98 if (open == std::string_view::npos) {
99 return {
100 spec,
101 std::numeric_limits<std::uint64_t>::max(),
102 0,
103 false
104 };
105 }
106
107 // Expected: name[lo:hi] or name[bit]
108 const auto colon = spec.find(':', open + 1);
109 const auto close = spec.find(']', open + 1);
110
111 if (close == std::string_view::npos ||close != spec.size() - 1) {
112 throw std::invalid_argument("Invalid AuxSpec");
113 }
114
115 std::size_t pos = open + 1;
116 const std::size_t lo = parseNumber(spec, pos, colon == std::string_view::npos ? close : colon);
117
118 std::size_t hi = lo;
119
120 if (colon != std::string_view::npos) {
121 // Range: [lo:hi]
122 if (colon == open + 1 || colon + 1 == close) {
123 throw std::invalid_argument("Invalid AuxSpec range");
124 }
125 pos = colon + 1;
126 hi = parseNumber(spec, pos, close);
127 }
128
129 if (pos != close || lo > hi || hi >= 64)
130 throw std::invalid_argument("Invalid bit range");
131
132 const std::size_t width = hi - lo + 1;
133
134 const std::uint64_t mask =
135 width == 64
136 ? std::numeric_limits<std::uint64_t>::max()
137 : ((std::uint64_t{1} << width) - 1) << lo;
138
139 return {
140 spec.substr(0, open),
141 mask,
142 lo,
143 true
144 };
145 }
const double width
@ open
Definition BinningType.h:40
std::uint64_t mask
Definition BitSpec.h:75
static constexpr std::size_t parseNumber(std::string_view str, std::size_t &pos, std::size_t end)
Definition BitSpec.h:79

◆ parseNumber()

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

Definition at line 79 of file BitSpec.h.

79 {
80 std::size_t value{};
81 const auto [ptr, ec] = std::from_chars(
82 str.data() + pos,
83 str.data() + end,
84 value
85 );
86
87 if (ec != std::errc{})
88 throw std::invalid_argument("Expected number");
89
90 pos = ptr - str.data();
91 return value;
92 }
void * ptr(T *p)
Definition SGImplSvc.cxx:76

Member Data Documentation

◆ has_mask

bool GlobalSim::AuxSpec::has_mask {}

Definition at line 77 of file BitSpec.h.

77{};

◆ mask

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

Definition at line 75 of file BitSpec.h.

75{};

◆ name

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

Definition at line 74 of file BitSpec.h.

74{};

◆ shift

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

Definition at line 76 of file BitSpec.h.

76{};

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