gatb.core-API-1.4.2
CompositeIterator< Item > Class Template Reference

Composite iterator. More...

#include <IteratorHelpers.hpp>

Inheritance diagram for CompositeIterator< Item >:
Inheritance graph

Public Member Functions

 CompositeIterator (std::vector< Iterator< Item > * > &iterators)
 
virtual ~CompositeIterator ()
 
void first ()
 
void next ()
 
bool isDone ()
 
Item & item ()
 
void setItem (Item &i)
 
virtual std::vector< Iterator< Item > * > getComposition ()
 
- Public Member Functions inherited from Iterator< Item >
Item * operator-> ()
 
Item & operator* ()
 
template<typename Functor >
void iterate (const Functor &f)
 
bool get (std::vector< Item > &current)
 
virtual void reset ()
 
virtual void finalize ()
 
- Public Member Functions inherited from SmartPointer
void use ()
 
void forget ()
 
- Public Member Functions inherited from ISmartPointer
virtual ~ISmartPointer ()
 

Additional Inherited Members

- Protected Member Functions inherited from SmartPointer
 SmartPointer ()
 
virtual ~SmartPointer ()
 

Detailed Description

template<class Item>
class gatb::core::tools::dp::impl::CompositeIterator< Item >

Composite iterator.

This iterator takes a list of iterators as input and iterates each one of these iterators.

Example:

// We include what we need for the test
#include <vector>
#include <iostream>
/********************************************************************************/
/* Iteration of a two iterators by pairs of items */
/********************************************************************************/
int main (int argc, char* argv[])
{
// We declare a STL list with some values.
float values1[] = {13,5,34};
std::list<float> l1 (values1, values1 + sizeof(values1)/sizeof(values1[0]) );
// We declare a STL list with some values.
float values2[] = {0.5, 3.1415, 2.71};
std::list<float> l2 (values2, values2 + sizeof(values2)/sizeof(values2[0]) );
std::vector<Iterator<float>*> iterators;
iterators.push_back (new ListIterator<float>(l1));
iterators.push_back (new ListIterator<float>(l2));
// We declare a composite iterator for the two iterators.
CompositeIterator<float> it (iterators);
// We iterate the pairs of the two lists
for (it.first(); !it.isDone(); it.next())
{
std::cout << it.item() << std::endl;
}
}

Constructor & Destructor Documentation

CompositeIterator ( std::vector< Iterator< Item > * > &  iterators)
inline

Constructor.

Parameters
[in]iterators: the iterators vector
virtual ~CompositeIterator ( )
inlinevirtual

Destructor.

Member Function Documentation

void first ( )
inlinevirtual

Method that initializes the iteration.

Implements Iterator< Item >.

virtual std::vector<Iterator<Item>*> getComposition ( )
inlinevirtual

Get a vector holding the composite structure of the iterator.

Reimplemented from Iterator< Item >.

bool isDone ( )
inlinevirtual

Method telling whether the iteration is finished or not.

Returns
true if iteration is finished, false otherwise.

Implements Iterator< Item >.

Item& item ( )
inlinevirtual

Method that returns the current iterated item. Note that the returned type is the template type.

Returns
the current item in the iteration.

Implements Iterator< Item >.

void next ( )
inlinevirtual

Method that goes to the next item in the iteration.

Returns
status of the iteration

Implements Iterator< Item >.

void setItem ( Item &  i)
inlinevirtual

IMPORTANT : the Item argument provided to 'setItem' must be the object to be modified by one of the delegate iterator AND NOT the current item of CompositeIterator. Therefore, we make point the delegate current item to this provided Item argument.

Reimplemented from Iterator< Item >.


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