OCC22278 No any sorting algorithm implemented for NCollection templates Developen...
[occt.git] / src / NCollection / NCollection_Comparator.hxx
1 // File       NCollection_Comparator.hxx
2 // Created    27 January 2011
3 // Author     KGV
4 // Copyright  OpenCASCADE 2011
5
6 #ifndef _NCollection_Comparator_HeaderFile
7 #define _NCollection_Comparator_HeaderFile
8
9 #include <Precision.hxx>
10
11 /**
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.
17  */
18 template<class TheItemType>
19 class NCollection_Comparator
20 {
21 public:
22
23   NCollection_Comparator (const Standard_Real theTolerance = Precision::Confusion())
24   : myTolerance (theTolerance) {}
25
26   virtual ~NCollection_Comparator() {}
27
28 public:
29   //! Comparison functions which should be overridden
30   //! if standard operators are not defined for user type.
31
32   //! Should return true if Left value is greater than Right
33   virtual Standard_Boolean IsGreater (const TheItemType& theLeft, const TheItemType& theRight) const
34   {
35     return theLeft > theRight;
36   }
37
38   //! Should return true if values are equal
39   virtual Standard_Boolean IsEqual (const TheItemType& theLeft, const TheItemType& theRight) const
40   {
41     return theLeft == theRight;
42   }
43
44 public:
45   //! Comparison functions which may be overridden for performance reasons
46
47   //! Should return true if Left value is lower than Right
48   virtual Standard_Boolean IsLower (const TheItemType& theLeft, const TheItemType& theRight) const
49   {
50     return !IsGreater (theLeft, theRight) && !IsEqual (theLeft, theRight);
51   }
52
53   virtual Standard_Boolean IsLowerEqual (const TheItemType& theLeft, const TheItemType& theRight) const
54   {
55     return !IsGreater (theLeft, theRight);
56   }
57
58   virtual Standard_Boolean IsGreaterEqual (const TheItemType& theLeft, const TheItemType& theRight) const
59   {
60     return IsGreater (theLeft, theRight) || IsEqual (theLeft, theRight);
61   }
62
63 protected:
64
65   Standard_Real myTolerance;
66
67 };
68
69 #endif /*_NCollection_Comparator_HeaderFile*/