ATLAS Offline Software
ConstIter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
14 #include <iostream>
15 #include <functional>
16 
17 namespace TrigConf {
18 
31  template<typename V, typename T>
32  class ConstIter final {
33  public:
53  ConstIter( const V & buf, size_t offset = 0,
54  std::function<T(const typename V::value_type &)> f = [](auto & x)->T{return {x};}) :
55  m_buf(buf),
57  m_data(),
58  m_f(f),
59  m_bufIt(buf.begin())
60  {}
61 
63  bool operator==(const ConstIter &i) const {
64  return &i.m_buf == &m_buf && i.m_offset == m_offset;
65  }
66 
68  bool operator!=(const ConstIter &i) const {
69  return !(*this == i);
70  }
71 
74  ++m_offset;
75  ++m_bufIt;
76  m_data.reset();
77  return *this;
78  }
79 
83  const T & operator*() const {
84  if( ! m_data.isValid() ) {
85  m_data.set (m_f(*m_bufIt));
86  }
87  return *m_data.ptr();
88  }
89 
90  private:
91  const V & m_buf;
92  std::size_t m_offset;
94  std::function<T(const typename V::value_type &)> m_f;
95  typename V::const_iterator m_bufIt;
96 
97  };
98 
99 }
100 
106 namespace std {
107  template<typename V, typename T>
108  class iterator_traits<TrigConf::ConstIter<V,T> >
109  {
110  public:
111  using difference_type = std::ptrdiff_t;
112  using size_type = std::size_t;
113  using value_type = const T;
114  using pointer = const T*;
115  using reference = const T&;
116  using iterator_category = std::forward_iterator_tag;
117  };
118 }
119 
120 #endif
TrigConf::ConstIter::m_buf
const V & m_buf
Const reference to the underlying data container.
Definition: ConstIter.h:91
TrigConf::ConstIter::m_offset
std::size_t m_offset
Current position of the iterator.
Definition: ConstIter.h:92
std::iterator_traits< TrigConf::ConstIter< V, T > >::reference
const T & reference
Definition: ConstIter.h:115
std::iterator_traits< TrigConf::ConstIter< V, T > >::size_type
std::size_t size_type
Definition: ConstIter.h:112
std::iterator_traits< TrigConf::ConstIter< V, T > >::value_type
const T value_type
Definition: ConstIter.h:113
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:94
TrigConf::ConstIter::operator==
bool operator==(const ConstIter &i) const
Comparison operator.
Definition: ConstIter.h:63
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:114
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:83
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:135
TrigConf::ConstIter
Forward iterator over an iterable of type V returning an object of type T.
Definition: ConstIter.h:32
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:53
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:116
TrigConf::ConstIter::m_bufIt
V::const_iterator m_bufIt
Iterator over the container.
Definition: ConstIter.h:95
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
TrigConf::ConstIter::operator!=
bool operator!=(const ConstIter &i) const
Not-equal operator.
Definition: ConstIter.h:68
TrigConf::ConstIter::operator++
ConstIter & operator++()
Pre-increment operator.
Definition: ConstIter.h:73
std::iterator_traits< TrigConf::ConstIter< V, T > >::difference_type
std::ptrdiff_t difference_type
Definition: ConstIter.h:111
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:93