home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 1.ddi / CLASSINC.ZIP / ARRAY.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  5.7 KB  |  226 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      Array
  6. //         Array::operator []
  7. //
  8. // Description
  9. //
  10. //      Defines the class Array.  An array object implies indexability.
  11. //
  12. // End ---------------------------------------------------------------------
  13.  
  14. // Interface Dependencies ---------------------------------------------------
  15.  
  16.  
  17. #ifndef __ARRAY_H
  18. #define __ARRAY_H
  19.  
  20. #ifndef __IOSTREAM_H
  21. #include <iostream.h>
  22. #define __IOSTREAM_H
  23. #endif
  24.  
  25. #ifndef __CLSTYPES_H
  26. #include <clstypes.h>
  27. #endif
  28.  
  29. #ifndef __OBJECT_H
  30. #include <object.h>
  31. #endif
  32.  
  33. #ifndef __ABSTARRY_H
  34. #include <abstarry.h>
  35. #endif
  36.  
  37. // End Interface Dependencies ------------------------------------------------
  38.  
  39.  
  40. // Class //
  41.  
  42. class Array:  public AbstractArray
  43. {
  44. public:                                                         
  45.             Array( int upper, int lower = 0, sizeType aDelta = 0 ) :
  46.                                 AbstractArray( upper, lower, aDelta ) {}
  47.     virtual ~Array();
  48.  
  49.             Object&         operator []( int ) const;
  50.  
  51.     virtual void            add( Object& );
  52.             void            addAt( Object&, int );
  53.     virtual classType       isA() const;
  54.     virtual char           *nameOf() const;
  55. };
  56.  
  57. // Description -------------------------------------------------------------
  58. //
  59. //      Defines the class Array.  The Array class is made up of Objects
  60. //         which can be indexed with the given operator.  The size of the
  61. //         array, i.e. the maximum number of elements which may be put
  62. //         into the array, is calculated from the bounds given at the
  63. //         construction of the array object.
  64. //
  65. // Constructor
  66. //
  67. //         Array
  68. //
  69. //         Constructor.  Parameter upper specifies the upper bound for the
  70. //         index of the array.    Parameter lower specifies a lower bound for
  71. //         the index of the array.  Paramter aDelta specifies the number of 
  72. //         array elements by which the array will grow if an element is added 
  73. //         to an array    which has no more space for elements.  Specify aDelta = 0 
  74. //         if the array should not be allowed to grow.
  75. //
  76. // Public Members
  77. //
  78. //         operator []
  79. //
  80. //         Subscript operator.  Returns a reference to the element at the 
  81. //         given index.  The subscript operator will report an index out of
  82. //         bounds if the index is not in the current range.
  83. //
  84. //         lowerBound
  85. //
  86. //         Returns the current lower bound of the array.  The lower bound is
  87. //         fixed when the array is constructed.
  88. //
  89. //         upperBound
  90. //
  91. //         Returns the upper bound of the array.  The upper bound is initially
  92. //         set when the array is constructed but may increase is more elements
  93. //         are added.    The amount by which the upper bound will increase is
  94. //         a parameter to the constructor for the array.
  95. //
  96. //         arraySize
  97. //
  98. //         Returns the size of the array, in elements, as determined by the
  99. //         lower bound and the current upper bound.
  100. //
  101. //         addAt
  102. //
  103. //      Places an object in the array of the specified idnex, growing the
  104. //      array as needed if the index exceeds the upper bound.
  105. //
  106. //      destroy
  107. //
  108. //      Removes an object reference from the array at the given index and
  109. //      destroys the object.
  110. //
  111. //         detach
  112. //
  113. //         Removes all references to the object at the given index in the array.
  114. //      Does not delete the object.  Use this function when the array elements
  115. //         are not owned by the array.
  116. //
  117. //      add
  118. //
  119. //      Appends an object to the array, expanding the array if necessary.
  120. //      Overrides add member function inherited from Collection.
  121. //     
  122. //      destroy
  123. //
  124. //      Destroys the given object.
  125. //
  126. //         detach
  127. //
  128. //      Removes a reference to the given object from the array.
  129. //
  130. //      hashValue
  131. //
  132. //         Returns a pre-defined value as the hash value of an array.
  133. //
  134. //         isA
  135. //
  136. //         Returns the class type of an array.
  137. //
  138. //         nameOf
  139. //
  140. //         Returns a pointer to the character string "Array."
  141. //     
  142. //         isEqual
  143. //
  144. //         Determines whether two arrays are equal.
  145. //
  146. // Inherited Members
  147. //
  148. //      hasMember
  149. //
  150. //      Inherited from Collection
  151. //
  152. //         isEmpty
  153. //
  154. //      Inherited from Collection.
  155. //
  156. //      forEach
  157. //
  158. //      Inherited from Container.
  159. //
  160. //      firstThat
  161. //
  162. //      Inherited from Container.
  163. //
  164. //      lastThat
  165. //
  166. //      Inherited from Container.
  167. //
  168. //         printOn
  169. //
  170. //         Inherited from Container.
  171. //
  172. //         printHeader
  173. //
  174. //         Inherited from Object.
  175. //
  176. //         printTrailer
  177. //
  178. //         Inherited from Object.
  179. //
  180. //         printSeparator
  181. //
  182. //         Inherited from Object.
  183. //
  184. // Protected Members
  185. //
  186. //      delta
  187. //
  188. //      Defines the number of elements by which we are to expand the
  189. //      array, if needed.
  190. //
  191. //      lowerbound
  192. //
  193. //      Defines the smallest value for an index in this array.
  194. //
  195. //      upperbound
  196. //
  197. //      Defines the largest index in the array which, if referenced,
  198. //      will not cause an array expansion to take place.
  199. //
  200. //      theArray
  201. //
  202. //      Points to the area in which array element references are located.
  203. //
  204. // End ---------------------------------------------------------------------
  205.  
  206.  
  207. // Member Function //
  208.  
  209. inline Object& Array::operator []( int atIndex ) const
  210.  
  211. // Summary -----------------------------------------------------------------
  212. //
  213. //      Subscript operator for arrays.
  214. //
  215. // Return Value
  216. //
  217. //         objectAt
  218. //
  219. //         Reference to the object at the given index.
  220. //
  221. // End ---------------------------------------------------------------------
  222. {
  223.     return objectAt( atIndex );
  224. }
  225. #endif // ifndef __ARRAY_H //
  226.