home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / Q1 < prev    next >
Encoding:
Text File  |  1992-06-07  |  5.3 KB  |  171 lines

  1. #ifndef __RWORDCLTN_H__
  2. #define __RWORDCLTN_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * RWOrdered --- Ordered Collection
  7.  *
  8.  * $Header:   E:/vcs/rw/ordcltn.h_v   1.7   17 Mar 1992 19:21:10   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave 
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1989, 1990, 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * The copy constructor and assignment operator use memberwise
  23.  * initialization and assignment, respectively.
  24.  *
  25.  * $Log:   E:/vcs/rw/ordcltn.h_v  $
  26.  * 
  27.  *    Rev 1.7   17 Mar 1992 19:21:10   KEFFER
  28.  * Changed BOUNDS_CHECK to RWBOUNDS_CHECK
  29.  * 
  30.  *    Rev 1.6   04 Mar 1992 09:03:52   KEFFER
  31.  * nil changed to rwnil
  32.  * 
  33.  *    Rev 1.5   18 Feb 1992 09:54:32   KEFFER
  34.  * 
  35.  *    Rev 1.4   05 Nov 1991 13:52:06   keffer
  36.  * Now declares GVector of RWCollectableP, instead of relying on collect.h
  37.  * 
  38.  *    Rev 1.3   28 Oct 1991 09:08:18   keffer
  39.  * Changed inclusions to <rw/xxx.h>
  40.  * 
  41.  *    Rev 1.2   20 Aug 1991 18:53:12   keffer
  42.  * pop() now returns nitems-1
  43.  * 
  44.  *    Rev 1.1   29 Jul 1991 14:13:56   keffer
  45.  * Added member function data().
  46.  * 
  47.  *    Rev 1.0   28 Jul 1991 08:15:54   keffer
  48.  * Tools.h++ V4.0.5 PVCS baseline version
  49.  *
  50.  */
  51.  
  52. #include "rw/seqcltn.h"
  53. #include "rw/iterator.h"
  54. #include "rw/gvector.h"
  55. declare(GVector,RWCollectableP)
  56.  
  57. class RWExport RWOrdered : public RWSequenceable {
  58.   friend class RWExport RWOrderedIterator;
  59. protected:
  60.   unsigned            nitems;
  61.   GVector(RWCollectableP)    vec;        // An array of pointers to objects.
  62. protected:
  63.   void                boundsCheck(int) const;
  64.   RWCollectable*        removeAt(unsigned);
  65. public:
  66.  
  67.   RWOrdered(unsigned size = RWCollection::DEFAULT_CAPACITY);
  68.  
  69.   /******************** Member operators ****************************/
  70.   RWBoolean            operator==(const RWOrdered&) const;
  71.  
  72.   /****************** Virtual member functions *******************/
  73.   virtual RWCollectable*    append(RWCollectable* a);
  74.   virtual void            apply(RWapplyCollectable, void*);
  75.   virtual RWCollectable*&    at(int);    // Can use as lvalue
  76. #ifdef CONST_OVERLOADS
  77.   virtual const RWCollectable*    at(int) const;    // Cannot use as lvalue.
  78. #endif
  79.   virtual void            clear();
  80. //virtual void            clearAndDestroy();
  81. //virtual RWBoolean        contains(const RWCollectable*) const;
  82.   virtual unsigned        entries() const {return nitems;}
  83.   virtual RWCollectable*    find(const RWCollectable*) const;    // First occurrence
  84.   virtual RWCollectable*    first() const;
  85.   virtual int            index(const RWCollectable*) const; // Returns -1 if not found.
  86.   virtual RWCollectable*    insert(RWCollectable*);         // Appends.
  87.   virtual RWCollectable*    insertAfter(int, RWCollectable*);     // Use -1 to insert at beginning
  88.   virtual ClassID        isA() const {return __RWORDERED;}
  89.   virtual RWBoolean        isEmpty() const {return nitems==0;}
  90.   virtual RWCollectable*    last() const;
  91.   virtual RWCollectable*    newSpecies() const;
  92.   virtual unsigned        occurrencesOf(const RWCollectable*) const;
  93.   virtual RWCollectable*    remove(const RWCollectable*);    // Remove first occurrence
  94. //virtual void            removeAndDestroy(const RWCollectable*);
  95.   virtual RWCollectable*    prepend(RWCollectable*);
  96.  
  97.   /*********************** Special functions ******************************/
  98.   RWCollectable*&        operator[](int);    // With bounds checking
  99.   RWCollectable*&        operator()(int);    // Optional bounds checking
  100. #ifdef CONST_OVERLOADS
  101.   RWCollectable*        operator[](int) const;    // With bounds checking
  102.   RWCollectable*        operator()(int) const;    // Optional bounds checking
  103. #endif
  104.   const RWCollectableP*        data() const;        // Use with care.
  105.   void                push(RWCollectable*);    // Alternative stack.
  106.   RWCollectable*        pop();
  107.   void                resize(unsigned);    // Cannot shrink below population
  108.   RWCollectable*        top() const;
  109. };
  110.  
  111. class RWExport RWOrderedIterator : public RWIterator {
  112.   const RWOrdered*    theCollection;
  113.   int            here;
  114. public:
  115.   RWOrderedIterator(const RWOrdered& ord) { theCollection=⩝ here=-1;}
  116.   virtual RWCollectable*    findNext(const RWCollectable*); // Find next matching item
  117.   virtual RWCollectable*    key() const;          // Return current key
  118.   virtual RWCollectable*    operator()();          // Advance iterator
  119.   virtual void            reset() {here=-1;}
  120. };
  121.  
  122. /************************ INLINES *******************************/
  123. inline RWCollectable*&
  124. RWOrdered::operator[](int i)
  125. { boundsCheck(i); return vec(i); }
  126.  
  127. inline RWCollectable*&
  128. RWOrdered::operator()(int i)
  129. {
  130. #ifdef RWBOUNDS_CHECK
  131.   boundsCheck(i);
  132. #endif
  133.   return vec(i);
  134. }
  135.  
  136. #ifdef CONST_OVERLOADS
  137. inline RWCollectable*
  138. RWOrdered::operator[](int i) const
  139. { boundsCheck(i); return vec(i); }
  140.  
  141. inline RWCollectable*
  142. RWOrdered::operator()(int i) const
  143. {
  144. #ifdef RWBOUNDS_CHECK
  145.   boundsCheck(i);
  146. #endif
  147.   return vec(i);
  148. }
  149. #endif    /* CONST_OVERLOADS */
  150.  
  151. inline const RWCollectableP*
  152. RWOrdered::data() const
  153. {
  154.   return vec.data();
  155. }
  156.  
  157. inline void
  158. RWOrdered::push(RWCollectable* c)
  159. { insert(c); }
  160.  
  161. inline RWCollectable*
  162. RWOrdered::pop()
  163. { return nitems>0 ? removeAt(nitems-1) : rwnil; }
  164.  
  165. inline RWCollectable*
  166. RWOrdered::top() const
  167. { return nitems>0 ? vec(nitems-1) : rwnil; }
  168.  
  169. pragma pop_align_members();
  170. #endif /* __RWORDCLTN_H__ */
  171.