ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifierField.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef IDENTIFIER_IDENTIFIERFIELD_H
6#define IDENTIFIER_IDENTIFIERFIELD_H
7
9#include <vector>
10#include <string>
11#include <stdexcept>
12#include <iostream>
13#include <limits>
14#include <utility>
15#include <variant>
16
17class MsgStream;
18
85{
86 public :
89 using element_vector = std::vector <element_type>;
90 using index_vector = std::vector <size_type>;
91 using BoundedRange = std::pair<element_type, element_type>;
92 static constexpr auto minimum_possible = std::numeric_limits<element_type>::min();
93 static constexpr auto maximum_possible = std::numeric_limits<element_type>::max();
94 static constexpr auto invalidValues = element_vector{};
95
103
105 IdentifierField () = default;
106
109
111 IdentifierField (element_type minimum, element_type maximum);
112
114 IdentifierField (const element_vector &values);
115
116 //
117 inline bool
120
121 //
122 inline element_type
123 get_minimum() const {return m_minimum;}
124
125 //
126 inline std::pair<element_type, element_type>
127 get_minmax() const {
128 return {m_minimum, m_maximum};
129 }
130 //
131 inline element_type
132 get_maximum () const {return m_maximum;}
133 //
134 inline const element_vector&
135 get_values() const {
136 if (isBounded()) return invalidValues;
137 return std::get<element_vector>(m_data);
138 }
139
140 bool get_previous (element_type current, element_type& previous) const;
141 bool get_next (element_type current, element_type& next) const;
142 size_type get_indices () const {return m_size;}
143 const index_vector& get_indexes () const {return m_indexes;}
145 size_type get_bits () const;
148
151 bool match (element_type value) const;
152
155 bool overlaps_with (const IdentifierField& other) const;
156
158 void clear ();
159 void set (element_type minimum, element_type maximum);
160 void add_value (element_type value);
161 void set (const element_vector& values);
162 void set (bool wraparound);
163 void set_next (int next);
164 void set_previous (int previous);
168 void operator |= (const IdentifierField& other);
169
170 operator std::string () const;
171 bool operator == (const IdentifierField& other) const;
172
173 void show(std::ostream & out = std::cout) const;
174 void show(MsgStream & out) const;
175
178
181 void optimize();
182
185 inline bool empty() const {return m_empty;}
187 inline bool isBounded() const {return std::holds_alternative<BoundedRange>(m_data);}
188 inline bool isEnumerated() const {return std::holds_alternative<element_vector>(m_data);}
189
190private :
191 static constexpr int m_maxNumberOfIndices = 100;
194
196 void create_index_table();
197 template <class T>
198 T * dataPtr(){return std::get_if<T>(&m_data);}
199 //
202 std::variant<element_vector, BoundedRange> m_data{};
207 bool m_empty{true};
209};
210
213 // Only both_bounded and enumerated are valid to calculate the
214 // value.
215 // both_bounded is the more frequent case and so comes first.
216 if (m_empty) return 0;
217 if (const auto * p{std::get_if<BoundedRange>(&m_data)}; p) {
218 if (index >= (size_type) (p->second - p->first + 1)) {
219 throw std::out_of_range("IdentifierField::get_value_at");
220 }
221 return (p->first + index);
222 }
223 return ((std::get<element_vector>(m_data)).at(index));
224
225}
226
227std::ostream &
228operator << (std::ostream &out, const IdentifierField &c);
229std::istream &
230operator >> (std::istream &in, IdentifierField &c);
231#endif
std::ostream & operator<<(std::ostream &out, const IdentifierField &c)
std::istream & operator>>(std::istream &in, IdentifierField &c)
boost::container::small_vector< element_type, 12 >::size_type size_type
This is the individual specification for the range of one ExpandedIdentifier IdentifierField.
ExpandedIdentifier::size_type size_type
bool operator==(const IdentifierField &other) const
static constexpr auto minimum_possible
IdentifierField()=default
Create a wild-card value.
size_type get_indices() const
std::pair< element_type, element_type > BoundedRange
element_type m_next
void set_previous(int previous)
void clear()
Set methods.
bool get_previous(element_type current, element_type &previous) const
Returns false if previous/next is at end of range, or not possible.
element_type get_minimum() const
Query the values.
index_vector m_indexes
void add_value(element_type value)
void set(element_type minimum, element_type maximum)
void set_next(int next)
static constexpr auto maximum_possible
bool empty() const
If true, this field does not have any constraints, and may hold any value representable by element_ty...
void show(std::ostream &out=std::cout) const
element_type m_previous
bool overlaps_with(const IdentifierField &other) const
Check whether two IdentifierFields overlap (Are there any values which satisfy the constraints of bot...
std::vector< element_type > element_vector
std::pair< element_type, element_type > get_minmax() const
void set_maximum(element_type value)
continuation_mode m_continuation_mode
static constexpr auto invalidValues
element_type m_maximum
bool wrap_around() const
bool check_for_both_bounded()
Check mode - switch from enumerated to both_bounded if possible.
size_type get_value_index(element_type value) const
bool isEnumerated() const
element_type m_minimum
void operator|=(const IdentifierField &other)
Find the union of two fields.
void optimize()
Optimize - try to switch mode to both_bounded, set up lookup table for finding index from value.
bool get_next(element_type current, element_type &next) const
ExpandedIdentifier::element_type element_type
void create_index_table()
Create index table from value table.
bool match(element_type value) const
The basic match operation Given a value, test to see if it satisfies the constraints for this field.
std::vector< size_type > index_vector
static constexpr int m_maxNumberOfIndices
element_type get_value_at(size_type index) const
const element_vector & get_values() const
void set(const element_vector &values)
void set_minimum(element_type value)
bool isBounded() const
element_type get_maximum() const
size_type get_bits() const
Return the number of bits needed to store a value of this field.
const index_vector & get_indexes() const
std::variant< element_vector, BoundedRange > m_data
Definition index.py:1
#define private