HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Compare.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Compare.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_COMPARE_H_INCLUDED__
12 #define __UT_COMPARE_H_INCLUDED__
13 
14 #include "UT_API.h"
15 
16 namespace UT_Compare
17 {
18 
19 template <typename T>
20 using Ternary = int (*)(const T*, const T*);
21 
22 template <typename T>
23 class Less
24 {
25 public:
26  Less(Ternary<T> compare) : myCompare(compare)
27  { }
28  bool operator()(const T& lhs, const T& rhs)
29  { return myCompare(&lhs, &rhs) < 0; }
30 private:
31  Ternary<T> myCompare;
32 };
33 
34 template <typename T>
35 class Greater
36 {
37 public:
38  Greater(Ternary<T> compare) : myCompare(compare)
39  { }
40  bool operator()(const T& lhs, const T& rhs)
41  { return myCompare(&lhs, &rhs) > 0; }
42 private:
43  Ternary<T> myCompare;
44 };
45 
46 template <typename T>
47 class Equal
48 {
49 public:
50  Equal(Ternary<T> compare) : myCompare(compare)
51  { }
52  bool operator()(const T& lhs, const T& rhs)
53  { return myCompare(&lhs, &rhs) == 0; }
54 private:
55  Ternary<T> myCompare;
56 };
57 
58 } // namespace UT_Compare
59 
60 /// Adaptor to convert C-style ternary comparators to C++-style bool functors
61 /// @{
62 template <typename T>
65 {
66  return UT_Compare::Less<T>(compare);
67 }
68 
69 template <typename T>
72 {
73  return UT_Compare::Greater<T>(compare);
74 }
75 
76 template <typename T>
79 {
80  return UT_Compare::Equal<T>(compare);
81 }
82 /// @}
83 
84 #endif // __UT_COMPARE_H_INCLUDED__
int(*)(const T *, const T *) Ternary
Definition: UT_Compare.h:20
bool operator()(const T &lhs, const T &rhs)
Definition: UT_Compare.h:52
UT_Compare::Greater< T > UTcompareGreater(UT_Compare::Ternary< T > compare)
Definition: UT_Compare.h:71
Equal(Ternary< T > compare)
Definition: UT_Compare.h:50
Less(Ternary< T > compare)
Definition: UT_Compare.h:26
typedef int
Definition: png.h:1175
UT_Compare::Less< T > UTcompareLess(UT_Compare::Ternary< T > compare)
Definition: UT_Compare.h:64
UT_Compare::Equal< T > UTcompareEqual(UT_Compare::Ternary< T > compare)
Definition: UT_Compare.h:78
bool operator()(const T &lhs, const T &rhs)
Definition: UT_Compare.h:40
Greater(Ternary< T > compare)
Definition: UT_Compare.h:38
bool operator()(const T &lhs, const T &rhs)
Definition: UT_Compare.h:28