LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT > Class Template Reference

Internal helper class: actual implementation of nested iterator. More...

#include "NestedIterator.h"

Inheritance diagram for lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >:

Classes

struct  BeginPositionTag
 
struct  EndPositionTag
 

Public Types

using OuterIterator_t = ITER
 
using InnerContainerExtractor_t = INNERCONTEXTRACT
 
using InnerContainer_t = typename InnerContainerExtractor_t::result_type
 
using InnerIterator_t = typename InnerContainer_t::const_iterator
 
using iterator_type = deep_const_fwd_iterator_nested< OuterIterator_t, InnerContainerExtractor_t >
 
using value_type = typename InnerIterator_t::value_type
 Type of the value pointed by the iterator. More...
 

Public Member Functions

 deep_const_fwd_iterator_nested ()=default
 Default constructor: invalid iterator. More...
 
 deep_const_fwd_iterator_nested (OuterIterator_t src, OuterIterator_t end)
 Constructor: starts from the container at the specified iterator. More...
 
template<class CONT >
 deep_const_fwd_iterator_nested (const CONT &cont, BeginPositionTag)
 Constructor: starts from the beginning of the specified container. More...
 
template<class CONT >
 deep_const_fwd_iterator_nested (const CONT &cont, EndPositionTag)
 Constructor: starts from the end of the specified container. More...
 
iterator_typeoperator++ ()
 Prefix increment operator: points to the next element. More...
 
iterator_type operator++ (int)
 Postfix increment operator: points to the next element. More...
 
void swap (iterator_type &with)
 Swaps this with the specified iterator. More...
 
Dereference operators
const value_typeoperator* () const
 
const value_typeoperator-> () const
 
Comparison operators

Returns true if the two iterators are equivalent

bool operator== (const iterator_type &as) const
 Returns true if the two iterators are not equivalent. More...
 
bool operator!= (const iterator_type &as) const
 Returns true if the two iterators are not equivalent. More...
 
 operator bool () const
 Bonus: convert to bool to find out if we are at the end. More...
 
bool operator! () const
 Bonus: convert to bool to find out if we are at the end. More...
 

Static Public Attributes

static constexpr BeginPositionTag begin = {}
 
static constexpr EndPositionTag end = {}
 

Protected Member Functions

 deep_const_fwd_iterator_nested (OuterIterator_t end)
 Internal constructor: past-the-end iterator pointing to specified place. More...
 

Protected Attributes

OuterIterator_t outer_iter
 points to current inner container More...
 
OuterIterator_t outer_end
 points to past-the-end inner container More...
 
InnerIterator_t inner_iter
 points to the current element More...
 
InnerIterator_t inner_end
 stores the end of current inner container More...
 

Private Member Functions

void init_inner ()
 
void reset_inner ()
 
void skip_empty ()
 points to the next item More...
 
bool is_end () const
 
const InnerContainerExtractor_t::result_type & extract_container (const typename OuterIterator_t::value_type &v)
 Extracts the value out of the inner iterator. More...
 

Detailed Description

template<typename ITER, typename INNERCONTEXTRACT>
class lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >

Internal helper class: actual implementation of nested iterator.

Definition at line 53 of file NestedIterator.h.

Member Typedef Documentation

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerContainer_t = typename InnerContainerExtractor_t::result_type

Definition at line 145 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerContainerExtractor_t = INNERCONTEXTRACT

Definition at line 144 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerIterator_t = typename InnerContainer_t::const_iterator

Definition at line 148 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::iterator_type = deep_const_fwd_iterator_nested<OuterIterator_t, InnerContainerExtractor_t>

Definition at line 152 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::OuterIterator_t = ITER

Definition at line 143 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::value_type = typename InnerIterator_t::value_type

Type of the value pointed by the iterator.

Definition at line 155 of file NestedIterator.h.

Constructor & Destructor Documentation

template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( )
default

Default constructor: invalid iterator.

This constructor sets the iterator in an invalid, end-of-container state.

template<typename ITER , typename INNERCONTEXTRACT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( OuterIterator_t  src,
OuterIterator_t  end 
)

Constructor: starts from the container at the specified iterator.

Parameters
srcthe starting point of the iterator
endthe end point of the iterator

This constructor does not set and end. Due to how the class works, if the outer container has an "end", reaching it with this iterator has a undefined behaviour. You most likely want to use the constructor where you can also specify the end of the container.

Definition at line 315 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::init_inner(), lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::is_end(), and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::skip_empty().

318  : outer_iter(src), outer_end(end)
319  {
320  if (is_end()) return;
321  init_inner();
322  skip_empty();
323  } // deep_const_fwd_iterator_nested(OuterIterator_t, OuterIterator_t)
OuterIterator_t outer_iter
points to current inner container
OuterIterator_t outer_end
points to past-the-end inner container
static constexpr EndPositionTag end
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
template<class CONT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( const CONT &  cont,
BeginPositionTag   
)
inline

Constructor: starts from the beginning of the specified container.

Parameters
contthe container
[anonymous]tag to select the begin-of-container behaviour

The second parameter is used just to choose which constructor to use. Two constants are provided, begin and end, defined in the iterator itself (no explicit namespace is required). Example:

using Data_t = std::vector<std::vector<float>>;
Data_t data(5, { 1., 3., 5. });
deep_const_fwd_iterator_nested<Data_t::const_iterator> iData(data, begin),
data_end(data, end);

Definition at line 199 of file NestedIterator.h.

201  {
202  skip_empty();
203  }
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
template<class CONT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( const CONT &  cont,
EndPositionTag   
)
inline

Constructor: starts from the end of the specified container.

Parameters
contthe container
[anonymous]tag to select the end-of-container behaviour

