gatb.core-API-1.4.2
ProductIterator< T1, T2 > Class Template Reference

Iterator over two iterators. More...

#include <IteratorHelpers.hpp>

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

Public Member Functions

 ProductIterator (Iterator< T1 > &it1, Iterator< T2 > &it2)
 
virtual ~ProductIterator ()
 
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>
class gatb::core::tools::dp::impl::ProductIterator< T1, T2 >

Iterator over two iterators.

We define a "product" iterator for two iterators, i.e. it will loop each possible couple of the two provided iterators.

It is useful for having only one loop instead of two loops. Note however that it may still be more efficient to have two loops. The CartesianIterator is just here for easing the product iteration on small sets.

NOTE: most likely it doesn't work in combination with Dispatcher, see PairedIterator for how to fix

Example:

// We include what we need for the test
#include <list>
#include <iostream>
/********************************************************************************/
/* Iteration of a Cartesian product of two iterators */
/********************************************************************************/
int main (int argc, char* argv[])
{
// We declare a STL list with some values.
int values1[] = {1,2,3,5,8,13,21,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 two iterators on the two lists.
ListIterator<int> it1 (l1);
ListIterator<float> it2 (l2);
// We declare a Cartesian iterator on the two iterators.
ProductIterator<int,float> it (it1, it2);
// We iterate the Cartesian product of the two lists
for (it.first(); !it.isDone(); it.next())
{
std::cout << it->first << " -- " << it->second << std::endl;
}
}

Constructor & Destructor Documentation

ProductIterator ( Iterator< T1 > &  it1,
Iterator< T2 > &  it2 
)
inline

Constructor.

Parameters
[in]it1: first iterator.
[in]it2: second iterator.
virtual ~ProductIterator ( )
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: