ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConf::ConstIter< V, T > Class Template Referencefinal

Forward iterator over an iterable of type V returning an object of type T. More...

#include <ConstIter.h>

Collaboration diagram for TrigConf::ConstIter< V, T >:

Public Member Functions

 ConstIter (const V &buf, size_t offset=0, std::function< T(const typename V::value_type &)> f=[](auto &x) ->T{return {x};})
 Constructor.
bool operator== (const ConstIter &i) const
 Comparison operator.
ConstIteroperator++ ()
 Pre-increment operator.
const T & operator* () const
 Dereference operator Creates object of type T from the current object in the container on the fly using the creation function m_f.

Private Attributes

const V & m_buf
 Const reference to the underlying data container.
std::size_t m_offset
 Current position of the iterator.
CxxUtils::CachedValue< T > m_data
 Holder of the transformed data.
std::function< T(const typename V::value_type &)> m_f
 Function to turn a single datum from the container into the output type.
V::const_iterator m_bufIt
 Iterator over the container.

Detailed Description

template<typename V, typename T>
class TrigConf::ConstIter< V, T >

Forward iterator over an iterable of type V returning an object of type T.

By its nature this is a generator, returning values of type T, computed on the fly https://en.wikipedia.org/wiki/Generator_(computer_programming)

Objects of type T must be creatable from V::value_type, either by having a constuctor T(V::valuetype) or by supplying an explicit conversion function to the constructor of the iterator

This is being used by HLTMenu, L1Menu, and L1TopoMenu

Definition at line 31 of file ConstIter.h.

Constructor & Destructor Documentation

◆ ConstIter()

template<typename V, typename T>
TrigConf::ConstIter< V, T >::ConstIter ( const V & buf,
size_t offset = 0,
std::function< T(const typename V::value_type &)> f = [](auto & x)->T{return {x};} )
inline

Constructor.

Parameters
bufReference to the underlying iterable data container
offsetPosition of the current element at construction time
fFunction to create an object of type T from type V::value_type, the default calls a contstructor T(V::value_type)

Iterators pointing to the front and back of the container, assuming that T can be created from the elements of V are created like this

ConstIter<V, T> begin( v );
ConstIter<V, T> end( v, v.size() );
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

An example for iterating over chains of an HLTMenu

ptree & chains = hltmenu.data().get_child("chains");
ConstIter<ptree, TrigConf::HLTChain> begin( v, 0, [](auto x){return HLTChain(x.second));
ConstIter<ptree, TrigConf::HLTChain> end( chains, chains.size(), [](auto x){return HLTChain(x.second) );
boost::property_tree::ptree ptree
#define x
HLT chain configuration information.

Definition at line 52 of file ConstIter.h.

53 {return {x};}) :
54 m_buf(buf),
56 m_data(),
57 m_f(std::move(f)),
59 {}
Forward iterator over an iterable of type V returning an object of type T.
Definition ConstIter.h:31
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
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

Member Function Documentation

◆ operator*()

template<typename V, typename T>
const T & TrigConf::ConstIter< V, T >::operator* ( ) const
inline

Dereference operator Creates object of type T from the current object in the container on the fly using the creation function m_f.

Definition at line 78 of file ConstIter.h.

78 {
79 if( ! m_data.isValid() ) {
80 m_data.set (m_f(*m_bufIt));
81 }
82 return *m_data.ptr();
83 }

◆ operator++()

template<typename V, typename T>
ConstIter & TrigConf::ConstIter< V, T >::operator++ ( )
inline

Pre-increment operator.

Definition at line 68 of file ConstIter.h.

68 {
69 ++m_offset;
70 ++m_bufIt;
71 m_data.reset();
72 return *this;
73 }

◆ operator==()

template<typename V, typename T>
bool TrigConf::ConstIter< V, T >::operator== ( const ConstIter< V, T > & i) const
inline

Comparison operator.

Definition at line 62 of file ConstIter.h.

62 {
63 return &i.m_buf == &m_buf && i.m_offset == m_offset;
64 }

Member Data Documentation

◆ m_buf

template<typename V, typename T>
const V& TrigConf::ConstIter< V, T >::m_buf
private

Const reference to the underlying data container.

Definition at line 86 of file ConstIter.h.

◆ m_bufIt

template<typename V, typename T>
V::const_iterator TrigConf::ConstIter< V, T >::m_bufIt
private

Iterator over the container.

Definition at line 90 of file ConstIter.h.

◆ m_data

template<typename V, typename T>
CxxUtils::CachedValue<T> TrigConf::ConstIter< V, T >::m_data
private

Holder of the transformed data.

Definition at line 88 of file ConstIter.h.

◆ m_f

template<typename V, typename T>
std::function<T(const typename V::value_type &)> TrigConf::ConstIter< V, T >::m_f
private

Function to turn a single datum from the container into the output type.

Definition at line 89 of file ConstIter.h.

◆ m_offset

template<typename V, typename T>
std::size_t TrigConf::ConstIter< V, T >::m_offset
private

Current position of the iterator.

Definition at line 87 of file ConstIter.h.


The documentation for this class was generated from the following file: