/** * iterator.h * Implemented by Blueprint Technologies, Inc. */ #ifndef _iterator_h #define _iterator_h /** * forward declarations */ class Iterator; class ConcreteIterator; class ConcreteAggregate; /** * Defines an interface for creating an Iterator object. */ class Aggregate { public: Aggregate(); virtual Iterator* createIterator() = 0; }; /** * Defines an interface for accessing and traversing elements. */ class Iterator { public: virtual int first() = 0; virtual int next() = 0; virtual int isDone() = 0; virtual int currentItem() = 0; }; /** * Implements the Iterator creation interface to return an instance * of the proper ConcreteIterator. */ class ConcreteAggregate: public Aggregate { public: /** * Simple data structure to traverse. */ int storage[ 1000 ]; /** * Return the proper iterator for * this type of aggregate. */ virtual Iterator* createIterator(); }; /** * Implements the Iterator interface. Keeps track of the current * position in the traversal of the aggregate. */ class ConcreteIterator: public Iterator { private: int current; ConcreteAggregate* root; public: ConcreteIterator( ConcreteAggregate* root ); virtual int first(); virtual int next(); virtual int isDone(); virtual int currentItem(); }; #endif