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 / SORTARRY.H < prev    next >
C/C++ Source or Header  |  1990-09-26  |  5KB  |  204 lines

  1. #ifndef __SORTARRY_H
  2. #define __SORTARRY_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. //      SortedArray
  18. //      SortedArray::SortedArray                    constructor
  19. //         SortedArray::operator []
  20. //
  21. // Description
  22. //
  23. //      Defines the class SortedArray.
  24. //
  25. // End ---------------------------------------------------------------------
  26.  
  27. // Interface Dependencies ---------------------------------------------------
  28.  
  29. #ifndef __IOSTREAM_H
  30. #include <iostream.h>
  31. #define __IOSTREAM_H
  32. #endif
  33.  
  34. #ifndef __CLSTYPES_H
  35. #include <clstypes.h>
  36. #endif
  37.  
  38. #ifndef __OBJECT_H
  39. #include <object.h>
  40. #endif
  41.  
  42. #ifndef __SORTABLE_H
  43. #include <sortable.h>
  44. #endif
  45.  
  46. #ifndef __ABSTARRY_H
  47. #include <abstarry.h>
  48. #endif
  49.  
  50. // End Interface Dependencies ------------------------------------------------
  51.  
  52.  
  53. // Class //
  54.  
  55. class SortedArray:  public AbstractArray
  56. {
  57. public:
  58.             SortedArray( int upper, int lower = 0, sizeType aDelta = 0 );
  59.     virtual ~SortedArray();
  60.  
  61.             const Sortable& operator []( int ) const;
  62.  
  63.     virtual void            add( Object& );
  64.     virtual    void            detach( const Object&, int = 0 );
  65.     virtual classType       isA() const;
  66.     virtual char           *nameOf() const;
  67.  
  68. private:
  69.             int             lastElementIndex;
  70. };
  71.  
  72. // Description -------------------------------------------------------------
  73. //
  74. //      Defines the class SortedArray.  The SortedArray class is an
  75. //     array in which any elements which are added are added in sorted
  76. //     order.  
  77. //
  78. // Constructor
  79. //
  80. //     SortedArray
  81. //
  82. //     Constructor.  Uses the AbstractArray class constructor.
  83. //
  84. // Public Members
  85. //
  86. //         operator []
  87. //      
  88. //         Subscript operator.  The subscript operator for sorted array
  89. //      returns a constant object.  Allowing assignments to an object 
  90. //      at a particular index might violate the sorting of the array.
  91. //
  92. //      add
  93. //
  94. //      Appends an object to the array, keeping the array elements sorted
  95. //      and expanding the array if necessary.
  96. //     
  97. //         detach
  98. //
  99. //         Removes a reference to the object from the array.
  100. //
  101. //         isA
  102. //
  103. //         Returns the class type of a sorted array.
  104. //
  105. //         nameOf
  106. //
  107. //         Returns a character pointer to the string "SortedArray."
  108. //
  109. // Inherited Members
  110. //
  111. //     lowerBound
  112. //
  113. //     Inherited from class AbstractArray.
  114. //
  115. //     upperBound
  116. //
  117. //     Inherited from class AbstractArray.
  118. //
  119. //     arraySize
  120. //
  121. //     Inherited from class AbstractArray.
  122. //
  123. //      destroy
  124. //
  125. //      Removes an object reference from the array.
  126. //
  127. //      hashValue
  128. //
  129. //     Inherited from AbstractArray.
  130. //
  131. //     isEqual
  132. //
  133. //     Inherited from AbstractArray.
  134. //
  135. //         printOn
  136. //
  137. //         Inherited from Container.
  138. //
  139. // Protected Members
  140. //
  141. //      delta
  142. //
  143. //     Inherited from Array and made protected.
  144. //
  145. //      lowerbound
  146. //
  147. //     Inherited from Array and made protected.
  148. //
  149. //      upperbound
  150. //
  151. //     Inherited from Array and made protected.
  152. //
  153. //      array
  154. //
  155. //     Inherited from Array and made protected.
  156. //
  157. // Private Members
  158. //
  159. //      lastElementIndex
  160. //
  161. //      The index of the last element in the sorted array.
  162. //
  163. // End ---------------------------------------------------------------------
  164.  
  165.  
  166. // Constructor //
  167.  
  168. inline  SortedArray::SortedArray( int upper, int lower, sizeType aDelta ) :
  169.                                         AbstractArray( upper, lower, aDelta )
  170.  
  171. // Summary -----------------------------------------------------------------
  172. //
  173. //      Constructor for a sorted array object.
  174. //
  175. // End ---------------------------------------------------------------------
  176. {
  177.     lastElementIndex = lowerbound - 1;
  178. }
  179. // End Constructor SortedArray::SortedArray //
  180.  
  181.  
  182. // Member Function //
  183.  
  184. inline const Sortable& SortedArray::operator []( int atIndex ) const
  185.  
  186. // Summary -----------------------------------------------------------------
  187. //
  188. //      Subscript operator for sorted arrays.
  189. //
  190. // Return Value
  191. //
  192. //     sortableAt
  193. //
  194. //     Reference to the sortable object at the given index.
  195. //
  196. // End ---------------------------------------------------------------------
  197. {
  198.     return (Sortable&)objectAt( atIndex );
  199. }
  200. // End Member Function SortedArray::operator [] //
  201.  
  202.  
  203. #endif // ifndef __SORTARRY_H //
  204.