next up previous contents
Next: Iterating for all Up: Iterators Previous: Hostile string iterators

Other non-pointer Point iterators

Some iterators can not return pointers (because there is no persistent instance of the object to reference). For example to iterate over a set of points that is generated functional (contrasted with a set that exists as a collection).

For example to iterate over all the points of the board

class AllPointIterator
{
public:
    AllPointIterator();
    Point       ptNext();
    BOOL        more() const;
    void        reset();

private:
    PointRep    _nextRep;
};

Or just the edge points.

class AllEdgePointIterator
{
  public:
    AllEdgePointIterator();
    Point       ptNext();
    BOOL        more() const;
    void        reset();
private:
    int      _i;
    int      _side;
    int      _width;
};

An example of iterating around all the edge points.

AllEdgePointIterator ptIter;
Point pt;

gui.displayCursor(TRUE);

while(ptIter.more())
{
    pt=ptIter.ptNext();
    gui.setCursorXY(pt.x(),pt.y());
    gui.pauseHit(" hit a key ");
}



P J Leonard
Tue Oct 1 15:25:19 BST 1996