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

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