Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
PreIterator< I, T > Class Template Reference

#include <elm/iter.h>

Public Types

typedef T t
 
typedef T return_t
 

Public Member Functions

bool operator() () const
 
bool operator! () const
 
operator* () const
 
operator-> () const
 
I & operator++ ()
 
void operator++ (int)
 
bool operator== (const I &i) const
 
bool operator!= (const I &i) const
 

Detailed Description

template<class I, class T>
class elm::PreIterator< I, T >

This class is an helper in the writing of iterators. It avoids to redefine all iterator operators each time an operator is defined. The user of this class has just to define four methods:

  • bool ended() const – that returns true when the iteration ends,
  • bool equals(const Iterator& i) const – to test if two iterators are equal,
  • void next() – to move to the next item,
  • T item() const – to get the current item (if any).

Using these 4 functions, PreIterator is able to support the operators (), !, ++ (prefix), ++ (suffix), *, ->, == and !=.

For example, the iterator on an array can be written as:

template <class T>
class ArrayIter: public PreIterator<ArrayIter, T> {
public:
inline ArrayIter(int number, T *array)
: n(number), i(0), a(array) { }
inline bool ended() const { return i >= n; }
inline bool equals(const ArrayIter& it)
{ return a == it.a && n == it.n && i == it.i; }
inline void next() { i++; }
inline T item() const { return a[i]; }
private:
int n, i;
T *a;
};
Parameters
IType of the defined iterator.
TType of the items.

Member Typedef Documentation

◆ return_t

typedef T return_t

◆ t

t

Type of the element held by the iterator.

Member Function Documentation

◆ operator!()

bool operator! ( ) const
inline

Test if the iteration is not ended.

Returns
True if the iteration is not ended, false else.

◆ operator!=()

bool operator!= ( const I &  i) const
inline

Test if the current iterator and the argument iterator are different.

Returns
True if both operators are different, false else.

◆ operator()()

bool operator() ( ) const
inline

Test if the iteration is ended.

Returns
True if the iteration is ended, false else.

◆ operator*()

T operator* ( ) const
inline

Get the current item of the iterator. It is forbidden to call this function if the iteration is ended.

Returns
Current iterator item.

◆ operator++() [1/2]

I & operator++ ( )
inline

Move the iterator to the next item. It is forbidden to call this function if the iteration is ended.

Returns
This iterator.

◆ operator++() [2/2]

void operator++ ( int  )
inline

Move the iterator to the next item. It is forbidden to call this function if the iteration is ended.

◆ operator->()

T operator-> ( ) const
inline

Get the current item of the iterator as a deferenced pointer. It is forbidden to call ths function if the iteration is ended.

Returns
Current iterator item.

◆ operator==()

bool operator== ( const I &  i) const
inline

Test if the current iterator and the argument iterator are equal.

Returns
True if both operators are equal, false else.

The documentation for this class was generated from the following files:
elm::equals
bool equals(const C1 &c1, const C2 &c2)
Definition: util.h:107
array