ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
13#include <iterator> //std::forward_iterator_tag
14#include <functional>
15
16namespace 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),
55 m_offset(offset),
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
101namespace 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
Cached value with atomic update.
#define x
Cached value with atomic update.
Definition CachedValue.h:55
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
V::const_iterator m_bufIt
Iterator over the container.
Definition ConstIter.h:90
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
CxxUtils::CachedValue< T > m_data
Holder of the transformed data.
Definition ConstIter.h:88
ConstIter & operator++()
Pre-increment operator.
Definition ConstIter.h:68
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
const V & m_buf
Const reference to the underlying data container.
Definition ConstIter.h:86
std::size_t m_offset
Current position of the iterator.
Definition ConstIter.h:87
bool operator==(const ConstIter &i) const
Comparison operator.
Definition ConstIter.h:62
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
STL namespace.