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

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