0024624: Lost word in license statement in source files
[occt.git] / src / NCollection / NCollection_Comparator.hxx
1 // Created on: 2011-01-27
2 // Created by: KGV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _NCollection_Comparator_HeaderFile
17 #define _NCollection_Comparator_HeaderFile
18
19 #include <Precision.hxx>
20
21 /**
22  * Class to define basic compare operations.
23  * Basic implementation use redirection to standard C++ operators.
24  * You can use standard C++ templates mechanisms to redefine these methods
25  * or to inherit basic implementation to create multiple comparators
26  * for same type with different rules.
27  */
28 template<class TheItemType>
29 class NCollection_Comparator
30 {
31 public:
32
33   NCollection_Comparator (const Standard_Real theTolerance = Precision::Confusion())
34   : myTolerance (theTolerance) {}
35
36   virtual ~NCollection_Comparator() {}
37
38 public:
39   //! Comparison functions which should be overridden
40   //! if standard operators are not defined for user type.
41
42   //! Should return true if Left value is greater than Right
43   virtual Standard_Boolean IsGreater (const TheItemType& theLeft, const TheItemType& theRight) const
44   {
45     return theLeft > theRight;
46   }
47
48   //! Should return true if values are equal
49   virtual Standard_Boolean IsEqual (const TheItemType& theLeft, const TheItemType& theRight) const
50   {
51     return theLeft == theRight;
52   }
53
54 public:
55   //! Comparison functions which may be overridden for performance reasons
56
57   //! Should return true if Left value is lower than Right
58   virtual Standard_Boolean IsLower (const TheItemType& theLeft, const TheItemType& theRight) const
59   {
60     return !IsGreater (theLeft, theRight) && !IsEqual (theLeft, theRight);
61   }
62
63   virtual Standard_Boolean IsLowerEqual (const TheItemType& theLeft, const TheItemType& theRight) const
64   {
65     return !IsGreater (theLeft, theRight);
66   }
67
68   virtual Standard_Boolean IsGreaterEqual (const TheItemType& theLeft, const TheItemType& theRight) const
69   {
70     return IsGreater (theLeft, theRight) || IsEqual (theLeft, theRight);
71   }
72
73 protected:
74
75   Standard_Real myTolerance;
76
77 };
78
79 #endif /*_NCollection_Comparator_HeaderFile*/