gatb.core-API-0.0.0
|
Definition of the Design Pattern Iterator interface. More...
#include <Iterator.hpp>
Public Member Functions | |
virtual void | first ()=0 |
virtual void | next ()=0 |
virtual bool | isDone ()=0 |
virtual Item & | item ()=0 |
Item * | operator-> () |
Item & | operator* () |
template<typename Functor > | |
void | iterate (const Functor &f) |
virtual void | setItem (Item &i) |
bool | get (std::vector< Item > ¤t) |
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 () |
Definition of the Design Pattern Iterator interface.
The Iterator concept is here reified as a template class that knows how to iterate some set of objects.
Actually, the interface has two ways for iterating instances: 1- the 'classic' one in terms of Iterator Design Pattern (see first/next/isDone methods) 2- a callback way (see 'iterate' methods) where some client provides a callback that will be called for each object
There may be good reasons for using one way or another. For instance, the first one may be easier to use by clients (no extra method to be defined) but may be less efficient because more methods calls will be carried out.
Note that 'iterate' has great subclassing potentiality; by default, its implementation relies on first/isDone/next/currentItem methods and so can't be faster that the 'classic' way. But specific implementations of Iterator may implement 'iterate' directly by using inner state of the class, and so without call to first/isDone/next/currentItem methods.
Note that for optimization point of view, an algorithm prefers to use the 'iterate' way with optimized implementations.
Sample of use:
A remark on the STL: the Standard Template Library provides also the iterator concept. For instance, one could write:
We can see the following differences with our own iterator.
In brief, our iterator encapsulates more information that the STL iterator, allows to iterate potential containers (versus actual containers) and may be easier to use.
Moreover, we can use our iterator as a basis for other ways for iteration.
note (GR): this iterator system looks like the range of C++11, now that we use C++11, we could switch to range:
for ( MyType elem : range ) { // use elem }
it has the same benefits as the listed benefits of the Iterator class, IMHO
|
inlinevirtual |
Method that may be called when an iteration is done. Does nothing by default.
|
pure virtual |
Method that initializes the iteration.
Implemented in IteratorAdaptor< T1, T2, Adaptor >, CompositeIterator< Item >, STLIterator< Container, Type >, STLIterator< std::vector< Type >, Type >, STLIterator< std::list< Type >, Type >, FilterIterator< Item, Filter >, CancellableIterator< Item >, TruncateIterator< Item >, CompoundIterator< T1, T2, Update >, SubjectIterator< Item >, SubjectIterator< Type >, PairedIterator< T1, T2 >, BankFasta::Iterator, BankBinary::Iterator, IteratorFile< Item >, ProductIterator< T1, T2 >, TokenizerIterator, and NullIterator< Item >.
|
inline |
Retrieve some iterated items in a vector. NOTE: In general, this method should be protected against concurrent accesses (IteratorCommand::execute)
[in] | current | : vector to be filled with iterated items. May be resized if not enough items available |
|
inlinevirtual |
Get a vector holding the composite structure of the iterator.
Reimplemented in CompositeIterator< Item >, SubjectIterator< Item >, and SubjectIterator< Type >.
|
pure virtual |
Method telling whether the iteration is finished or not.
Implemented in IteratorAdaptor< T1, T2, Adaptor >, CompositeIterator< Item >, STLIterator< Container, Type >, STLIterator< std::vector< Type >, Type >, STLIterator< std::list< Type >, Type >, FilterIterator< Item, Filter >, CancellableIterator< Item >, TruncateIterator< Item >, CompoundIterator< T1, T2, Update >, SubjectIterator< Item >, SubjectIterator< Type >, PairedIterator< T1, T2 >, BankFasta::Iterator, ProductIterator< T1, T2 >, BankBinary::Iterator, IteratorFile< Item >, TokenizerIterator, and NullIterator< Item >.
|
pure virtual |
Method that returns the current iterated item. Note that the returned type is the template type.
Implemented in IteratorAdaptor< T1, T2, Adaptor >, CompositeIterator< Item >, STLIterator< Container, Type >, STLIterator< std::vector< Type >, Type >, STLIterator< std::list< Type >, Type >, FilterIterator< Item, Filter >, CancellableIterator< Item >, TruncateIterator< Item >, CompoundIterator< T1, T2, Update >, SubjectIterator< Item >, SubjectIterator< Type >, PairedIterator< T1, T2 >, BankFasta::Iterator, ProductIterator< T1, T2 >, BankBinary::Iterator, IteratorFile< Item >, TokenizerIterator, and NullIterator< Item >.
|
inline |
Another way to iterate: push model, ie a functor is called for each item.
|
pure virtual |
Method that goes to the next item in the iteration.
Implemented in IteratorAdaptor< T1, T2, Adaptor >, CompositeIterator< Item >, STLIterator< Container, Type >, STLIterator< std::vector< Type >, Type >, STLIterator< std::list< Type >, Type >, FilterIterator< Item, Filter >, CancellableIterator< Item >, TruncateIterator< Item >, CompoundIterator< T1, T2, Update >, SubjectIterator< Item >, SubjectIterator< Type >, PairedIterator< T1, T2 >, BankFasta::Iterator, BankBinary::Iterator, ProductIterator< T1, T2 >, IteratorFile< Item >, TokenizerIterator, and NullIterator< Item >.
|
inline |
Operator overload as a shortcut for the 'item' method.
|
inline |
Operator overload as a shortcut for the 'item' method.
|
inlinevirtual |
Reset the iterator.
Reimplemented in SubjectIterator< Item >, and SubjectIterator< Type >.
|
inlinevirtual |
Get a reference on the object to be configured as the currently iterated item.
[in] | i | : object to be referred. |
Reimplemented in CompositeIterator< Item >, SubjectIterator< Item >, and SubjectIterator< Type >.