1 // Created on: 2011-01-27
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _NCollection_Comparator_HeaderFile
17 #define _NCollection_Comparator_HeaderFile
19 #include <Precision.hxx>
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.
28 template<class TheItemType>
29 class NCollection_Comparator
33 NCollection_Comparator (const Standard_Real theTolerance = Precision::Confusion())
34 : myTolerance (theTolerance) {}
36 virtual ~NCollection_Comparator() {}
39 //! Comparison functions which should be overridden
40 //! if standard operators are not defined for user type.
42 //! Should return true if Left value is greater than Right
43 virtual Standard_Boolean IsGreater (const TheItemType& theLeft, const TheItemType& theRight) const
45 return theLeft > theRight;
48 //! Should return true if values are equal
49 virtual Standard_Boolean IsEqual (const TheItemType& theLeft, const TheItemType& theRight) const
51 return theLeft == theRight;
55 //! Comparison functions which may be overridden for performance reasons
57 //! Should return true if Left value is lower than Right
58 virtual Standard_Boolean IsLower (const TheItemType& theLeft, const TheItemType& theRight) const
60 return !IsGreater (theLeft, theRight) && !IsEqual (theLeft, theRight);
63 virtual Standard_Boolean IsLowerEqual (const TheItemType& theLeft, const TheItemType& theRight) const
65 return !IsGreater (theLeft, theRight);
68 virtual Standard_Boolean IsGreaterEqual (const TheItemType& theLeft, const TheItemType& theRight) const
70 return IsGreater (theLeft, theRight) || IsEqual (theLeft, theRight);
75 Standard_Real myTolerance;
79 #endif /*_NCollection_Comparator_HeaderFile*/