gatb.core-API-0.0.0
PairedIterator< T1, T2 > Class Template Reference

Iterator over two iterators. More...

#include <IteratorHelpers.hpp>

Inheritance diagram for PairedIterator< T1, T2 >:
Inheritance graph

Public Member Functions

 PairedIterator (Iterator< T1 > *it1, Iterator< T2 > *it2)
 
virtual ~PairedIterator ()
 
void first ()
 
void next ()
 
bool isDone ()
 
std::pair< T1, T2 > & item ()
 
- Public Member Functions inherited from Iterator< std::pair< T1, T2 > >
std::pair< T1, T2 > * operator-> ()
 
std::pair< T1, T2 > & operator* ()
 
void iterate (const Functor &f)
 
virtual void setItem (std::pair< T1, T2 > &i)
 
bool get (std::vector< std::pair< T1, T2 > > &current)
 
virtual void reset ()
 
virtual void finalize ()
 
virtual std::vector< Iterator< std::pair< T1, T2 > > * > getComposition ()
 
- 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 T1, class T2 = T1>
class gatb::core::tools::dp::impl::PairedIterator< T1, T2 >

Iterator over two iterators.

We define a an iterator for two iterators, by iterating each of the two iterators and providing a pair of the two currently iterated items.

Example:

// We include what we need for the test
#include <list>
#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.
int values1[] = {13,5,34};
std::list<int> 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]) );
// We declare a paired iterator on the two iterators.
PairedIterator<int,float> it (new ListIterator<int>(l1), new ListIterator<float>(l2));
// We iterate the pairs of the two lists
for (it.first(); !it.isDone(); it.next())
{
std::cout << it->first << " -- " << it->second << std::endl;
}
}

Constructor & Destructor Documentation

PairedIterator ( Iterator< T1 > *  it1,
Iterator< T2 > *  it2 
)
inline

Constructor.

Parameters
[in]it1: first iterator.
[in]it2: second iterator.
virtual ~PairedIterator ( )
inlinevirtual

Destructor.

Member Function Documentation

void first ( )
inlinevirtual

Method that initializes the iteration.

Implements Iterator< std::pair< T1, T2 > >.

bool isDone ( )
inlinevirtual

Method telling whether the iteration is finished or not.

Returns
true if iteration is finished, false otherwise.

Implements Iterator< std::pair< T1, T2 > >.

std::pair<T1,T2>& 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< std::pair< T1, T2 > >.

void next ( )
inlinevirtual

Method that goes to the next item in the iteration.

Returns
status of the iteration

Implements Iterator< std::pair< T1, T2 > >.


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