Overview     Modules     Class Hierarchy     Classes     Members  

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

That class enables to store elements of an iterator and to iterate 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

Protected Attributes

  • std::vector< itType > cloneIt
  • std::vector< itType >
    ::const_iterator itStl

Detailed Description

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

That class enables to store elements of an iterator and to iterate on a copy.

That iterator store all elements accessible by the input iterator into an internal data structure (created at the construction) and then only use that structure for the iteration. Order of iteration is the same. If one knows the number of elements that will be iterated one could give give it in paremeters to speed up the duplication process.

Warning:
By default StableIterator manage the destruction of the iterator given in parameter, (ie, delete will be call on the input iterator).

That class is really useful when one need 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 > *  itIn,
size_t  nbElements = 0,
bool  deleteIterator = true 
) [inline]
template<class itType>
tlp::StableIterator< itType >::~StableIterator (  )  [inline]

Member Function Documentation

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

Return true if it exist a next element.

Implements tlp::Iterator< itType >.

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

Return the next element.

Implements tlp::Iterator< itType >.

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

Enables to restart the iteration at the begining.


Member Data Documentation

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


Tulip Software by LaBRI Visualization Team    2001 - 2011