ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifierField.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef IDENTIFIER_IDENTIFIERFIELD_H
6#define IDENTIFIER_IDENTIFIERFIELD_H
8#include <vector>
9#include <string>
10#include <stdexcept>
11#include <iosfwd>
12#include <limits>
13#include <utility>
14#include <variant>
15
16
83{
84 public :
87 using element_vector = std::vector <element_type>;
88 using index_vector = std::vector <size_type>;
89 using BoundedRange = std::pair<element_type, element_type>;
90 static constexpr auto minimum_possible = std::numeric_limits<element_type>::min();
91 static constexpr auto maximum_possible = std::numeric_limits<element_type>::max();
92 static constexpr auto invalidValues = element_vector{};
93
101
103 IdentifierField () = default;
104
107
109 IdentifierField (element_type minimum, element_type maximum);
110
112 IdentifierField (const element_vector &values);
113
114 //
115 inline bool
118
119 //
120 inline element_type
121 get_minimum() const {return m_minimum;}
122
123 //
124 inline std::pair<element_type, element_type>
125 get_minmax() const {
126 return {m_minimum, m_maximum};
127 }
128 //
129 inline element_type
130 get_maximum () const {return m_maximum;}
131 //
132 inline const element_vector&
133 get_values() const {
134 if (isBounded()) return invalidValues;
135 return std::get<element_vector>(m_data);
136 }
137
138 bool get_previous (element_type current, element_type& previous) const;
139 bool get_next (element_type current, element_type& next) const;
140 size_type get_indices () const {return m_size;}
141 const index_vector& get_indexes () const {return m_indexes;}
143 size_type get_bits () const;
146
149 bool match (element_type value) const;
150
153 bool overlaps_with (const IdentifierField& other) const;
154
156 void clear ();
157 void set (element_type minimum, element_type maximum);
158 void add_value (element_type value);
159 void set (const element_vector& values);
160 void set (bool wraparound);
161 void set_next (int next);
162 void set_previous (int previous);
166 void operator |= (const IdentifierField& other);
167
168 operator std::string () const;
169 bool operator == (const IdentifierField& other) const;
170
171 void show() const;
172
175
178 void optimize();
179
182 inline bool empty() const {return m_empty;}
184 inline bool isBounded() const {return std::holds_alternative<BoundedRange>(m_data);}
185 inline bool isEnumerated() const {return std::holds_alternative<element_vector>(m_data);}
186
187private :
188 static constexpr int m_maxNumberOfIndices = 100;
191
193 void create_index_table();
194 template <class T>
195 T * dataPtr(){return std::get_if<T>(&m_data);}
196 //
199 std::variant<element_vector, BoundedRange> m_data{};
204 bool m_empty{true};
206};
207
210 // Only both_bounded and enumerated are valid to calculate the
211 // value.
212 // both_bounded is the more frequent case and so comes first.
213 if (m_empty) return 0;
214 if (const auto * p{std::get_if<BoundedRange>(&m_data)}; p) {
215 if (index >= (size_type) (p->second - p->first + 1)) {
216 throw std::out_of_range("IdentifierField::get_value_at");
217 }
218 return (p->first + index);
219 }
220 return ((std::get<element_vector>(m_data)).at(index));
221
222}
223
224std::ostream &
225operator << (std::ostream &out, const IdentifierField &c);
226std::istream &
227operator >> (std::istream &in, IdentifierField &c);
228#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...
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