The second parameter is used just to choose which constructor to use. Two constants are provided, begin and end, defined in the iterator itself (no explicit namespace is required). Example:

using Data_t = std::vector<std::vector<float>>;
Data_t data(5, { 1., 3., 5. });
deep_const_fwd_iterator_nested<Data_t::const_iterator> iData(data, begin),
data_end(data, end);

Definition at line 222 of file NestedIterator.h.

224  {}
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( OuterIterator_t  end)
inlineprotected

Internal constructor: past-the-end iterator pointing to specified place.

Definition at line 291 of file NestedIterator.h.

292  {}
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
static constexpr EndPositionTag end

Member Function Documentation

template<typename ITER, typename INNERCONTEXTRACT>
const InnerContainerExtractor_t::result_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::extract_container ( const typename OuterIterator_t::value_type &  v)
inlineprivate

Extracts the value out of the inner iterator.

Definition at line 302 of file NestedIterator.h.

Referenced by lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::init_inner().

304  {
305  return InnerContainerExtractor_t()(v);
306  }
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::init_inner ( )
private

Definition at line 344 of file NestedIterator.h.

References util::begin(), util::end(), lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::extract_container(), lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_end, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter.

Referenced by lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested(), and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::skip_empty().

345  {
348  } // deep_const_fwd_iterator_nested<>::init_inner()
InnerIterator_t inner_iter
points to the current element
const InnerContainerExtractor_t::result_type & extract_container(const typename OuterIterator_t::value_type &v)
Extracts the value out of the inner iterator.
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator bool ( ) const
inline

Bonus: convert to bool to find out if we are at the end.

Returns
whether this operator is past-the-end

Definition at line 276 of file NestedIterator.h.

276 { return !is_end(); }
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator! ( ) const
inline

Bonus: convert to bool to find out if we are at the end.

Returns
whether this operator is past-the-end

Definition at line 277 of file NestedIterator.h.

277 { return is_end(); }
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator!= ( const iterator_type as) const
inline

Returns true if the two iterators are not equivalent.

Definition at line 264 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::is_end(), and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter.

265  {
266  return (as.outer_iter != outer_iter) ||
267  ((as.inner_iter != inner_iter) && (!is_end() || !as.is_end()));
268  }
InnerIterator_t inner_iter
points to the current element
OuterIterator_t outer_iter
points to current inner container
template<typename ITER, typename INNERCONTEXTRACT>
const value_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator* ( ) const
inline

Definition at line 251 of file NestedIterator.h.

251 { return *inner_iter; }
InnerIterator_t inner_iter
points to the current element
template<typename ITER , typename INNERCONTEXTRACT >
deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT > & lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator++ ( )

Prefix increment operator: points to the next element.

Returns
this iterator, already incremented

The behaviour of this method on a past-the-end iterator is undefined (currently, chances are it will access invalid memory).

Definition at line 327 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::skip_empty().

328  {
329  ++inner_iter;
330  skip_empty();
331  return *this;
332  } // deep_const_fwd_iterator_nested<>::operator++()
InnerIterator_t inner_iter
points to the current element
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
iterator_type lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator++ ( int  )
inline

Postfix increment operator: points to the next element.

Returns
a copy of this iterator before the increment

The behaviour of this method on a past-the-end iterator is undefined (currently, chances are it will access invalid memory).

Definition at line 242 of file NestedIterator.h.

243  {
244  iterator_type old(*this);
245  this->operator++();
246  return old;
247  }
iterator_type & operator++()
Prefix increment operator: points to the next element.
deep_const_fwd_iterator_nested< OuterIterator_t, InnerContainerExtractor_t > iterator_type
template<typename ITER, typename INNERCONTEXTRACT>
const value_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator-> ( ) const
inline

Definition at line 252 of file NestedIterator.h.

252 { return *inner_iter; }
InnerIterator_t inner_iter
points to the current element
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator== ( const iterator_type as) const
inline

Returns true if the two iterators are not equivalent.

Definition at line 258 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::is_end(), and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter.

259  {
260  return (as.outer_iter == outer_iter) &&
261  ((as.inner_iter == inner_iter) || (is_end() && as.is_end()));
262  }
InnerIterator_t inner_iter
points to the current element
OuterIterator_t outer_iter
points to current inner container
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::reset_inner ( )
private
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::skip_empty ( )
private

points to the next item

Definition at line 357 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::init_inner(), lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_end, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::is_end(), lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter, and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::reset_inner().

Referenced by lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested(), and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator++().

358  {
359  while (inner_iter == inner_end) {
360  ++outer_iter;
361  if (is_end()) {
362  reset_inner();
363  return;
364  } // if
365  init_inner();
366  } // while inner iterator ended
367  } // skip_empty()
InnerIterator_t inner_iter
points to the current element
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::swap ( iterator_type with)

Swaps this with the specified iterator.

Definition at line 335 of file NestedIterator.h.

References lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_end, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter, lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_end, and lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter.

Referenced by std::swap().

336  {
337  std::swap(outer_iter, with.outer_iter);
338  std::swap(outer_end, with.outer_end);
339  std::swap(inner_iter, with.inner_iter);
340  std::swap(inner_end, with.inner_end);
341  } // deep_const_fwd_iterator_nested<>::swap()
InnerIterator_t inner_iter
points to the current element
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
OuterIterator_t outer_end
points to past-the-end inner container
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)

Member Data Documentation

template<typename ITER, typename INNERCONTEXTRACT>
constexpr BeginPositionTag lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::begin = {}
static

Definition at line 160 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
constexpr EndPositionTag lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::end = {}
static

Definition at line 161 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
OuterIterator_t lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_end
protected

points to past-the-end inner container

Definition at line 285 of file NestedIterator.h.

Referenced by lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::swap().


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