ATLAS Offline Software
ConstIter.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 TRIGCONFDATA_CONSTITER_H
6 #define TRIGCONFDATA_CONSTITER_H
7 
12 #include "CxxUtils/CachedValue.h"
13 #include <iterator> //std::forward_iterator_tag
14 #include <functional>
15 
16 namespace TrigConf {
17 
30  template<typename V, typename T>
31  class ConstIter final {
32  public:
52  ConstIter( const V & buf, size_t offset = 0,
53  std::function<T(const typename V::value_type &)> f = [](auto & x)->T{return {x};}) :
54  m_buf(buf),
56  m_data(),
57  m_f(std::move(f)),
58  m_bufIt(buf.begin())
59  {}
60 
62  bool operator==(const ConstIter &i) const {
63  return &i.m_buf == &m_buf && i.m_offset == m_offset;
64  }
65 
66 
69  ++m_offset;
70  ++m_bufIt;
71  m_data.reset();
72  return *this;
73  }
74 
78  const T & operator*() const {
79  if( ! m_data.isValid() ) {
80  m_data.set (m_f(*m_bufIt));
81  }
82  return *m_data.ptr();
83  }
84 
85  private:
86  const V & m_buf;
87  std::size_t m_offset;
89  std::function<T(const typename V::value_type &)> m_f;
90  typename V::const_iterator m_bufIt;
91 
92  };
93 
94 }
95 
101 namespace std {
102  template<typename V, typename T>
103  class iterator_traits<TrigConf::ConstIter<V,T> >
104  {
105  public:
106  using difference_type = std::ptrdiff_t;
107  using size_type = std::size_t;
108  using value_type = const T;
109  using pointer = const T*;
110  using reference = const T&;
111  using iterator_category = std::forward_iterator_tag;
112  };
113 }
114 
115 #endif
TrigConf::ConstIter::m_buf
const V & m_buf
Const reference to the underlying data container.
Definition: ConstIter.h:86
TrigConf::ConstIter::m_offset
std::size_t m_offset
Current position of the iterator.
Definition: ConstIter.h:87
std::iterator_traits< TrigConf::ConstIter< V, T > >::reference
const T & reference
Definition: ConstIter.h:110
std::iterator_traits< TrigConf::ConstIter< V, T > >::size_type
std::size_t size_type
Definition: ConstIter.h:107
std::iterator_traits< TrigConf::ConstIter< V, T > >::value_type
const T value_type
Definition: ConstIter.h:108
TrigConf::ConstIter::m_f
std::function< T(const typename V::value_type &)> m_f
Function to turn a single datum from the container into the output type.
Definition: ConstIter.h:89
TrigConf::ConstIter::operator==
bool operator==(const ConstIter &i) const
Comparison operator.
Definition: ConstIter.h:62
x
#define x
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
std::iterator_traits< TrigConf::ConstIter< V, T > >::pointer
const T * pointer
Definition: ConstIter.h:109
TrigConf::ConstIter::operator*
const T & operator*() const
Dereference operator Creates object of type T from the current object in the container on the fly usi...
Definition: ConstIter.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
CxxUtils::CachedValue
Cached value with atomic update.
Definition: CachedValue.h:55
hist_file_dump.f
f
Definition: hist_file_dump.py:140
columnar::final
CM final
Definition: ColumnAccessor.h:106
TrigConf::ConstIter
Forward iterator over an iterable of type V returning an object of type T.
Definition: ConstIter.h:31
TrigConf::ConstIter::ConstIter
ConstIter(const V &buf, size_t offset=0, std::function< T(const typename V::value_type &)> f=[](auto &x) ->T{return {x};})
Constructor.
Definition: ConstIter.h:52
CachedValue.h
Cached value with atomic update.
std::iterator_traits< TrigConf::ConstIter< V, T > >::iterator_category
std::forward_iterator_tag iterator_category
Definition: ConstIter.h:111
TrigConf::ConstIter::m_bufIt
V::const_iterator m_bufIt
Iterator over the container.
Definition: ConstIter.h:90
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
TrigConf::ConstIter::operator++
ConstIter & operator++()
Pre-increment operator.
Definition: ConstIter.h:68
std::iterator_traits< TrigConf::ConstIter< V, T > >::difference_type
std::ptrdiff_t difference_type
Definition: ConstIter.h:106
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TrigConf::ConstIter::m_data
CxxUtils::CachedValue< T > m_data
Holder of the transformed data.
Definition: ConstIter.h:88