UT_Iterator< ELEMENT, CONTAINER > Class Template Reference

#include <UT_Iterator.h>

List of all members.

Public Member Functions

 UT_Iterator (const CONTAINER &container, UT_NotifierImpl< UT_IteratorEvent & > *notifier, int idx=0, bool reverse=false)
bool isValid ()
 Returns true if the iterator points to a valid element.
ELEMENT current ()
bool next ()
int index ()
template<typename ELEMENT_OUT >
bool get (ELEMENT_OUT &e)


Detailed Description

template<typename ELEMENT, typename CONTAINER>
class UT_Iterator< ELEMENT, CONTAINER >

Generic iterator class for containers.

The container class *must* have the following: an "ELEMENT operator(int index) const" method an "int entries() const" method a "const ELEMENT &null() const" method

The container class should have the following: a typedef of the form "typedef UT_Iterator<ELEMENT, MyContainer> Iterator;" an iterator(int index = 0) method that returns a new (forward) iterator. optionally also an iteratorReverse(int index = 0) method.

See UT_Pointers for an example implementation.

Definition at line 55 of file UT_Iterator.h.


Constructor & Destructor Documentation

template<typename ELEMENT, typename CONTAINER>
UT_Iterator< ELEMENT, CONTAINER >::UT_Iterator ( const CONTAINER &  container,
UT_NotifierImpl< UT_IteratorEvent & > *  notifier,
int  idx = 0,
bool  reverse = false 
) [inline]

NOTE: index counts from the *end* if reverse is true. This is to preserve old UT_Pointers behaviour.

Definition at line 61 of file UT_Iterator.h.


Member Function Documentation

template<typename ELEMENT, typename CONTAINER>
ELEMENT UT_Iterator< ELEMENT, CONTAINER >::current (  )  [inline]

Do not call this function on invalid iterators, as there is no sensible value to return in that case.

Definition at line 88 of file UT_Iterator.h.

template<typename ELEMENT, typename CONTAINER>
template<typename ELEMENT_OUT >
bool UT_Iterator< ELEMENT, CONTAINER >::get ( ELEMENT_OUT &  e  )  [inline]

This is for code that wants to loop like: for(CONTAINER::Iterator it=p.iterator(); it.get(s); ) { do stuff }

instead of: for(CONTAINER::Iterator it=p.iterator(); it.isValid(); it.next()) { ELEMENT e = it.current(); do stuff }

Note that this function is templated so that the type can be inferred.

Definition at line 134 of file UT_Iterator.h.

template<typename ELEMENT, typename CONTAINER>
int UT_Iterator< ELEMENT, CONTAINER >::index ( void   )  [inline]

Do not call this function on invalid iterators, as there is no sensible value to return in that case.

Definition at line 115 of file UT_Iterator.h.

template<typename ELEMENT, typename CONTAINER>
bool UT_Iterator< ELEMENT, CONTAINER >::isValid ( void   )  [inline]

Returns true if the iterator points to a valid element.

Definition at line 81 of file UT_Iterator.h.

template<typename ELEMENT, typename CONTAINER>
bool UT_Iterator< ELEMENT, CONTAINER >::next (  )  [inline]

This function returns true if the iterator was valid before the next() operation. Note that it may be invalid after the next() operation. (because it just moved off the end of the list, for example)

Definition at line 98 of file UT_Iterator.h.


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

Generated on Fri May 25 00:10:50 2012 for HDK by  doxygen 1.5.9