1 // File NCollection_Comparator.hxx
2 // Created 27 January 2011
4 // Copyright OpenCASCADE 2011
6 #ifndef _NCollection_Comparator_HeaderFile
7 #define _NCollection_Comparator_HeaderFile
9 #include <Precision.hxx>
12 * Class to define basic compare operations.
13 * Basic implementation use redirection to standard C++ operators.
14 * You can use standard C++ templates mechanisms to redefine these methods
15 * or to inherit basic implementation to create multiple comparators
16 * for same type with different rules.
18 template<class TheItemType>
19 class NCollection_Comparator
23 NCollection_Comparator (const Standard_Real theTolerance = Precision::Confusion())
24 : myTolerance (theTolerance) {}
26 virtual ~NCollection_Comparator() {}
29 //! Comparison functions which should be overridden
30 //! if standard operators are not defined for user type.
32 //! Should return true if Left value is greater than Right
33 virtual Standard_Boolean IsGreater (const TheItemType& theLeft, const TheItemType& theRight) const
35 return theLeft > theRight;
38 //! Should return true if values are equal
39 virtual Standard_Boolean IsEqual (const TheItemType& theLeft, const TheItemType& theRight) const
41 return theLeft == theRight;
45 //! Comparison functions which may be overridden for performance reasons
47 //! Should return true if Left value is lower than Right
48 virtual Standard_Boolean IsLower (const TheItemType& theLeft, const TheItemType& theRight) const
50 return !IsGreater (theLeft, theRight) && !IsEqual (theLeft, theRight);
53 virtual Standard_Boolean IsLowerEqual (const TheItemType& theLeft, const TheItemType& theRight) const
55 return !IsGreater (theLeft, theRight);
58 virtual Standard_Boolean IsGreaterEqual (const TheItemType& theLeft, const TheItemType& theRight) const
60 return IsGreater (theLeft, theRight) || IsEqual (theLeft, theRight);
65 Standard_Real myTolerance;
69 #endif /*_NCollection_Comparator_HeaderFile*/