Belle II Software development
ObjArrayIterator< ArrayType, ValueType > Class Template Reference

Optimizes class to iterate over TObjArray and classes inheriting from it. More...

#include <ArrayIterator.h>

Public Types

using iterator_category = std::forward_iterator_tag
 Iterator category.
 
using difference_type = std::ptrdiff_t
 Difference type.
 
using value_type = ValueType
 Value type.
 
using pointer = ValueType*
 Pointer.
 
using reference = ValueType&
 Reference.
 

Public Member Functions

 ObjArrayIterator ()=default
 default constructor
 
 ObjArrayIterator (ArrayType &array, size_t index)
 real constructor
 
 ObjArrayIterator (ArrayType const *array, bool end=false)
 Convenience constructor in case of a TClonesArray pointer.
 
 ObjArrayIterator (ArrayType const *const *array, bool end=false)
 Convenience constructor because we usually have a TClonesArray** member so this takes cares of the checks.
 
ObjArrayIterator< ArrayType, ValueType > & operator++ ()
 prefix increment
 
ObjArrayIterator< ArrayType, ValueType > operator++ (int)
 postfix increment
 
bool operator== (const ObjArrayIterator< ArrayType, ValueType > &rhs) const
 check equality.
 
bool operator!= (const ObjArrayIterator< ArrayType, ValueType > &rhs) const
 check inequality.
 
ValueType & operator* () const
 dereference.
 
ValueType * operator-> () const
 dereference.
 

Private Attributes

TObject ** m_array {nullptr}
 pointer to the fCont member of the TObjArray
 

Detailed Description

template<class ArrayType, class ValueType>
class Belle2::ObjArrayIterator< ArrayType, ValueType >

Optimizes class to iterate over TObjArray and classes inheriting from it.

iterators are invalidated if the size of the TObjArray is changed.

Definition at line 23 of file ArrayIterator.h.

Member Typedef Documentation

◆ difference_type

template<class ArrayType, class ValueType>
using difference_type = std::ptrdiff_t

Difference type.

Definition at line 31 of file ArrayIterator.h.

◆ iterator_category

template<class ArrayType, class ValueType>
using iterator_category = std::forward_iterator_tag

Iterator category.

Definition at line 28 of file ArrayIterator.h.

◆ pointer

template<class ArrayType, class ValueType>
using pointer = ValueType*

Pointer.

Definition at line 37 of file ArrayIterator.h.

◆ reference

template<class ArrayType, class ValueType>
using reference = ValueType&

Reference.

Definition at line 40 of file ArrayIterator.h.

◆ value_type

template<class ArrayType, class ValueType>
using value_type = ValueType

Value type.

Definition at line 34 of file ArrayIterator.h.

Constructor & Destructor Documentation

◆ ObjArrayIterator() [1/3]

template<class ArrayType, class ValueType>
ObjArrayIterator ( ArrayType & array,
size_t index )
inline

real constructor

Parameters
arrayreference to the TObjArray instance we want to iterate over
indexinteger of the index we want to point to right away

Definition at line 48 of file ArrayIterator.h.

48: m_array{array.GetObjectRef() + index} {}

◆ ObjArrayIterator() [2/3]

template<class ArrayType, class ValueType>
ObjArrayIterator ( ArrayType const * array,
bool end = false )
inlineexplicit

Convenience constructor in case of a TClonesArray pointer.

The "const *" is needed so that a const TClonesArray* can be passed in for const ObjArrayIterators

Parameters
arraypointer to where the array is located. If any of the two is NULL a default iterator is created
endif true point to after the array, otherwise point to the beginning

Definition at line 57 of file ArrayIterator.h.

58 {
59 if (array) {
60 m_array = array->GetObjectRef() + (end ? array->GetEntriesFast() : 0);
61 }
62 }

◆ ObjArrayIterator() [3/3]

template<class ArrayType, class ValueType>
ObjArrayIterator ( ArrayType const *const * array,
bool end = false )
inlineexplicit

Convenience constructor because we usually have a TClonesArray** member so this takes cares of the checks.

The "const * const *" is needed so that a const TClonesArray** can be passed in for const ObjArrayIterators

Parameters
arraypointer to the pointer where the array is located. If any of the two is NULL a default iterator is created
endif true point to after the array, otherwise point to the beginning

Definition at line 71 of file ArrayIterator.h.

71: ObjArrayIterator(array ? * array : nullptr, end) {}

Member Function Documentation

◆ operator!=()

template<class ArrayType, class ValueType>
bool operator!= ( const ObjArrayIterator< ArrayType, ValueType > & rhs) const
inline

check inequality.

Definition at line 79 of file ArrayIterator.h.

79{ return !(*this == rhs); }

◆ operator*()

template<class ArrayType, class ValueType>
ValueType & operator* ( ) const
inline

dereference.

Definition at line 82 of file ArrayIterator.h.

82{ return *static_cast<ValueType*>(*m_array); }

◆ operator++() [1/2]

template<class ArrayType, class ValueType>
ObjArrayIterator< ArrayType, ValueType > & operator++ ( )
inline

prefix increment

Definition at line 73 of file ArrayIterator.h.

73{ ++m_array; return *this; }

◆ operator++() [2/2]

template<class ArrayType, class ValueType>
ObjArrayIterator< ArrayType, ValueType > operator++ ( int )
inline

postfix increment

Definition at line 75 of file ArrayIterator.h.

75{ auto old = *this; ++(*this); return old; }

◆ operator->()

template<class ArrayType, class ValueType>
ValueType * operator-> ( ) const
inline

dereference.

Definition at line 84 of file ArrayIterator.h.

84{ return &(operator*()); }

◆ operator==()

template<class ArrayType, class ValueType>
bool operator== ( const ObjArrayIterator< ArrayType, ValueType > & rhs) const
inline

check equality.

Definition at line 77 of file ArrayIterator.h.

77{ return m_array == rhs.m_array; }

Member Data Documentation

◆ m_array

template<class ArrayType, class ValueType>
TObject** m_array {nullptr}
private

pointer to the fCont member of the TObjArray

Definition at line 87 of file ArrayIterator.h.

87{nullptr};

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