home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmiter.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  2.6 KB  |  64 lines

  1. // CmIter.h
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Abstract container iterator definition.
  7. // -----------------------------------------------------------------
  8.  
  9. #ifndef _CMITER_H
  10. #define _CMITER_H
  11.  
  12. #include <cm/include/cmobject.h>
  13.  
  14. class CmIterator : public CmObject {                  // Iterator definition.
  15. public:
  16.   virtual Bool      done    () const = 0;             // Check if end of cont.
  17.   virtual CmObject* next    ()       = 0;             // Return and advance.
  18.   virtual CmObject* previous()       = 0;             // Return and backup.
  19.   virtual CmObject* current () const = 0;             // Return current object.
  20.   virtual void      first   ()       = 0;             // Set to first object.
  21.   virtual void      last    ()       = 0;             // Set to last object.
  22.  
  23.   CmObject* nextOccurrence    (CmObject*);            // Go to next equal.
  24.   CmObject* previousOccurrence(CmObject*);            // Go to prevous equal.
  25.  
  26.   operator int() const;                               // Check if not end.
  27.  
  28.   CmObject* operator++();                             // Advance and return.
  29.   CmObject* operator++(int);                          // Return and advance.
  30.   CmObject* operator+=(int);                          // Advance n places.
  31.   CmObject* operator--();                             // Backup and return.
  32.   CmObject* operator--(int);                          // Return and backup.
  33.   CmObject* operator-=(int);                          // Backup n places.
  34.   CmObject* operator()() const;                       // Return current object.
  35.  
  36.   CMOBJECT_ABSTRACT(CmIterator, CmObject)             // Define object funcs.
  37. };
  38.  
  39. // "int" conversion operator returns zero if at the end.
  40. inline CmIterator::operator int() const
  41. { return !done(); }
  42.  
  43. // "++" advances the iterator to the next object and returns it.
  44. inline CmObject* CmIterator::operator++()
  45. { next(); return current(); }
  46.  
  47. // "++" returns the current object and advances the iterator to the next.
  48. inline CmObject* CmIterator::operator++(int)
  49. { return next(); }
  50.  
  51. // "--" decrements the iterator by one and returns the object.
  52. inline CmObject* CmIterator::operator--()
  53. { previous(); return current(); }
  54.  
  55. // "--" returns the current object and decrements the iterator by one.
  56. inline CmObject* CmIterator::operator--(int)
  57. { return previous(); }
  58.  
  59. // "()" returns the current iterator object.
  60. inline CmObject* CmIterator::operator()() const
  61. { return current(); }
  62.  
  63. #endif
  64.