6#include "GaudiKernel/MsgStream.h"
20template<
class SetA,
class SetB,
typename Compare = std::less<>>
22share_element(SetA&& setA, SetB&& setB, Compare comp = Compare{}){
23 auto xA = setA.begin();
24 auto xB = setB.begin();
25 while (xA != setA.end() && xB != setB.end()){
28 }
else if (
comp(*xB, *xA)) {
43 if (--indices)
return std::bit_width(indices);
58 if (v.size()==1)
return 0;
64 auto it = std::ranges::find(v, value);
65 if (it != v.end())
return std::distance(v.begin(), it);
78 return (std::ranges::find(v, value)!=v.end());
95 set(minimum, maximum);
109 previous = current - 1;
125 previous = current - 1;
132 previous = values.back();
143 previous = values[
index];
174 if ((
index == values.size() - 1) || (
index == 0 && current != values.front())) {
176 next = values.front();
187 next = values[
index];
196 if (
m_empty or other.m_empty)
return true;
202 if (
isBounded() and other.isEnumerated() ){
204 for (
const auto & v:
ev) {
210 for (
const auto & v:
ev){
211 if ((v >= other.m_minimum) and (v <= other.m_maximum))
return (
true);
217 return share_element(
get_values(), other.get_values());
239 if (minimum == maximum) {
258 if (std::ranges::binary_search(*p, value))
return;
260 std::ranges::sort(*p);
277 std::ranges::sort (*p);
327 set(other.get_values ());
344IdentifierField::operator std::string ()
const {
349 const auto & [minimum, maximum] =
get_minmax();
350 if (minimum == maximum) {
351 result = std::to_string(minimum);
361 result = std::format(
"{}:{}", minimum, maximum);
363 catch (
const std::format_error& e) {
376 if (
m_data != other.m_data)
return false;
393 out <<
"indices " <<
m_size <<
" ";
395 out <<
"next " <<
m_next <<
" ";
400 out <<
"both_bounded ";
402 out <<
"enumerated ";
413 out <<
"has_previous ";
419 out <<
"has_wrap_around ";
427 std::ostringstream os;
469 m_indexes = std::vector<size_type>(size, 0);
472 auto &v = std::get<element_vector>(
m_data);
473 for (
const auto & thisValue: v) {
474 if (
const auto idx=(thisValue -
m_minimum); idx < (int)size) {
478 std::cout <<
"size, value, index, i "
479 << size <<
" " << thisValue <<
" "
480 <<
index <<
" " << i++ <<
" min, max "
499 while (std::isspace(is.peek())){is.ignore();}
505 if (c ==
'+') is.ignore();
511 std::vector<int>
vec(1,v);
513 vec.insert(
vec.end(), restOfList.begin(), restOfList.end());
515 }
else if (c ==
':'){
526 std::string
msg{
"Stream extraction for IdentifierField: "};
530 throw std::invalid_argument(
msg);
std::vector< size_t > vec
std::ostream & operator<<(std::ostream &out, const IdentifierField &c)
std::istream & operator>>(std::istream &is, IdentifierField &idf)
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
void set_previous(int previous)
bool get_previous(element_type current, element_type &previous) const
Returns false if previous/next is at end of range, or not possible.
void add_value(element_type value)
void set(element_type minimum, element_type maximum)
static constexpr auto maximum_possible
void show(std::ostream &out=std::cout) const
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
continuation_mode m_continuation_mode
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
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.
static constexpr int m_maxNumberOfIndices
element_type get_value_at(size_type index) const
const element_vector & get_values() const
size_type get_bits() const
Return the number of bits needed to store a value of this field.
std::variant< element_vector, BoundedRange > m_data
bool isDigit(const char c)
IdentifierField::element_type parseStreamDigits(std::istream &is)
IdentifierField::element_vector parseStreamList(std::istream &is)
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.