Overview     Modules     Class Hierarchy     Classes     Members  

tlp::StableIterator< itType > Class Template Reference
[Iterators]

Stores the elements of an iterator and iterates on a copy. More...

#include <StableIterator.h>

Inheritance diagram for tlp::StableIterator< itType >:
Collaboration diagram for tlp::StableIterator< itType >:

List of all members.

Public Member Functions

  • StableIterator (Iterator< itType > *inputIterator, size_t nbElements=0, bool deleteIterator=true)
    Creates a stable Iterator, that allows to delete elements from a graph while iterating on them.
  • ~StableIterator ()
  • itType next ()
    Moves the Iterator on the next element.
  • bool hasNext ()
    Tells if the sequence is at its end.
  • void restart ()
    Restarts the iteration by moving the Iterator to the beginning of the sequence.

Protected Attributes

  • std::vector< itType > sequenceCopy
    A copy of the sequence of elements to iterate on.
  • std::vector< itType >
    ::const_iterator copyIterator
    STL const_iterator on the cloned sequence.

Detailed Description

template<class itType>
class tlp::StableIterator< itType >

Stores the elements of an iterator and iterates on a copy.

THis Iterator stores all the elements accessible by another Iterator into an internal data structure (created at the construction), and then uses this structure for the iteration. Iteration order is the same.

Warning:
By default StableIterator takes ownership of the iterator given in parameter, (ie, delete will be called on the input iterator). The deletion takes place when constructing the StableIterator.

This class is really useful when one needs to modify the graph during an iteration. For instance the following code remove all nodes that match the function myfunc(). Using standard iterators for that operations is not possible since we modify the graph.

 StableIterator<node> it(graph->getNodes());
 while(it.hasNext()) {
  node n = it.next();
  if (myfunc(n))
     graph->delNode(n);
 }
See also:
stableForEach

Constructor & Destructor Documentation

template<class itType>
tlp::StableIterator< itType >::StableIterator ( Iterator< itType > *  inputIterator,
size_t  nbElements = 0,
bool  deleteIterator = true 
) [inline]

Creates a stable Iterator, that allows to delete elements from a graph while iterating on them.

Parameters:
inputIterator Input Iterator, which defines the sequence on which this Iterator will iterate.
nbElements The number of elements the iteration will take place on. Defaults to 0.
deleteIterator Whether or not to delete the Iterator given as first parameter. Defaults to true.
template<class itType>
tlp::StableIterator< itType >::~StableIterator (  )  [inline]

Member Function Documentation

template<class itType>
bool tlp::StableIterator< itType >::hasNext (  )  [inline, virtual]

Tells if the sequence is at its end.

Returns:
bool Whether there are more elements to iterate on.

Implements tlp::Iterator< itType >.

template<class itType>
itType tlp::StableIterator< itType >::next (  )  [inline, virtual]

Moves the Iterator on the next element.

Returns:
The current element pointed by the Iterator.

Implements tlp::Iterator< itType >.

template<class itType>
void tlp::StableIterator< itType >::restart (  )  [inline]

Restarts the iteration by moving the Iterator to the beginning of the sequence.

Returns:
void

Member Data Documentation

template<class itType>
std::vector<itType>::const_iterator tlp::StableIterator< itType >::copyIterator [protected]

STL const_iterator on the cloned sequence.

template<class itType>
std::vector<itType> tlp::StableIterator< itType >::sequenceCopy [protected]

A copy of the sequence of elements to iterate on.



Tulip Software by LaBRI Visualization Team    2001 - 2012