Lumiera  0.pre.03
»edit your freedom«
TestContainer Class Reference

Description

Example of a more elaborate custom container exposing an iteration API.

While the demo implementation here is based on pointers within a vector, we hand out a IterAdapter, which will call back when used by the client, thus allowing us to control the iteration process. Moreover, we provide a variant of this iterator, which automatically dereferences the pointers, thus yielding direct references for the client code to use.

Definition at line 92 of file iter-adapter-test.cpp.

Public Types

typedef IterAdapter< _Vec::const_iterator, const TestContainer * > const_iterator
 
typedef PtrDerefIter< const_iteratorconst_ref_iter
 
typedef IterAdapter< _Vec::iterator, const TestContainer * > iterator
 
typedef PtrDerefIter< iteratorref_iterator
 

Public Member Functions

 TestContainer (uint count)
 
iterator begin ()
 
const_iterator begin () const
 
ref_iterator begin_ref ()
 
const_ref_iter begin_ref () const
 
iterator end ()
 
const_iterator end () const
 
size_t size () const
 

Friends

template<class ITER >
bool checkPoint (const TestContainer *src, ITER &pos)
 Implementation of Iteration-logic: detect iteration end. More...
 
template<class ITER >
void iterNext (const TestContainer *, ITER &pos)
 Implementation of Iteration-logic: pull next element. More...
 

Private Types

typedef vector< int * > _Vec
 

Static Private Member Functions

static void killIt (int *it)
 

Private Attributes

_Vec numberz_
 

Friends And Related Function Documentation

◆ iterNext

void iterNext ( const TestContainer ,
ITER &  pos 
)
friend

Implementation of Iteration-logic: pull next element.

Remarks
typically the implementation is simplistic, since the way this extension point is called from IterAdapter ensures that _pos is still valid_ and that the checkPoint() function is invoked immediately afterwards, allowing to adjust pos if necessary

Definition at line 146 of file iter-adapter-test.cpp.

◆ checkPoint

bool checkPoint ( const TestContainer src,
ITER &  pos 
)
friend

Implementation of Iteration-logic: detect iteration end.

Note
the problem here is that this implementation chooses to use two representations of ⟂ ("bottom", end, invalid). The reason is, we want the default-constructed IterAdapter also be the ⟂ value. This is in accordance with the »Lumiera Forward Iterator« concept, which requires the default constructed iterator to mark the iteration end and to evaluate to bool(false). Thus, when we detect the iteration end by internal logic (numberz_.end() ), we immediately transform this into the official "bottom"

Definition at line 163 of file iter-adapter-test.cpp.

+ Collaboration diagram for TestContainer:

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