Instruction Manual
current object. There are various methods for moving this mark. For example, most of the time
you will probably be using member function operator(). In Tools.h++, it is designed to always
advance to the next object, then return either TRUE or a pointer to the next object, depending
on whether the associated collection class is value-based or reference-based, respectively. It
always returns FALSE (i.e., zero) when the end of the collection class is reached. Hence, a
simple canonical form for using an iterator is:
RWSlistCollectable list;
.
.
.
RWSlistCollectableIterator iterator(list);
RWCollectable* next;
while (next = iterator()) {
.
. // (use next)
.
}
As an alternative, you can also use the prefix increment operator ++X. Some iterators have
other member functions for manipulating the mark, such as findNext() or removeNext().
Member function key() always returns either the current object or a pointer to the current object,
again depending on whether the collection class is value-based or reference-based, respectively.
For most collection classes, using member function apply() to access every member is much
faster than using an iterator. This is particularly true for the sorted collection classes_usually a
tree has to be traversed here, requiring that the parent of a node be stored on a stack. Function
apply() uses the program's stack, while the sorted collection class iterator must maintain its
own. The former is much faster.