SortClass.h

00001 /***********************************************************************************
00002         SortClass.h
00003         
00004  * Copyright (c) 1997
00005  * Mark of the Unicorn, Inc.
00006  *
00007  * Permission to use, copy, modify, distribute and sell this software
00008  * and its documentation for any purpose is hereby granted without fee,
00009  * provided that the above copyright notice appear in all copies and
00010  * that both that copyright notice and this permission notice appear
00011  * in supporting documentation.  Mark of the Unicorn makes no
00012  * representations about the suitability of this software for any
00013  * purpose.  It is provided "as is" without express or implied warranty.
00014                 
00015                 SUMMARY: A class designed to test operations that compares objects. All
00016                         comparisons on SortClass may fail. Also records its own address for
00017                         the sake of testing the stability of sorting algorithms.
00018                 
00019 ***********************************************************************************/
00020 #if ! defined (INCLUDED_MOTU_SortClass)
00021 #define INCLUDED_MOTU_SortClass 1
00022 
00023 # include "Prefix.h"
00024 # include "TestClass.h"
00025 
00026 class SortClass : public TestClass
00027 {
00028 public:
00029         enum { kRange = 100 };
00030 
00031         SortClass( int v ) : TestClass( v ), addr(this) {}
00032         SortClass() : TestClass( (int)get_random(kRange) ), addr(this) {}
00033         
00034         bool operator<( const TestClass& rhs ) const
00035         {
00036                 simulate_possible_failure();
00037                 return (const TestClass&)*this < ( rhs );
00038         }
00039         
00040         bool operator==( const TestClass& rhs ) const
00041         {
00042                 simulate_possible_failure();
00043                 return (const TestClass&)*this == ( rhs );
00044         }
00045         
00046         SortClass* GetAddress() const { return addr; }
00047         void ResetAddress() { addr = this; }
00048         
00049 private:
00050         SortClass* addr;
00051 };
00052 
00053 inline bool operator>( const SortClass& lhs, const SortClass& rhs ) {
00054     return rhs < lhs;
00055 }
00056 
00057 inline bool operator<=( const SortClass& lhs, const SortClass& rhs ) {
00058     return !(rhs < lhs);
00059 }
00060 
00061 inline bool operator>=( const SortClass& lhs, const SortClass& rhs ) {
00062     return !(lhs < rhs);
00063 }
00064 
00065 inline bool operator != ( const SortClass& lhs, const SortClass& rhs ) {
00066     return !(lhs == rhs);
00067 }
00068 
00069 #if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
00070 # if defined( __MSL__ ) && __MSL__ < 0x2406
00071 __MSL_FIX_ITERATORS__(SortClass);
00072 __MSL_FIX_ITERATORS__(const SortClass);
00073 # endif
00074 #endif
00075 
00076 #endif // INCLUDED_MOTU_SortClass

Generated on Mon Jun 5 10:20:48 2006 for Intelligence.kdevelop by  doxygen 1.4.6