tlp::StableIterator< itType > Class Template Reference
[Iterators]
Stores the elements of an iterator and iterates on a copy.
More...
#include <StableIterator.h>
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
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. |
Member Function Documentation
Tells if the sequence is at its end.
- Returns:
- bool Whether there are more elements to iterate on.
Implements tlp::Iterator< itType >.
Restarts the iteration by moving the Iterator to the beginning of the sequence.
- Returns:
- void
Member Data Documentation
STL const_iterator on the cloned sequence.
A copy of the sequence of elements to iterate on.