Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JEquals.hh
Go to the documentation of this file.
1#ifndef __JLANG__JEQUALS__
2#define __JLANG__JEQUALS__
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 JEquals;
25
26
27 /**
28 * General purpose specialisation of class JEquals for any data type.
29 *
30 * The template parameter should have the corresponding member method:
31 * <pre>
32 * bool equals(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 JEquals<JClass_t, JNullType>
39 {
40 /**
41 * Equal operator.
42 *
43 * \param first first object
44 * \param second second object
45 * \return true if two objects are equal; else false
46 */
47 friend bool operator==(const JClass_t& first,
48 const JClass_t& second)
49 {
50 return first.equals(second);
51 }
52
53
54 /**
55 * Not equal operator.
56 *
57 * \param first first object
58 * \param second second object
59 * \return true if two objects are not equal; else false
60 */
61 friend bool operator!=(const JClass_t& first,
62 const JClass_t& second)
63 {
64 return !first.equals(second);
65 }
66 };
67
68
69 /**
70 * Specialisation of class JEquals for two data types.
71 *
72 * The first template parameter should have the corresponding member methods:
73 * <pre>
74 * bool equals(const JFirst_t&) const;
75 * bool equals(const JSecond_t&) const;
76 * </pre>
77 * where <tt>JFirst_t</tt> and <tt>JSecond_t</tt> refer to the first and second template parameter, respectively.
78 * The second template parameter may be a primitive data type.
79 * This class uses in-class friend operators (see Barton-Nackman trick).
80 */
81 template<class JFirst_t, class JSecond_t>
82 struct JEquals :
83 public JEquals<JFirst_t>
84 {
85 /**
86 * Equal operator.
87 *
88 * \param first first object
89 * \param second second object
90 * \return true if two objects are equal; else false
91 */
92 friend bool operator==(const JFirst_t& first,
94 {
95 return first.equals(second);
96 }
97
98
99 /**
100 * Equal operator.
101 *
102 * \param first first object
103 * \param second second object
104 * \return true if two objects are equal; else false
105 */
107 const JFirst_t& second)
108 {
109 return second.equals(first);
110 }
111
112
113 /**
114 * Not equal operator.
115 *
116 * \param first first object
117 * \param second second object
118 * \return true if two objects are not equal; else false
119 */
120 friend bool operator!=(const JFirst_t& first,
121 typename JClass<JSecond_t>::argument_type second)
122 {
123 return !first.equals(second);
124 }
125
126
127 /**
128 * Not equal operator.
129 *
130 * \param first first object
131 * \param second second object
132 * \return true if two objects are not equal; else false
133 */
135 const JFirst_t& second)
136 {
137 return !second.equals(first);
138 }
139 };
140}
141
142#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.
Definition JEquals.hh:47
friend bool operator!=(const JClass_t &first, const JClass_t &second)
Not equal operator.
Definition JEquals.hh:61
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
friend bool operator!=(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Not equal operator.
Definition JEquals.hh:134
friend bool operator!=(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Not equal operator.
Definition JEquals.hh:120
friend bool operator==(typename JClass< JSecond_t >::argument_type first, const JFirst_t &second)
Equal operator.
Definition JEquals.hh:106
friend bool operator==(const JFirst_t &first, typename JClass< JSecond_t >::argument_type second)
Equal operator.
Definition JEquals.hh:92
Auxiliary class for no type definition.
Definition JNullType.hh:19