NAME
OTC_PairIterator -
Interface to a cursor of a key/item pair.
SYNOPSIS
#include <OTC/collctn/pritertr.hh>
template<class T1, class T2>
class OTC_PairIterator
{
public:
static os_typespec* get_os_typespec();
inline ~OTC_PairIterator();
inline OTC_PairIterator();
inline OTC_PairIterator(OTC_PairCursor<T1,T2>* theIter);
inline OTC_PairIterator(OTC_PairIterator<T1,T2> const& theIter);
inline OTC_PairIterator<T1,T2>& operator=(
OTC_PairCursor<T1,T2>* theIter
);
inline OTC_PairIterator<T1,T2>& operator=(
OTC_PairIterator<T1,T2> const& theIter
);
inline void next();
inline void reset();
inline T1 const& key() const;
inline T2 const& item() const;
inline OTC_Boolean isValid() const;
inline OTC_PairIterator<T1,T2> clone() const;
inline void apply(OTC_PairVisitor<T1,T2>& theApplicator);
protected:
inline T2& _item() const;
inline OTC_PairCursor<T1,T2>* _clone() const;
inline void _apply(OTC_PairVisitor<T1,T2>& theApplicator);
inline void _apply(OTC_PairWorker<T1,T2>& theApplicator);
};
CLASS TYPE
Concrete
DESCRIPTION
This class exists so that the user of an iterator for collections
holding key/item pairs, does not have to worry about deleting the
iterator when finished with it, nor need to know how to create an
iterator for a specific type of collection. This class will ensure
that the iterator is destroyed, when this class goes out of scope.
In order for this to work correctly, an instance of this class
should never be created using new.
INITIALISATION
inline OTC_PairIterator();
inline OTC_PairIterator(OTC_PairCursor<T1,T2>* theIter);
Constructor used when an iterator
for a particular type of collection is
first created. Passing in 0 will
result in a nil iterator being
constructed.
inline OTC_PairIterator(OTC_PairIterator<T1,T2> const& theIter);
Copy constructor for when an iterator is
used as return type.
inline OTC_PairIterator<T1,T2>& operator=(
OTC_PairCursor<T1,T2>* theIter
);
Sets this iterator to theIter.
If theIter is 0, the iterator
is turned into a null iterator and
all associations with the previous
collection are lost.
inline OTC_PairIterator<T1,T2>& operator=(
OTC_PairIterator<T1,T2> const& theIter
);
Sets this iterator to theIter.
MOVEMENT
inline void next();
Moves the iterator to the next item.
inline void reset();
Resets the iterator to the start.
RETRIEVAL
inline T1 const& key() const;
Returns the key under the current
location of the iterator. Raises an
exception if there is no pair under the
iterator, or if this is a null iterator.
inline T2 const& item() const;
Returns the item under the current
location of the iterator. Raises an
exception if there is no pair under the
iterator, or if this is a null iterator.
inline OTC_Boolean isValid() const;
Returns OTCLIB_TRUE while there is a
valid data item under the current location
of the iterator.
CLONING
inline OTC_PairIterator<T1,T2> clone() const;
Returns an iterator which is a clone of
this iterator. The new iterator will
initially be located over the same item as
this iterator, however subsequent
operations will be independent of this
iterator.
APPLICATOR
inline void apply(OTC_PairVisitor<T1,T2>& theApplicator);
Applies theApplicator to each key/item
pair accessible by this iterator.
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1993 TELSTRA CORPORATION LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED