home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSINC.ZIP / ABSTARRY.H next >
C/C++ Source or Header  |  1990-09-26  |  8KB  |  323 lines

  1. #ifndef __ABSTARRY_H
  2. #define __ABSTARRY_H
  3.  
  4. //
  5. // This file contains proprietary information of Borland International.
  6. // Copying or reproduction without prior written approval is prohibited.
  7. //
  8. // Copyright (c) 1990
  9. // Borland International
  10. // 1800 Scotts Valley Dr.
  11. // Scotts Valley, CA 95066
  12. // (408) 438-8400
  13. //
  14.  
  15. // Contents ----------------------------------------------------------------
  16. //
  17. //      AbstractArray
  18. //         AbstractArray::arraySize
  19. //
  20. //      ArrayIterator
  21. //      ArrayIterator::ArrayIterator
  22. //
  23. // Description
  24. //
  25. //      Defines the class AbstractArray.  An array object implies 
  26. //      indexability.  Defines the class ArrayIterator.
  27. //
  28. // End ---------------------------------------------------------------------
  29.  
  30. // Interface Dependencies ---------------------------------------------------
  31.  
  32. #ifndef __IOSTREAM_H
  33. #include <iostream.h>
  34. #define __IOSTREAM_H
  35. #endif
  36.  
  37. #ifndef __CLSTYPES_H
  38. #include <clstypes.h>
  39. #endif
  40.  
  41. #ifndef __OBJECT_H
  42. #include <object.h>
  43. #endif
  44.  
  45. #ifndef __COLLECT_H
  46. #include <collect.h>
  47. #endif
  48.  
  49. // End Interface Dependencies ------------------------------------------------
  50.  
  51.  
  52. class AbstractArray:  public Collection
  53. {
  54. public:                                                         
  55.             AbstractArray( int upper, int lower = 0, sizeType aDelta = 0 );
  56.     virtual ~AbstractArray();
  57.  
  58.             int             lowerBound() const { return lowerbound; }
  59.             int             upperBound() const { return upperbound; }
  60.             sizeType        arraySize() const;
  61.  
  62.     virtual ContainerIterator& initIterator() const;
  63.  
  64.     virtual void            add( Object& ) = 0;
  65.             void            destroy( int i ) { detach( i, 1 ); }
  66.             void            detach( int, int = 0 );
  67.  
  68.     virtual    void            detach( const Object&, int = 0 );
  69.  
  70.     virtual classType       isA() const = 0;
  71.     virtual char           *nameOf() const = 0;
  72.     virtual int             isEqual( const Object& ) const;
  73.     virtual hashValueType   hashValue() const;
  74.  
  75.     virtual    void            printContentsOn( ostream& ) const;
  76.  
  77. protected:
  78.             Object&         objectAt( int i ) const
  79.                                 { return *theArray[ i - lowerbound ]; }
  80.             void            reallocate( sizeType );
  81.             sizeType        delta;
  82.             int                lowerbound;
  83.             int                upperbound;
  84.             int                whereToAdd;
  85.             Object        **theArray;
  86.  
  87.     friend  class ArrayIterator;
  88. };
  89.  
  90. // Description -------------------------------------------------------------
  91. //
  92. //      Defines the class AbstractArray.  The AbstractArray class is 
  93. //      used as a base class for random-access and sorted arrays.
  94. //      The size of the array, i.e. the maximum number of elements 
  95. //      which may be put into the array, is calculated from the bounds 
  96. //      given at the construction of the array object.
  97. //
  98. // Constructor
  99. //
  100. //         AbstractArray
  101. //
  102. //         Constructor.  Parameter upper specifies the upper bound for the
  103. //         index of the array.    Parameter lower specifies a lower bound for
  104. //      the index of the array.  Paramter aDelta specifies the number of 
  105. //         array elements by which the array will grow if an element is added 
  106. //         to an array    which has no more space for elements.  Specify aDelta = 0 
  107. //         if the array should not be allowed to grow.
  108. //
  109. // Public Members
  110. //
  111. //         lowerBound
  112. //
  113. //         Returns the current lower bound of the array.  The lower bound is
  114. //         fixed when the array is constructed.
  115. //
  116. //         upperBound
  117. //
  118. //         Returns the upper bound of the array.  The upper bound is initially
  119. //         set when the array is constructed but may increase is more elements
  120. //         are added.    The amount by which the upper bound will increase is
  121. //         a parameter to the constructor for the array.
  122. //
  123. //         arraySize
  124. //
  125. //         Returns the size of the array, in elements, as determined by the
  126. //         lower bound and the current upper bound.
  127. //
  128. //         initIterator
  129. //
  130. //         Array iterator initializer.
  131. //
  132. //      add
  133. //
  134. //      Pure virtual function.
  135. //     
  136. //      destroy
  137. //
  138. //      Removes an object reference from the array at the given index and
  139. //      destroys the object.
  140. //
  141. //         detach
  142. //
  143. //         Removes all references to the object at the given index in the array.
  144. //      Does not delete the object.  Use this function when the array elements
  145. //         are not owned by the array.
  146. //
  147. //         detach
  148. //
  149. //      Removes a reference to the given object from the array.
  150. //
  151. //      hashValue
  152. //
  153. //         Returns a pre-defined value as the hash value of an array.
  154. //
  155. //         isEqual
  156. //
  157. //         Determines whether two arrays are equal.
  158. //
  159. //         printContentsOn
  160. //
  161. //         Displays the non-ZERO elements of the array.
  162. //
  163. // Inherited Members
  164. //
  165. //      hasMember
  166. //
  167. //      Inherited from Collection
  168. //
  169. //         isEmpty
  170. //
  171. //      Inherited from Collection.
  172. //
  173. //      forEach
  174. //
  175. //      Inherited from Container.
  176. //
  177. //      firstThat
  178. //
  179. //      Inherited from Container.
  180. //
  181. //      lastThat
  182. //
  183. //      Inherited from Container.
  184. //
  185. //         printOn
  186. //
  187. //         Inherited from Container.
  188. //
  189. //      destroy
  190. //
  191. //      Inherited from Collection.
  192. //
  193. // Protected Members
  194. //
  195. //         objectAt
  196. //
  197. //         Returns a reference to the object at the given index.
  198. //
  199. //         reallocate
  200. //
  201. //         Expands the pointer array to a new size.
  202. //
  203. //      delta
  204. //
  205. //      Defines the number of elements by which we are to expand the
  206. //      array, if needed.
  207. //
  208. //      lowerbound
  209. //
  210. //      Defines the smallest value for an index in this array.
  211. //
  212. //      upperbound
  213. //
  214. //      Defines the largest index in the array which, if referenced,
  215. //      will not cause an array expansion to take place.
  216. //
  217. //      theArray
  218. //
  219. //      Points to the area in which array element references are located.
  220. //
  221. // End ---------------------------------------------------------------------
  222.  
  223.  
  224. // Member Function //
  225.  
  226. inline sizeType AbstractArray::arraySize() const
  227.  
  228. // Summary -----------------------------------------------------------------
  229. //
  230. //      Returns the current size of the array.
  231. //
  232. // End ---------------------------------------------------------------------
  233. {
  234.     return sizeType( upperbound - lowerbound + 1 );
  235. }
  236. // End Member Function AbstractArray::arraySize //
  237.  
  238.  
  239. // Class //
  240.  
  241. class ArrayIterator:  public ContainerIterator
  242. {
  243. public:
  244.             ArrayIterator( const AbstractArray& );
  245.     virtual ~ArrayIterator();
  246.  
  247.     virtual                operator int();
  248.     virtual                operator Object&();
  249.     virtual    Object&        operator ++();
  250.     virtual    void        restart();
  251.  
  252. private:
  253.             int            currentIndex;
  254.     const   AbstractArray& beingIterated;
  255. };
  256.  
  257. // Description -------------------------------------------------------------
  258. //
  259. //         Defines the array iterator class.  Upon initialization, we set up
  260. //         an internal pointer to our current position in the array.  As
  261. //      the increment operator is called, we update this current position.
  262. //
  263. // Constructor
  264. //
  265. //      ArrayIterator( const AbstractArray& )
  266. //
  267. //         Constructor for an iterator.  Note that this isn't a copy
  268. //         constructor, since it takes an object from a different class.
  269. //
  270. // Destructor
  271. //
  272. //         ~ArrayIterator
  273. //
  274. // Public Members
  275. //
  276. //         operator int
  277. //
  278. //         We are allowed one cast operator to a predefined type.  This
  279. //         operator defines an explicit or an implicit cast from a
  280. //         ArrayIterator to an integer.
  281. //
  282. //      operator Object&
  283. //
  284. //      Conversion to Object operator.
  285. //
  286. //         operator ++
  287. //
  288. //      The increment operator.
  289. //
  290. //         restart
  291. //
  292. //         Restarts an array iterator.
  293. //
  294. // Private Members
  295. //
  296. //         currentIndex
  297. //
  298. //         Maintains the position information for this iterator.
  299. //
  300. //         beingIterated
  301. //
  302. //      Maintains a pointer to the array being iterated.
  303. //
  304. // End ---------------------------------------------------------------------
  305.  
  306.  
  307. // Constructor //
  308.  
  309. inline  ArrayIterator::ArrayIterator( const AbstractArray& toIterate ) :
  310.             beingIterated( toIterate ), currentIndex( toIterate.lowerbound )
  311.  
  312. // Summary -----------------------------------------------------------------
  313. //
  314. //      Constructor for a array iterator object.
  315. //
  316. // End ---------------------------------------------------------------------
  317. {
  318. }
  319. // End Constructor ArrayIterator::ArrayIterator //
  320.  
  321.  
  322. #endif // ifndef __ABSTARRY_H //
  323.