Lumiera  0.pre.03
»edit your freedom«
IterAdapter< POS, CON > Class Template Reference

#include "lib/iter-adapter.hpp"

Description

template<class POS, class CON>
class lib::IterAdapter< POS, CON >

Adapter for building an implementation of the »Lumiera Forward Iterator« concept.

The "current position" is represented as an opaque element (usually a nested iterator), with callbacks into the controlling container instance to manage this position. This allows to influence and customise the iteration process to a large extent. Basically such an IterAdapter behaves like the similar concept from STL, but

  • it is not just a disguised pointer (meaning, it's more expensive)
  • it checks validity on every operation and may throw
  • it has a distinct back-link to the source container
  • the source container needs to support checkPoint() and iterNext() free functions.
  • we may need friendship to implement those extension points on the container
  • the end-of-iteration can be detected by bool check
    Note
    it is possible to "hide" a smart-ptr within the CON template parameter.
    Template Parameters
    POSpointer or similar mutable link to the current value. Will be bool() checked to detect iteration end, end else dereferenced.
    CONtype of the backing container, which needs to implement two extension point functions for iteration control
    Stipulations
  • POS refers to the current position within the data source of this iterator.
    1. it should be default constructible
    2. it should be copy constructible
    3. when IterAdapter is supposed to be assignable, then POS should be
    4. it should provide embedded typedefs for pointer, reference and value_type, or alternatively resolve these types through specialisation of meta::ValueTypeBinding.
    5. it should be convertible to the pointer type it declares
    6. dereferencing should yield a type that is convertible to the reference type
  • CON points to the data source of this iterator (typically a data container type) We store a pointer-like backlink to invoke a special iteration control API:
    1. checkPoint yields true iff the source has yet more result values to yield
    2. iterNext advances the POS to the next element
Note
  • when POS is just a pointer, we use the pointee as value type
  • but when POS is a class, we expect the usual STL style nested typedefs value_type, reference and pointer
See also
scoped-ptrvect.hpp usage example
value-type-binding.hpp
iter-adapter-test.cpp

Definition at line 185 of file iter-adapter.hpp.

Public Types

using pointer = typename _ValTrait::pointer
 
using reference = typename _ValTrait::reference
 
using value_type = typename _ValTrait::value_type
 

Public Member Functions

 IterAdapter (CON src, POS const &startpos)
 
bool empty () const
 
 ENABLE_USE_IN_STD_RANGE_FOR_LOOPS (IterAdapter)
 
bool isValid () const
 
 operator bool () const
 
reference operator* () const
 
IterAdapteroperator++ ()
 
pointer operator-> () const
 

Friends

template<class P1 , class P2 , class CX >
bool operator== (IterAdapter< P1, CX > const &, IterAdapter< P2, CX > const &)
 comparison is allowed to access impl iterator
 

Protected Types

using ConRef = typename meta::RefTraits< CON >::Reference
 

Protected Member Functions

bool check () const
 ask the controlling container if this position is valid. More...
 
void iterate ()
 ask the controlling container to yield the next position. More...
 
void resetPos (POS otherPos)
 
ConRef source ()
 allow derived classes to access backing container
 
const ConRef source () const
 

Private Types

using _ValTrait = meta::ValueTypeBinding< std::remove_pointer_t< POS > >
 

Private Member Functions

void _maybe_throw () const
 

Private Attributes

POS pos_
 
CON source_
 

Member Function Documentation

◆ check()

bool check ( ) const
inlineprotected

ask the controlling container if this position is valid.

Note
this function is called before any operation, thus the container may adjust the position value, for example setting it to a "stop iteration" mark.

Definition at line 262 of file iter-adapter.hpp.

Referenced by IterAdapter< Pos, DataHandle >::iterate(), and IterAdapter< Pos, DataHandle >::source().

+ Here is the caller graph for this function:

◆ iterate()

void iterate ( )
inlineprotected

ask the controlling container to yield the next position.

The call is dispatched only if the current position is valid; any new position reached will typically be validated prior to any further access, through invocation of check.

Definition at line 273 of file iter-adapter.hpp.

+ Inheritance diagram for IterAdapter< POS, CON >:
+ Collaboration diagram for IterAdapter< POS, CON >:

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