home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 24 / PCPLUS115.iso / pcplus / tclite / include / iterator.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-28  |  1.7 KB  |  45 lines

  1. #ifndef    ITERATOR_H
  2. #define    ITERATOR_H
  3.  
  4. #include "object.h"
  5.  
  6. class Collection;
  7. class Link;
  8.  
  9. extern const Class class_Iterator;
  10.  
  11. class Iterator: public Object {
  12.     Collection* cltn;           // Collection being iterated over
  13. public:
  14.     int         index;          // index of next Object
  15.     Object*     ptr;            // pointer to current Object or NULL
  16.     unsigned    num;            // object number, used by Bags
  17. public:
  18.                             Iterator(const Collection&);
  19.     void                    reset();            // reset to beginning
  20.                                                 // of Collection
  21.     Object*                 operator++();       // advance to next object
  22.                                                 // in Collection
  23.     Collection*             collection() const  { return cltn; }
  24.     bool                    operator==(const Iterator&) const;
  25.     bool                    operator!=(const Iterator& a) const
  26.                                                 { return !(*this==a); }
  27.     virtual Object*         copy() const;       // shallowCopy()
  28.     virtual void            deepenShallowCopy();// copy with cltn->deepCopy()
  29.     virtual unsigned        hash() const;
  30.     virtual const Class*    isA() const;
  31.     virtual bool            isEqual(const Object&) const;
  32.     virtual void            printOn(ostream& strm) const;
  33.     virtual Object*         shallowCopy() const;// copy with cltn->copy()
  34.     virtual const Class*    species() const;
  35. };
  36.  
  37. #define DO(cltn,cls,arg)\
  38.         { cls arg; \
  39.             Iterator DO_pos(cltn); \
  40.             while ((arg = (cls)DO_pos++) != 0) \
  41.             {
  42. #define DONE }}
  43.  
  44. #endif
  45.