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 / SORTABLE.H < prev    next >
C/C++ Source or Header  |  1990-09-26  |  6KB  |  253 lines

  1. #ifndef _SORTABLE_H
  2. #define _SORTABLE_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. //      Sortable      
  18. //      operator >
  19. //      operator >=
  20. //      operator <=
  21. //
  22. // Description
  23. //
  24. //      Defines the abstract class Sortable and inline member functions.
  25. //
  26. // End ---------------------------------------------------------------------
  27.  
  28. // Interface Dependencies ---------------------------------------------------
  29.  
  30. #ifndef __IOSTREAM_H
  31. #include <iostream.h>
  32. #define __IOSTREAM_H
  33. #endif
  34.  
  35. #ifndef __CLSTYPES_H
  36. #include "clstypes.h"
  37. #endif
  38.  
  39. #ifndef __OBJECT_H
  40. #include "object.h"
  41. #endif
  42.  
  43. // End Interface Dependencies ------------------------------------------------
  44.  
  45. // Class //
  46.  
  47. class Sortable:  public Object
  48. {
  49. public:
  50.     virtual ~Sortable();
  51.  
  52.     virtual int             isEqual( const Object& ) const = 0;
  53.     virtual int             isLessThan( const Object& ) const = 0;
  54.     virtual int             isSortable() const;
  55.  
  56.     virtual classType       isA() const = 0;
  57.     virtual char            *nameOf() const = 0;
  58.     virtual hashValueType   hashValue() const = 0;
  59.  
  60. protected:
  61.     virtual void            printOn( ostream& ) const = 0;
  62. };
  63.  
  64. // Description -------------------------------------------------------------
  65. //
  66. //     Defines the abstract class Sortable.  Sortable implies that ordering
  67. //     operations can be performed up pairs of Sortable objects.  The
  68. //     relational operations depend upon the implementation of the 
  69. //     classes derived from the class Sortable.
  70. //
  71. //     Sortable objects, i.e. objects instantiated of classes derived from
  72. //     Sortable, are used in ordered collections.
  73. //
  74. // Public Members
  75. //
  76. //     isEqual
  77. //
  78. //     Returns 1 if two objects are equivalent, 0 otherwise.
  79. //     Determines equivalence by comparing the contents of the two objects.
  80. //      Perpetuates the pure virtual function inherited from Object.
  81. //
  82. //     operator <
  83. //
  84. //     Returns 1 if this is less than a test object.
  85. //
  86. //     operator >
  87. //
  88. //     Returns 1 if this is greater than a test object.
  89. //
  90. //     operator <=
  91. //
  92. //     Returns 1 if this is less than or equal to a test object.
  93. //
  94. //     operator >=
  95. //
  96. //     Returns 1 if this is greater than or equal to a test object.
  97. //
  98. //     isA()
  99. //
  100. //     Inherited from Object and redeclared as a pure virtual function.
  101. //
  102. //     nameOf
  103. //
  104. //     Inherited from Object and redeclared as a pure virtual function.
  105. //     
  106. //     hashValue
  107. //
  108. //     Inherited from Object and redeclared as a pure virtual function.
  109. //
  110. // Inherited Members
  111. //
  112. //      operator new
  113. //
  114. //      Inherited from Object.
  115. //
  116. //     operator !=
  117. //
  118. //      Inherited from Object.
  119. //
  120. //      forEach
  121. //
  122. //      Inherited from Object.
  123. //
  124. //      firstThat
  125. //
  126. //      Inherited from Object.
  127. //
  128. //      lastThat
  129. //
  130. //      Inherited from Object.
  131. //
  132. // Protected Members
  133. //
  134. //     printOn
  135. //
  136. //     Inherited from Object a redeclared as a pure virtual function.
  137. //
  138. // End ---------------------------------------------------------------------
  139.  
  140.  
  141.             int             operator < ( const Sortable&, const Sortable& );
  142.             int             operator > ( const Sortable&, const Sortable& );
  143.             int             operator <=( const Sortable&, const Sortable& );
  144.             int             operator >=( const Sortable&, const Sortable& );
  145.  
  146. // Function //
  147.  
  148. inline  int operator < ( const Sortable& test1, const Sortable& test2 )
  149.  
  150. // Summary -----------------------------------------------------------------
  151. //
  152. //      Determines whether the first object is less than the second.  We
  153. //      do type checking on the two objects (objects of different
  154. //      classes can't be compared, even if they're derived from each other).
  155. //
  156. // Parameters
  157. //
  158. //      test1
  159. //
  160. //      The first object we are testing.
  161. //
  162. //      test2
  163. //
  164. //      The second object we are testing.
  165. //
  166. // End ---------------------------------------------------------------------
  167. {
  168.     return ( (test1.isA() == test2.isA()) && test1.isLessThan( test2 ) );
  169. }
  170. // EndFunction operator < //
  171.  
  172.  
  173. // Function //
  174.  
  175. inline  int operator > ( const Sortable& test1, const Sortable& test2 )
  176.  
  177. // Summary -----------------------------------------------------------------
  178. //
  179. //      Determines whether the first object is greater than the second.  We
  180. //      just reverse the condition returned from operator < and test for
  181. //      inequality.
  182. //
  183. // Parameters
  184. //
  185. //      test1
  186. //
  187. //      The first object we are testing.
  188. //
  189. //      test2
  190. //
  191. //      The second object we are testing.
  192. //
  193. // End ---------------------------------------------------------------------
  194. {
  195.     return !( test1 < test2 ) && test1 != test2;
  196. }
  197. // EndFunction operator > //
  198.  
  199.  
  200. // Function //
  201.  
  202. inline  int operator >=( const Sortable& test1, const Sortable& test2 )
  203.  
  204. // Summary -----------------------------------------------------------------
  205. //
  206. //      Determines whether the first object is greater than or equal to
  207. //      the second.  We just reverse the condition returned from operator <.
  208. //
  209. // Parameters
  210. //
  211. //      test1
  212. //
  213. //      The first object we are testing.
  214. //
  215. //      test2
  216. //
  217. //      The second object we are testing.
  218. //
  219. // End ---------------------------------------------------------------------
  220. {
  221.     return ( !( test1 <( test2 ) ) );
  222. }
  223. // EndFunction operator >= //
  224.  
  225.  
  226. // Function //
  227.  
  228. inline  int operator <=( const Sortable& test1, const Sortable& test2 )
  229.  
  230. // Summary -----------------------------------------------------------------
  231. //
  232. //      Determines whether test1 is less than or equal to test2.
  233. //      We just combine the less than and equal to operators.
  234. //
  235. // Parameters
  236. //
  237. //      test1
  238. //
  239. //      The first object we are testing.
  240. //
  241. //      test2
  242. //
  243. //      The second object we are testing.
  244. //
  245. // End ---------------------------------------------------------------------
  246. {
  247.     return ( test1 < test2 || test1 == test2 );
  248. }
  249. // EndFunction Sortable::operator <= //
  250.  
  251.  
  252. #endif // ifndef _SORTABLE_H //
  253.