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 SortClass(int v)31 SortClass( int v ) : TestClass( v ), addr(0) { 32 ResetAddress(); 33 } 34 SortClass()35 SortClass() : TestClass( (int)get_random(kRange) ), addr(0) { 36 ResetAddress(); 37 } 38 39 bool operator<( const TestClass& rhs ) const 40 { 41 simulate_possible_failure(); 42 return (const TestClass&)*this < ( rhs ); 43 } 44 45 bool operator==( const TestClass& rhs ) const 46 { 47 simulate_possible_failure(); 48 return (const TestClass&)*this == ( rhs ); 49 } 50 GetAddress()51 SortClass* GetAddress() const { return addr; } ResetAddress()52 void ResetAddress() { addr = this; } 53 54 private: 55 SortClass* addr; 56 }; 57 58 inline bool operator>( const SortClass& lhs, const SortClass& rhs ) { 59 return rhs < lhs; 60 } 61 62 inline bool operator<=( const SortClass& lhs, const SortClass& rhs ) { 63 return !(rhs < lhs); 64 } 65 66 inline bool operator>=( const SortClass& lhs, const SortClass& rhs ) { 67 return !(lhs < rhs); 68 } 69 70 inline bool operator != ( const SortClass& lhs, const SortClass& rhs ) { 71 return !(lhs == rhs); 72 } 73 74 #if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL 75 # if defined( __MSL__ ) && __MSL__ < 0x2406 76 __MSL_FIX_ITERATORS__(SortClass); 77 __MSL_FIX_ITERATORS__(const SortClass); 78 # endif 79 #endif 80 81 #endif // INCLUDED_MOTU_SortClass 82