Jpp  15.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiComparable.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JMULTICOMPARABLE__
2 #define __JLANG__JMULTICOMPARABLE__
3 
4 #include "JLang/JNullType.hh"
5 #include "JLang/JTypeList.hh"
6 #include "JLang/JType.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JLANG {}
14 namespace JPP { using namespace JLANG; }
15 
16 namespace JLANG {
17 
18 
19  /**
20  * Template definition of auxiliary base class for composite data structures
21  * composed of base classes with comparisons capabilities.
22  *
23  * Each data type <tt>T</tt> in the type list should have the corresponding operator:
24  * <pre>
25  * bool operator<(const T&, const T& second);
26  * </pre>
27  * This class uses in-class friend operators (see Barton-Nackman trick).
28  *
29  * This class implements the operators <tt> < > <= >= == != </tt>.
30  */
31  template<class JClass_t, class JTypelist_t>
33  protected:
34  /**
35  * Less than method for composite data types.
36  *
37  * \param first first object
38  * \param second second object
39  * \param type type
40  * \return true if first object is less than second object; else false
41  */
42  template<class JHead_t, class JTail_t>
43  static inline bool lt(const JClass_t& first,
44  const JClass_t& second,
45  const JType<JTypeList<JHead_t, JTail_t> >& type)
46  {
47  if (static_cast<const JHead_t&>(first) <
48  static_cast<const JHead_t&>(second))
49  return true;
50  else if (static_cast<const JHead_t&>(second) <
51  static_cast<const JHead_t&>(first))
52  return false;
53  else
54  return lt(first, second, JType<JTail_t>());
55  }
56 
57 
58  /**
59  * Less than method for composite data types.
60  *
61  * \param first first object
62  * \param second second object
63  * \param type type
64  * \return true if first object is less than second object; else false
65  */
66  template<class JHead_t>
67  static inline bool lt(const JClass_t& first,
68  const JClass_t& second,
70  {
71  return (static_cast<const JHead_t&>(first) <
72  static_cast<const JHead_t&>(second));
73  }
74 
75  public:
76  /**
77  * Less than operator.
78  *
79  * \param first first object
80  * \param second second object
81  * \return true if first object is less than second object; else false
82  */
83  friend bool operator<(const JClass_t& first,
84  const JClass_t& second)
85  {
86  return lt(first, second, JType<JTypelist_t>());
87  }
88 
89 
90  /**
91  * Greater than operator.
92  *
93  * \param first first object
94  * \param second second object
95  * \return true if first object is greater than second object; else false
96  */
97  friend bool operator>(const JClass_t& first,
98  const JClass_t& second)
99  {
100  return lt(second, first, JType<JTypelist_t>());
101  }
102 
103 
104  /**
105  * Less than or equal operator.
106  *
107  * \param first first object
108  * \param second second object
109  * \return true if first object is less than or equal to second object; else false
110  */
111  friend bool operator<=(const JClass_t& first,
112  const JClass_t& second)
113  {
114  return !lt(second, first, JType<JTypelist_t>());
115  }
116 
117 
118  /**
119  * Greater than or equal operator.
120  *
121  * \param first first object
122  * \param second second object
123  * \return true if first object is greater than or equal to second object; else false
124  */
125  friend bool operator>=(const JClass_t& first,
126  const JClass_t& second)
127  {
128  return !lt(first, second, JType<JTypelist_t>());
129  }
130 
131 
132  /**
133  * Equal operator.
134  *
135  * \param first first object
136  * \param second second object
137  * \return true if two objects are equal; else false
138  */
139  friend bool operator==(const JClass_t& first,
140  const JClass_t& second)
141  {
142  return (!lt(first, second, JType<JTypelist_t>()) &&
143  !lt(second, first, JType<JTypelist_t>()));
144  }
145 
146 
147  /**
148  * Not equal operator.
149  *
150  * \param first first object
151  * \param second second object
152  * \return true if two objects are not equal; else false
153  */
154  friend bool operator!=(const JClass_t& first,
155  const JClass_t& second)
156  {
157  return (lt(first, second, JType<JTypelist_t>()) ||
158  lt(second, first, JType<JTypelist_t>()));
159  }
160  };
161 }
162 
163 #endif
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)
Less than operator.
Auxiliary class for a type holder.
Definition: JType.hh:19
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Type list.
Definition: JTypeList.hh:22
friend bool operator>(const JClass_t &first, const JClass_t &second)
Greater than operator.
static bool lt(const JClass_t &first, const JClass_t &second, const JType< JTypeList< JHead_t, JTail_t > > &type)
Less than method for composite data types.
static bool lt(const JClass_t &first, const JClass_t &second, const JType< JTypeList< JHead_t, JNullType > > &type)
Less than method for composite data types.
friend bool operator==(const JClass_t &first, const JClass_t &second)
Equal 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.
Template definition of auxiliary base class for composite data structures composed of base classes wi...