Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiEquals.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JMULTIEQUALS__
2 #define __JLANG__JMULTIEQUALS__
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 data structures
21  * composed of multiple base classes with equality evaluations capabilities.
22  *
23  * The data type <tt>JType_t</tt> should have the corresponding operator:
24  * <pre>
25  * bool operator==(const JType_t& first, const JType_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 JType_t>
32  struct JMultiEquals {
33  /**
34  * Equal operator.
35  *
36  * \param first first object
37  * \param second second object
38  * \return true if two objects are equal; else false
39  */
40  friend bool operator==(const JClass_t& first,
41  const JClass_t& second)
42  {
43  return static_cast<const JType_t&>(first) == static_cast<const JType_t&>(second);
44  }
45 
46 
47  /**
48  * Not equal operator.
49  *
50  * \param first first object
51  * \param second second object
52  * \return true if two objects are not equal; else false
53  */
54  friend bool operator!=(const JClass_t& first,
55  const JClass_t& second)
56  {
57  return static_cast<const JType_t&>(first) != static_cast<const JType_t&>(second);
58  }
59  };
60 
61 
62  /**
63  * Template specialisation of auxiliary base class for data structures
64  * composed of multiple base classes with equality evaluations capabilities.
65  *
66  * Each data type <tt>T</tt> in the type list should have the corresponding operator:
67  * <pre>
68  * bool operator==(const T& first, const T& second);
69  * </pre>
70  * This class uses in-class friend operators (see Barton-Nackman trick).
71  *
72  * This class implements the operators <tt> == != </tt>.
73  */
74  template<class JClass_t, class head_type, class tail_type>
75  struct JMultiEquals<JClass_t, JTypeList<head_type, tail_type> > {
76  protected:
77 
79 
80 
81  /**
82  * Equals method for composite data types.
83  *
84  * \param first first object
85  * \param second second object
86  * \param type type
87  * \return true if two objects are equal; else false
88  */
89  template<class JHead_t, class JTail_t>
90  static inline bool eq(const JClass_t& first,
91  const JClass_t& second,
92  const JType<JTypeList<JHead_t, JTail_t> >& type)
93  {
94  return (static_cast<const JHead_t&>(first) ==
95  static_cast<const JHead_t&>(second) &&
96  eq(first, second, JType<JTail_t>()));
97  }
98 
99 
100  /**
101  * Equals method for composite data types.
102  *
103  * \param first first object
104  * \param second second object
105  * \param type type
106  * \return true if two objects are equal; else false
107  */
108  template<class JHead_t>
109  static inline bool eq(const JClass_t& first,
110  const JClass_t& second,
111  const JType<JTypeList<JHead_t, JNullType> >& type)
112  {
113  return (static_cast<const JHead_t&>(first) ==
114  static_cast<const JHead_t&>(second));
115  }
116 
117  public:
118  /**
119  * Equal operator.
120  *
121  * \param first first object
122  * \param second second object
123  * \return true if two objects are equal; else false
124  */
125  friend bool operator==(const JClass_t& first,
126  const JClass_t& second)
127  {
128  return eq(first, second, JType<JTypelist_t>());
129  }
130 
131 
132  /**
133  * Not equal operator.
134  *
135  * \param first first object
136  * \param second second object
137  * \return true if two objects are not equal; else false
138  */
139  friend bool operator!=(const JClass_t& first,
140  const JClass_t& second)
141  {
142  return !eq(first, second, JType<JTypelist_t>());
143  }
144  };
145 }
146 
147 #endif
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)
Equal operator.
Definition: JMultiEquals.hh:40
friend bool operator!=(const JClass_t &first, const JClass_t &second)
Not equal operator.
Definition: JMultiEquals.hh:54
Auxiliary class for a type holder.
Definition: JType.hh:19
static bool eq(const JClass_t &first, const JClass_t &second, const JType< JTypeList< JHead_t, JNullType > > &type)
Equals method for composite data types.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Template definition of auxiliary base class for data structures composed of multiple base classes wit...
Definition: JMultiEquals.hh:32
Type list.
Definition: JTypeList.hh:22
static bool eq(const JClass_t &first, const JClass_t &second, const JType< JTypeList< JHead_t, JTail_t > > &type)
Equals method for composite data types.
Definition: JMultiEquals.hh:90
friend bool operator==(const JClass_t &first, const JClass_t &second)
Equal operator.