#ifndef LISTITERATOR_HH #define LISTITERATOR_HH /* * Name: Geoff Kuenning * Course: CS 70, Spring 2000 * Assignment #8 * * This file contains the interface for the ListIterator class. This class * supports iteration over lists defined in the list.hh file. * * Normally, this file would be part of list.hh, since lists and their * iterators are tied so closely together. It is provided separately * only because students are expected to provide their own list class. * * Requirements for the DATA class: * The DATA class must support copy construction for the list * class to be useful. No other functions are required, but if * DATA supports input or output, then the list class will * support the corresponding functions. * * The ListIterator class provides forward-iterator access to list * elements. Note that all iterators are inactivated whenever any * element is removed from the list. * * The following operations are supported: * * Constructors and destructors: * Zero-argument construction is not allowed. The constructor * must specify a target list that is to be iterated over. A * copy constructor is also provided. * Operators: * = Assignment between iterators. * bool Typecast to boolean. Returns true if the * iterator currently refers to a valid list * element, false if the iterator has been * stepped past the end of the list. * * Access. Returns a reference to the DATA item * stored by the current list element. Normally * used as "x = *iterator;". * -> Access. Returns a pointer to the DATA item * stored by the current list element. Normally * used as "x = iterator->member;". * ++ Incrementation. Steps the iterator to the * next list element. Available in both prefix * and postfix versions, properly implemented to * return the iterator after or before * incrementation, respectively. */ #include #include "list.hh" /* * Table of contents: the following classes are defined in this file */ template class ListIterator; /* * The ListIterator class. See above for documentation of the public * functions. */ template class ListIterator { public: ListIterator(const List& source); ListIterator(const ListIterator& source); ~ListIterator(); ListIterator& operator=(const ListIterator& source); operator bool() const; // Test for more data DATA& operator*() const; // Provide member access DATA* operator->() const; // Provide member access ListIterator& operator++(); // Pre-incrementation ListIterator operator++(int); // Post-incrementation void reset(); // Reset to beginning of list private: /* * Private data members */ const List& target; // Target of the iterator List::Element* current; // Current data element }; #include "listiterator.icc" #endif // LISTITERATOR_HH