Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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 207 of file iter-adapter.hpp.

Public Types

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

Public Member Functions

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

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 = meta::RefTraits< CON >::Reference
 

Protected Member Functions

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

Private Types

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

Private Member Functions

void _maybe_throw () const
 

Private Attributes

CON source_
 
POS pos_
 

Constructor & Destructor Documentation

◆ IterAdapter() [1/2]

template<class POS , class CON >
IterAdapter ( CON  src,
POS const &  startpos 
)
inline

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

References IterAdapter< POS, CON >::check().

+ Here is the call graph for this function:

◆ IterAdapter() [2/2]

template<class POS , class CON >
IterAdapter ( )
inline

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

Member Typedef Documentation

◆ _ValTrait

template<class POS , class CON >
using _ValTrait = meta::ValueTypeBinding<std::remove_pointer_t<POS> >
private

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

◆ value_type

template<class POS , class CON >
using value_type = _ValTrait::value_type

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

◆ reference

template<class POS , class CON >
using reference = _ValTrait::reference

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

◆ pointer

template<class POS , class CON >
using pointer = _ValTrait::pointer

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

◆ ConRef

template<class POS , class CON >
using ConRef = meta::RefTraits<CON>::Reference
protected

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

Member Function Documentation

◆ operator bool()

template<class POS , class CON >
operator bool ( ) const
inlineexplicit

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

References IterAdapter< POS, CON >::isValid().

+ Here is the call graph for this function:

◆ operator*()

template<class POS , class CON >
reference operator* ( ) const
inline

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

References IterAdapter< POS, CON >::_maybe_throw(), and IterAdapter< POS, CON >::pos_.

+ Here is the call graph for this function:

◆ operator->()

template<class POS , class CON >
pointer operator-> ( ) const
inline

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

References IterAdapter< POS, CON >::_maybe_throw(), and IterAdapter< POS, CON >::pos_.

+ Here is the call graph for this function:

◆ operator++()

template<class POS , class CON >
IterAdapter & operator++ ( )
inline

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

References IterAdapter< POS, CON >::_maybe_throw(), and IterAdapter< POS, CON >::iterate().

+ Here is the call graph for this function:

◆ isValid()

template<class POS , class CON >
bool isValid ( ) const
inline

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

References IterAdapter< POS, CON >::check().

Referenced by IterAdapter< POS, CON >::_maybe_throw(), IterAdapter< POS, CON >::empty(), and IterAdapter< POS, CON >::operator bool().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

template<class POS , class CON >
bool empty ( ) const
inline

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

References IterAdapter< POS, CON >::isValid().

+ Here is the call graph for this function:

◆ check()

template<class POS , class CON >
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 284 of file iter-adapter.hpp.

References IterAdapter< POS, CON >::pos_, and IterAdapter< POS, CON >::source_.

Referenced by IterAdapter< POS, CON >::IterAdapter(), IterAdapter< POS, CON >::isValid(), IterAdapter< POS, CON >::iterate(), and IterAdapter< POS, CON >::resetPos().

+ Here is the caller graph for this function:

◆ iterate()

template<class POS , class CON >
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 295 of file iter-adapter.hpp.

References IterAdapter< POS, CON >::check(), IterAdapter< POS, CON >::pos_, and IterAdapter< POS, CON >::source_.

Referenced by IterAdapter< POS, CON >::operator++().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source() [1/2]

template<class POS , class CON >
ConRef source ( )
inlineprotected

allow derived classes to access backing container

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

References IterAdapter< POS, CON >::source_.

◆ source() [2/2]

template<class POS , class CON >
const ConRef source ( ) const
inlineprotected

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

◆ resetPos()

template<class POS , class CON >
void resetPos ( POS  otherPos)
inlineprotected

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

References IterAdapter< POS, CON >::check(), and IterAdapter< POS, CON >::pos_.

+ Here is the call graph for this function:

◆ _maybe_throw()

template<class POS , class CON >
void _maybe_throw ( ) const
inlineprivate

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

References IterAdapter< POS, CON >::isValid().

Referenced by IterAdapter< POS, CON >::operator*(), IterAdapter< POS, CON >::operator++(), and IterAdapter< POS, CON >::operator->().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ENABLE_USE_IN_STD_RANGE_FOR_LOOPS()

template<class POS , class CON >
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS ( IterAdapter< POS, CON >  )

Member Data Documentation

◆ source_

template<class POS , class CON >
CON source_
private

◆ pos_

Friends And Related Symbol Documentation

◆ operator==

template<class POS , class CON >
template<class P1 , class P2 , class CX >
bool operator== ( IterAdapter< P1, CX > const &  ,
IterAdapter< P2, CX > const &   
)
friend

comparison is allowed to access impl iterator

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

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