gatb.core-API-0.0.0
FilterIterator< Item, Filter > Class Template Reference

Iterator that filters out some iterated items. More...

#include <IteratorHelpers.hpp>

Inherits ISmartIterator< T >.

Public Member Functions

 FilterIterator (Iterator< Item > *ref, Filter filter)
 
 ~FilterIterator ()
 
void first ()
 
void next ()
 
bool isDone ()
 
Item & item ()
 
void setItem (Item &i)
 

Detailed Description

template<class Item, typename Filter>
class gatb::core::tools::dp::impl::FilterIterator< Item, Filter >

Iterator that filters out some iterated items.

This iterator iterates a referred iterator and will filter out some items according to a functor provided at construction.

Example:

// We include what we need for the test
#include <list>
#include <iostream>
/********************************************************************************/
// We a define a functor that will be called during iteration for filtering odd items.
struct FilterFunctor { bool operator () (int& val) { return val%2 == 0; } };
/********************************************************************************/
/* Iteration with filtering */
/********************************************************************************/
int main (int argc, char* argv[])
{
// We declare a STL list with some values.
int values[] = {1,2,3,5,8,13,21,34};
std::list<int> l (values, values + sizeof(values)/sizeof(values[0]));
// We declare a functor for filtering items.
FilterFunctor filter;
// We declare an iterator over list entries with filtering out odd values.
FilterIterator<int,FilterFunctor> it (new ListIterator<int> (l), filter);
// We iterate the truncated list
for (it.first(); !it.isDone(); it.next())
{
// We should have only even values here.
std::cout << *it << std::endl;
}
}

Constructor & Destructor Documentation

FilterIterator ( Iterator< Item > *  ref,
Filter  filter 
)
inline

Constructor.

Parameters
[in]ref: the referred iterator
[in]filter: the filter on items. Returns true if item is kept, false otherwise.
~FilterIterator ( )
inline

Destructor.

Member Function Documentation

void first ( )
inlinevirtual

Method that initializes the iteration.

Implements Iterator< T >.

bool isDone ( )
inlinevirtual

Method telling whether the iteration is finished or not.

Returns
true if iteration is finished, false otherwise.

Implements Iterator< T >.

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< T >.

void next ( )
inlinevirtual

Method that goes to the next item in the iteration.

Returns
status of the iteration

Implements Iterator< T >.

void setItem ( Item &  i)
inline

Get a reference on the object to be configured as the currently iterated item.

Parameters
[in]i: object to be referred.

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