Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JComparable.hh
Go to the documentation of this file.
1#ifndef __JLANG__JCOMPARABLE__
2#define __JLANG__JCOMPARABLE__
3
4#include "JLang/JNullType.hh"
5#include "JLang/JClass.hh"
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JLANG {}
13namespace JPP { using namespace JLANG; }
14
15namespace JLANG {
16
17
18 /**
19 * Template definition of auxiliary base class for comparison of data structures.
20 *
21 * The various specialisations of this class implement the operators <tt> < > <= >= == != </tt>.
22 */
23 template<class JFirst_t, class JSecond_t = JNullType>
24 struct JComparable;
25
26
27 /**
28 * General purpose specialisation of class JComparable for any data type.
29 *
30 * The template parameter should have the corresponding member method:
31 * <pre>
32 * bool less(const JClass_t&) const;
33 * </pre>
34 *
35 * This class uses in-class friend operators (see Barton-Nackman trick).
36 */
37 template<class JClass_t>
38 struct JComparable<JClass_t, JNullType>
39 {
40 /**
41 * Less than operator.
42 *
43 * \param first first object
44 * \param second second object
45 * \return true if first object is less than second object; else false
46 */
47 friend bool operator<(const JClass_t& first,
48 const JClass_t& second)
49 {
50 return first.less(second);
51 }
52
53
54 /**
55 * Greater than operator.
56 *
57 * \param first first object
58 * \param second second object
59 * \return true if first object is greater than second object; else false
60 */
61 friend bool operator>(const JClass_t& first,
62 const JClass_t& second)
63 {
64 return second.less(first);
65 }
66
67
68 /**
69 * Less than or equal operator.
70 *
71 * \param first first object
72 * \param second second object
73 * \return true if first object is less than or equal to second object; else false
74 */
75 friend bool operator<=(const JClass_t& first,
76 const JClass_t& second)
77 {
78 return !second.less(first);
79 }
80
81
82 /**
83 * Greater than or equal operator.
84 *
85 * \param first first object
86 * \param second second object
87 * \return true if first object is greater than or equal to second object; else false
88 */
89 friend bool operator>=(const JClass_t& first,
90 const JClass_t& second)
91 {
92 return !first.less(second);
93 }
94
95
96 /**
97 * Equal operator.
98 *
99 * \param first first object
100 * \param second second object
101 * \return true if two objects are equal; else false
102 */
103 friend bool operator==(const JClass_t& first,
104 const JClass_t& second)
105 {
106 return !first.less(second) && !second.less(first);
107 }
108
109
110 /**
111 * Not equal operator.
112 *
113 * \param first first object
114 * \param second second object
115 * \return true if two objects are not equal; else false
116 */
117 friend bool operator!=(const JClass_t& first,
118 const JClass_t& second)
119 {
120 return first.less(second) || second.less(first);
121 }
122 };
123
124
125 /**
126 * Specialisation of class JComparable for two data types.
127 *
128 * The first template parameter should have the corresponding member methods:
129 * <pre>
130 * bool less(const JSecond_t&) const;
131 * bool more(const JSecond_t&) const;
132 * </pre>
133 * where <tt>JFirst_t</tt> andd <tt>JSecond_t</tt> refers to the first and second template parameter, respectively.
134 * The second template parameter may be a primitive data type.
135 * This class uses in-class friend operators (see Barton-Nackman trick).
136 */
137 template<class JFirst_t, class JSecond_t>
139 {
140 /**
141 * Less than operator.
142 *
143 * \param first first object
144 * \param second second object
145 * \return true if first object is less than second object; else false
146 */
147 friend bool operator<(const JFirst_t& first,
148 typename JClass<JSecond_t>::argument_type second)
149 {
150 return first.less(second);
151 }
152
153
154 /**
155 * Less than operator.
156 *
157 * \param first first object
158 * \param second second object
159 * \return true if first object is less than second object; else false
160 */
161 friend bool operator<(typename JClass<JSecond_t>::argument_type first,
162 const JFirst_t& second)
163 {
164 return second.more(first);
165 }
166
167
168 /**
169 * Greater than operator.
170 *
171 * \param first first object
172 * \param second second object
173 * \return true if first object is greater than second object; else false
174 */
175 friend bool operator>(const JFirst_t& first,
176 typename JClass<JSecond_t>::argument_type second)
177 {
178 return first.more(second);
179 }
180
181
182 /**
183 * Greater than operator.
184 *
185 * \param first first object
186 * \param second second object
187 * \return true if first object is greater than second object; else false
188 */
189 friend bool operator>(typename JClass<JSecond_t>::argument_type first,
190 const JFirst_t& second)
191 {
192 return second.less(first);
193 }
194
195
196 /**
197 * Less than or equal operator.
198 *
199 * \param first first object
200 * \param second second object
201 * \return true if first object is less than or equal to second object; else false
202 */
203 friend bool operator<=(const JFirst_t& first,
204 typename JClass<JSecond_t>::argument_type second)
205 {
206 return !first.more(second);
207 }
208
209
210 /**
211 * Less than or equal operator.
212 *
213 * \param first first object
214 * \param second second object
215 * \return true if first object is less than or equal to second object; else false
216 */
218 const JFirst_t& second)
219 {
220 return second.more(first);
221 }
222
223
224 /**
225 * Greater than or equal operator.
226 *
227 * \param first first object
228 * \param second second object
229 * \return true if first object is greater than or equal to second object; else false
230 */
231 friend bool operator>=(const JFirst_t& first,
232 typename JClass<JSecond_t>::argument_type second)
233 {
234 return !first.less(second);
235 }
236
237
238 /**
239 * Greater than or equal operator.
240 *
241 * \param first first object
242 * \param second second object
243 * \return true if first object is greater than or equal to second object; else false
244 */
246 const JFirst_t& second)
247
248 {
249 return second.less(first);
250 }
251
252
253 /**
254 * Equal operator.
255 *
256 * \param first first object
257 * \param second second object
258 * \return true if two objects are equal; else false
259 */
260 friend bool operator==(const JFirst_t& first,
261 typename JClass<JSecond_t>::argument_type second)
262 {
263 return !first.less(second) && !first.more(second);
264 }
265
266
267 /**
268 * Equal operator.
269 *
270 * \param first first object
271 * \param second second object
272 * \return true if two objects are equal; else false
273 */
275 const JFirst_t& second)
276
277 {
278 return !second.less(first) && !second.more(first);
279 }
280
281
282 /**
283 * Not equal operator.
284 *
285 * \param first first object
286 * \param second second object
287 * \return true if two objects are not equal; else false
288 */
289 friend bool operator!=(const JFirst_t& first,
290 typename JClass<JSecond_t>::argument_type second)
291 {
292 return first.less(second) || first.more(second);
293 }
294
295
296 /**
297 * Not equal operator.
298 *
299 * \param first first object
300 * \param second second object
301 * \return true if two objects are not equal; else false
302 */
304 const JFirst_t& second)
305 {
306 return second.less(first) || second.more(first);
307 }
308 };
309}
310
311#endif
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
friend bool operator==(const JClass_t &first, const JClass_t &second)
Equal operator.
friend bool operator<=(const JClass_t &first, const JClass_t &second)
Less than or equal operator.
friend bool operator>(const JClass_t &first, const JClass_t &second)
Greater than operator.
friend bool operator!=(const JClass_t &first, const JClass_t &second)
Not equal operator.
friend bool operator>=(const JClass_t &first, const JClass_t &second)
Greater than or equal operator.
friend bool operator<(const JClass_t &first, const JClass_t &second)
Less than operator.
Template definition of auxiliary base class for comparison of data structures.
friend bool operator>(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Greater than operator.
friend bool operator<(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Less than operator.
friend bool operator<=(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Less than or equal operator.
friend bool operator>=(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Greater than or equal operator.
friend bool operator!=(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Not equal operator.
friend bool operator!=(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Not equal operator.
friend bool operator<(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Less than operator.
friend bool operator<=(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Less than or equal operator.
friend bool operator>(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Greater than operator.
friend bool operator==(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Equal operator.
friend bool operator>=(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Greater than or equal operator.
friend bool operator==(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Equal operator.
Auxiliary class for no type definition.
Definition JNullType.hh:19