TruncateIterator< Item > Class Template Reference

Iterator that truncate the number of iterations if needed. More...

#include <IteratorHelpers.hpp>

Inheritance diagram for TruncateIterator< Item >:
Inheritance graph

Public Member Functions

 TruncateIterator (Iterator< Item > &ref, u_int64_t limit, bool initRef=true)
void first ()
void next ()
bool isDone ()
Item & item ()
- Public Member Functions inherited from Iterator< Item >
Item * operator-> ()
Item & operator* ()
template<typename Functor >
void iterate (const Functor &f)
virtual void setItem (Item &i)
bool get (std::vector< Item > &current)
virtual void reset ()
virtual void finalize ()
virtual std::vector< Iterator< Item > * > 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 Item>
class gatb::core::tools::dp::impl::TruncateIterator< Item >

Iterator that truncate the number of iterations if needed.

This iterator iterates a referred iterator and will finish:

  • when the referred iterator is over or - when a limit number of iterations is reached.


// We include what we need for the test
#include <list>
#include <iostream>
/* Iteration of a part of an iterator */
int main (int argc, char* argv[])
// We declare a STL list with some values.
int values[] = {1,2,3,5,8,13,21,34};
int valuesLen = sizeof(values)/sizeof(values[0]);
std::list<int> l (values, values + valuesLen);
// We declare one iterator on the list
ListIterator<int> it (l);
// We declare a truncated iterator for the list iterator.
TruncateIterator<int> itTrunc (it, valuesLen/2);
// We iterate the truncated list
for (itTrunc.first(); !itTrunc.isDone();
std::cout << *itTrunc << std::endl;

Constructor & Destructor Documentation

TruncateIterator ( Iterator< Item > &  ref,
u_int64_t  limit,
bool  initRef = true 


[in]ref: the referred iterator
[in]limit: the maximal number of iterations.
[in]initRef: will call 'first' on the reference if true

Member Function Documentation

void first ( )

Method that initializes the iteration.

Implements Iterator< Item >.

bool isDone ( )

Method telling whether the iteration is finished or not.

true if iteration is finished, false otherwise.

Implements Iterator< Item >.

Item& item ( )

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

the current item in the iteration.

Implements Iterator< Item >.

void next ( )

Method that goes to the next item in the iteration.

status of the iteration

Implements Iterator< Item >.

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