Tulip  5.6.3
Large graphs analysis and drawing
tlp::StableIterator< T > Class Template Reference

#include <StableIterator.h>

+ Inheritance diagram for tlp::StableIterator< T >:
+ Collaboration diagram for tlp::StableIterator< T >:

Public Member Functions

 StableIterator (Iterator< T > *inputIterator, size_t nbElements=0, bool deleteIterator=true, bool sortCopy=false)
bool hasNext ()
next ()
void restart ()
- Public Member Functions inherited from tlp::Iterator< T >
iterator_t begin ()
iterator_t end ()

Protected Attributes

std::vector< T >::const_iterator copyIterator
std::vector< T > sequenceCopy

Detailed Description

template<typename T>
class tlp::StableIterator< T >

Stores the elements of an iterator and iterates 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.

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 operation is not possible since we modify the graph.

StableIterator<node> it(graph->getNodes());
while(it.hasNext()) {
node n = it.next();
if (myfunc(n))

Definition at line 60 of file StableIterator.h.

Constructor & Destructor Documentation

◆ StableIterator()

template<typename T >
tlp::StableIterator< T >::StableIterator ( Iterator< T > *  inputIterator,
size_t  nbElements = 0,
bool  deleteIterator = true,
bool  sortCopy = false 

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

inputIteratorInput Iterator, which defines the sequence on which this Iterator will iterate.
nbElementsThe number of elements the iteration will take place on. Defaults to 0.
deleteIteratorWhether or not to delete the Iterator given as first parameter. Defaults to true.

Definition at line 72 of file StableIterator.h.

Member Function Documentation

◆ hasNext()

template<typename T >
bool tlp::StableIterator< T >::hasNext ( )

Tells if the sequence is at its end.

bool Whether there are more elements to iterate.

Implements tlp::Iterator< T >.

Definition at line 97 of file StableIterator.h.

◆ next()

template<typename T >
T tlp::StableIterator< T >::next ( )

Moves the Iterator on the next element.

The current element pointed by the Iterator.

Implements tlp::Iterator< T >.

Definition at line 91 of file StableIterator.h.

◆ restart()

template<typename T >
void tlp::StableIterator< T >::restart ( )

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


Definition at line 107 of file StableIterator.h.

Member Data Documentation

◆ copyIterator

template<typename T >
std::vector<T>::const_iterator tlp::StableIterator< T >::copyIterator

STL const_iterator on the cloned sequence.

Definition at line 120 of file StableIterator.h.

◆ sequenceCopy

template<typename T >
std::vector<T> tlp::StableIterator< T >::sequenceCopy

A copy of the sequence of the elements to iterate.

Definition at line 115 of file StableIterator.h.