9 #ifndef IMPBASE_COMPARISON_MACROS_H
10 #define IMPBASE_COMPARISON_MACROS_H
11 #include <IMP/base/base_config.h>
14 #if defined(IMP_DOXYGEN)
27 #define IMP_COMPARISONS(Name)
33 #define IMP_COMPARISONS_1(Name, field)
40 #define IMP_COMPARISONS_2(Name, f0, f1)
48 #define IMP_COMPARISONS_3(Name, f0, f1, f2)
51 #define IMP_SWIG_COMPARISONS(Name) \
52 bool __eq__(const Name& o) const; \
53 bool __ne__(const Name& o) const; \
54 bool __lt__(const Name& o) const; \
55 bool __gt__(const Name& o) const; \
56 bool __ge__(const Name& o) const; \
57 bool __le__(const Name& o) const
59 #define IMP_COMPARISONS(Name) IMP_SWIG_COMPARISONS(Name)
61 #define IMP_COMPARISONS_1(Name, field) IMP_SWIG_COMPARISONS(Name)
63 #define IMP_COMPARISONS_2(Name, f0, f1) IMP_SWIG_COMPARISONS(Name)
65 #define IMP_COMPARISONS_3(Name, f0, f1, f2) IMP_SWIG_COMPARISONS(Name)
68 #define IMP_SWIG_COMPARISONS(Name) \
69 IMP_HELPER_MACRO_PUSH_WARNINGS bool __eq__(const Name& o) const { \
70 return operator==(o); \
72 bool __ne__(const Name& o) const { return operator!=(o); } \
73 bool __lt__(const Name& o) const { return operator<(o); } \
74 bool __gt__(const Name& o) const { return operator>(o); } \
75 bool __ge__(const Name& o) const { return operator>=(o); } \
76 bool __le__(const Name& o) const { return operator<=(o); } \
77 int __cmp__(const Name& o) const { return compare(o); } \
78 IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(comparisons)
80 #define IMP_COMPARISONS(Name) \
81 IMP_SWIG_COMPARISONS(Name); \
82 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
83 return (Name::compare(o) == 0); \
85 bool operator!=(const Name& o) const { return (Name::compare(o) != 0); } \
86 bool operator<(const Name& o) const { return (Name::compare(o) < 0); } \
87 bool operator>(const Name& o) const { return (compare(o) > 0); } \
88 bool operator>=(const Name& o) const { return !(Name::compare(o) < 0); } \
89 bool operator<=(const Name& o) const { return !(Name::compare(o) > 0); } \
90 IMP_HELPER_MACRO_POP_WARNINGS template <class T> \
91 friend int compare(const T& a, const T& b)
93 #define IMP_COMPARISONS_1(Name, field) \
94 IMP_SWIG_COMPARISONS(Name); \
95 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
96 return (field == o.field); \
98 bool operator!=(const Name& o) const { return (field != o.field); } \
99 bool operator<(const Name& o) const { return (field < o.field); } \
100 bool operator>(const Name& o) const { return (field > o.field); } \
101 bool operator>=(const Name& o) const { return (field >= o.field); } \
102 bool operator<=(const Name& o) const { return (field <= o.field); } \
103 int compare(const Name& o) const { \
106 else if (operator>(o)) \
111 IMP_HELPER_MACRO_POP_WARNINGS
113 #define IMP_COMPARISONS_2(Name, f0, f1) \
114 IMP_SWIG_COMPARISONS(Name); \
115 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
116 return (f0 == o.f0 && f1 == o.f1); \
118 bool operator!=(const Name& o) const { return (f0 != o.f0 || f1 != o.f1); } \
119 bool operator<(const Name& o) const { \
122 else if (f0 > o.f0) \
127 bool operator>(const Name& o) const { \
130 else if (f0 < o.f0) \
135 bool operator>=(const Name& o) const { return operator>(o) || operator==( \
137 bool operator<=(const Name& o) const { return operator<(o) || operator==( \
139 int compare(const Name& o) const { \
142 else if (operator>(o)) \
147 IMP_HELPER_MACRO_POP_WARNINGS
149 #define IMP_COMPARISONS_3(Name, f0, f1, f2) \
150 IMP_SWIG_COMPARISONS(Name); \
151 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
152 return (f0 == o.f0 && f1 == o.f1 && f2 == o.f2); \
154 bool operator!=(const Name& o) const { \
155 return (f0 != o.f0 || f1 != o.f1 || f2 != o.f2); \
157 bool operator<(const Name& o) const { \
160 else if (f0 > o.f0) \
164 else if (f1 > o.f1) \
169 bool operator>(const Name& o) const { \
172 else if (f0 < o.f0) \
176 else if (f1 < o.f1) \
181 bool operator>=(const Name& o) const { return operator>(o) || operator==( \
183 bool operator<=(const Name& o) const { return operator<(o) || operator==( \
185 int compare(const Name& o) const { \
188 else if (operator>(o)) \
193 IMP_HELPER_MACRO_POP_WARNINGS
197 #define IMP_SAFE_BOOL(Name, expr)
202 #define IMP_SAFE_BOOL(Name, expr) \
204 typedef void (Name::*bool_type)() const; \
205 void this_type_does_not_support_comparisons() const {} \
208 operator bool_type() const { \
209 return (expr) ? &Name::this_type_does_not_support_comparisons : 0; \
217 #define IMP_COMPARE_ONE(vara, varb) \
220 else if (varb < vara) \
Various general useful macros for IMP.