home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / SCLTEST.EXE / SEARRITR.H < prev    next >
C/C++ Source or Header  |  1994-12-13  |  1KB  |  43 lines

  1. /*
  2.  * SEarritr.h
  3.  *
  4.  * Ian Soboroff, NIST
  5.  * June, 1994
  6.  *
  7.  * This is an iterator class for arrays of STEPentities.  Given a
  8.  * STEPentity** and its size, you can create one of these, with which
  9.  * you can neatly iterate through the array.  Since it's an array of
  10.  * _pointers_ to STEPentities, they can point to anything derived from
  11.  * that class, i.e., whatever entities you've drawn up in the schema.
  12.  *
  13.  */
  14.  
  15. // SEarrIterator -- an iterator class to walk arrays of pointers to STEP
  16. // entities (class STEPEntity).
  17. // Best used in the form:  for (SEitr=0; !SEitr; ++SEitr) { ... }
  18. // (this for loop walks the whole array)
  19.  
  20. class SEarrIterator 
  21. {
  22.  private:
  23.     const STEPentity** SEarr;  // Array of pointers to STEPentity's
  24.     int index;           // current index
  25.     int size;            // size of array
  26.  public:
  27.     // Construct the iterator with a given array and its size
  28.     SEarrIterator(const STEPentity** entarr, int sz)
  29.         { SEarr = entarr; index = 0; size = sz; }
  30.     
  31.     // set the value of the index: SEitr = 3
  32.     void operator= (int newindex) { index = newindex; }
  33.     
  34.     // check if we're out of range: if (!SEitr)...
  35.     int operator! () { return (index < size); }
  36.  
  37.     // return current element: SEptr = SEitr()
  38.     STEPentity* operator() () { return (STEPentity*)SEarr[index]; }
  39.  
  40.     // PREFIX increment operator: ++SEitr
  41.     int operator++ () { index++; return operator! (); }
  42. };
  43.