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 int __cmp__(const Name& o) const; \
53 bool __eq__(const Name& o) const; \
54 bool __ne__(const Name& o) const; \
55 bool __lt__(const Name& o) const; \
56 bool __gt__(const Name& o) const; \
57 bool __ge__(const Name& o) const; \
58 bool __le__(const Name& o) const
60 #define IMP_COMPARISONS(Name) IMP_SWIG_COMPARISONS(Name)
62 #define IMP_COMPARISONS_1(Name, field) IMP_SWIG_COMPARISONS(Name)
64 #define IMP_COMPARISONS_2(Name, f0, f1) IMP_SWIG_COMPARISONS(Name)
66 #define IMP_COMPARISONS_3(Name, f0, f1, f2) IMP_SWIG_COMPARISONS(Name)
69 #define IMP_SWIG_COMPARISONS(Name) \
70 IMP_HELPER_MACRO_PUSH_WARNINGS bool __eq__(const Name& o) const { \
71 return operator==(o); \
73 bool __ne__(const Name& o) const { return operator!=(o); } \
74 bool __lt__(const Name& o) const { return operator<(o); } \
75 bool __gt__(const Name& o) const { return operator>(o); } \
76 bool __ge__(const Name& o) const { return operator>=(o); } \
77 bool __le__(const Name& o) const { return operator<=(o); } \
78 int __cmp__(const Name& o) const { return compare(o); } \
79 IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(comparisons)
81 #define IMP_COMPARISONS(Name) \
82 IMP_SWIG_COMPARISONS(Name); \
83 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
84 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 (Name::compare(o) < 0); } \
88 bool operator>(const Name& o) const { return (compare(o) > 0); } \
89 bool operator>=(const Name& o) const { return !(Name::compare(o) < 0); } \
90 bool operator<=(const Name& o) const { return !(Name::compare(o) > 0); } \
91 IMP_HELPER_MACRO_POP_WARNINGS template <class T> \
92 friend int compare(const T& a, const T& b)
94 #define IMP_COMPARISONS_1(Name, field) \
95 IMP_SWIG_COMPARISONS(Name); \
96 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
97 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 bool operator<=(const Name& o) const { return (field <= o.field); } \
104 int compare(const Name& o) const { \
107 else if (operator>(o)) \
112 IMP_HELPER_MACRO_POP_WARNINGS
114 #define IMP_COMPARISONS_2(Name, f0, f1) \
115 IMP_SWIG_COMPARISONS(Name); \
116 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
117 return (f0 == o.f0 && f1 == o.f1); \
119 bool operator!=(const Name& o) const { return (f0 != o.f0 || f1 != o.f1); } \
120 bool operator<(const Name& o) const { \
123 else if (f0 > o.f0) \
128 bool operator>(const Name& o) const { \
131 else if (f0 < o.f0) \
136 bool operator>=(const Name& o) const { return operator>(o) || operator==( \
138 bool operator<=(const Name& o) const { return operator<(o) || operator==( \
140 int compare(const Name& o) const { \
143 else if (operator>(o)) \
148 IMP_HELPER_MACRO_POP_WARNINGS
150 #define IMP_COMPARISONS_3(Name, f0, f1, f2) \
151 IMP_SWIG_COMPARISONS(Name); \
152 IMP_HELPER_MACRO_PUSH_WARNINGS bool operator==(const Name& o) const { \
153 return (f0 == o.f0 && f1 == o.f1 && f2 == o.f2); \
155 bool operator!=(const Name& o) const { \
156 return (f0 != o.f0 || f1 != o.f1 || f2 != o.f2); \
158 bool operator<(const Name& o) const { \
161 else if (f0 > o.f0) \
165 else if (f1 > o.f1) \
170 bool operator>(const Name& o) const { \
173 else if (f0 < o.f0) \
177 else if (f1 < o.f1) \
182 bool operator>=(const Name& o) const { return operator>(o) || operator==( \
184 bool operator<=(const Name& o) const { return operator<(o) || operator==( \
186 int compare(const Name& o) const { \
189 else if (operator>(o)) \
194 IMP_HELPER_MACRO_POP_WARNINGS
198 #define IMP_SAFE_BOOL(Name, expr)
203 #define IMP_SAFE_BOOL(Name, expr) \
205 typedef void (Name::*bool_type)() const; \
206 void this_type_does_not_support_comparisons() const {} \
209 operator bool_type() const { \
210 return (expr) ? &Name::this_type_does_not_support_comparisons : 0; \
218 #define IMP_COMPARE_ONE(vara, varb) \
221 else if (varb < vara) \
Various general useful macros for IMP.