home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / test / eh / SortClass.h < prev    next >
C/C++ Source or Header  |  2000-12-07  |  2KB  |  77 lines

  1. /***********************************************************************************
  2.     SortClass.h
  3.     
  4.  * Copyright (c) 1997
  5.  * Mark of the Unicorn, Inc.
  6.  *
  7.  * Permission to use, copy, modify, distribute and sell this software
  8.  * and its documentation for any purpose is hereby granted without fee,
  9.  * provided that the above copyright notice appear in all copies and
  10.  * that both that copyright notice and this permission notice appear
  11.  * in supporting documentation.  Mark of the Unicorn makes no
  12.  * representations about the suitability of this software for any
  13.  * purpose.  It is provided "as is" without express or implied warranty.
  14.         
  15.         SUMMARY: A class designed to test operations that compares objects. All
  16.             comparisons on SortClass may fail. Also records its own address for
  17.             the sake of testing the stability of sorting algorithms.
  18.         
  19. ***********************************************************************************/
  20. #if ! defined (INCLUDED_MOTU_SortClass)
  21. #define INCLUDED_MOTU_SortClass 1
  22.  
  23. # include "Prefix.h"
  24. # include "TestClass.h"
  25.  
  26. class SortClass : public TestClass
  27. {
  28. public:
  29.     enum { kRange = 100 };
  30.  
  31.     SortClass( int v ) : TestClass( v ), addr(this) {}
  32.     SortClass() : TestClass( (int)get_random(kRange) ), addr(this) {}
  33.     
  34.     bool operator<( const TestClass& rhs ) const
  35.     {
  36.         simulate_possible_failure();
  37.         return (const TestClass&)*this < ( rhs );
  38.     }
  39.     
  40.     bool operator==( const TestClass& rhs ) const
  41.     {
  42.         simulate_possible_failure();
  43.         return (const TestClass&)*this == ( rhs );
  44.     }
  45.     
  46.     SortClass* GetAddress() const { return addr; }
  47.     void ResetAddress() { addr = this; }
  48.     
  49. private:
  50.     SortClass* addr;
  51. };
  52.  
  53. inline bool operator>( const SortClass& lhs, const SortClass& rhs ) {
  54.     return rhs < lhs;
  55. }
  56.  
  57. inline bool operator<=( const SortClass& lhs, const SortClass& rhs ) {
  58.     return !(rhs < lhs);
  59. }
  60.  
  61. inline bool operator>=( const SortClass& lhs, const SortClass& rhs ) {
  62.     return !(lhs < rhs);
  63. }
  64.  
  65. inline bool operator != ( const SortClass& lhs, const SortClass& rhs ) {
  66.     return !(lhs == rhs);
  67. }
  68.  
  69. #if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
  70. # if defined( __MSL__ ) && __MSL__ < 0x2406
  71. __MSL_FIX_ITERATORS__(SortClass);
  72. __MSL_FIX_ITERATORS__(const SortClass);
  73. # endif
  74. #endif
  75.  
  76. #endif // INCLUDED_MOTU_SortClass
  77.