Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JPredicate.hh
Go to the documentation of this file.
1#ifndef __JLANG__JPREDICATE__
2#define __JLANG__JPREDICATE__
3
4#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 * Template definition of auxiliary class to select objects.
19 * The first template argument refers to the data member or member method and
20 * the second template argument to the comparator of the corresponding values.
21 */
22 template<class JTypename_t, class JComparator_t = JComparison::eq>
24
25
26 /**
27 * Template specialisation of JPredicate for selection of objects via data member.
28 */
29 template<class T, class JResult_t, class JComparator_t>
30 class JPredicate<JResult_t T::*, JComparator_t> {
31 public:
32
33 typedef JResult_t data_type;
35 typedef JResult_t T::*data_member; //!< Type definition of data member
36 typedef JComparator_t comparator_type; //!< Type definition of comparator
37
38
39 /**
40 * Constructor.
41 *
42 * \param member pointer to data member
43 * \param value value
44 * \param comparator comparator method
45 */
47 argument_type value,
48 const comparator_type& comparator = comparator_type()) :
49 member (member),
50 value (value),
51 comparator(comparator)
52 {}
53
54
55 /**
56 * Select objets.
57 *
58 * \param object object
59 * \return true if selected; else false
60 */
61 bool operator()(const T& object) const
62 {
63 return comparator(object.*member, value);
64 }
65
66 protected:
70 };
71
72
73 /**
74 * Template specialisation of JPredicate for selection of objects via member method.
75 */
76 template<class T, class JResult_t, class JComparator_t>
77 class JPredicate<JResult_t (T::*)() const, JComparator_t> {
78 public:
79
80 typedef JResult_t data_type;
82 typedef JResult_t (T::*member_method)() const; //!< Type definition of member method
83 typedef JComparator_t comparator_type; //!< Type definition of comparator
84
85
86 /**
87 * Constructor.
88 *
89 * \param function pointer to member method
90 * \param value value
91 * \param comparator comparator method
92 */
93 JPredicate(member_method function,
94 argument_type value,
95 const comparator_type& comparator = comparator_type()) :
96 function (function),
97 value (value),
98 comparator(comparator)
99 {}
100
101
102 /**
103 * Select objets.
104 *
105 * \param object object
106 * \return true if selected; else false
107 */
108 bool operator()(const T& object) const
109 {
110 return comparator((object.*function)(), value);
111 }
112
113 protected:
114 member_method function;
117 };
118
119
120 /**
121 * Helper method to create predicate for data member.
122 *
123 * \param member pointer to data member
124 * \param value value
125 * \return predicate
126 */
127 template<class T, class JResult_t>
129 const JResult_t value)
130 {
132 }
133
134
135 /**
136 * Helper method to create predicate for data member.
137 *
138 * \param member pointer to data member
139 * \param value value
140 * \param comparator comparator between values of data members
141 * \return predicate
142 */
143 template<class T, class JResult_t, class JComparator_t>
145 const JResult_t value,
146 const JComparator_t& comparator)
147 {
148 return JPredicate<JResult_t T::*, JComparator_t>(member, value, comparator);
149 }
150
151
152 /**
153 * Helper method to create predicate for return values of member method.
154 *
155 * \param function pointer to member method
156 * \param value value
157 * \return predicate
158 */
159 template<class T, class JResult_t>
160 JPredicate<JResult_t (T::*)() const, JComparison::eq> make_predicate(JResult_t (T::*function)() const,
161 const JResult_t value)
162 {
164 }
165
166
167 /**
168 * Helper method to create predicate for return values of member method.
169 *
170 * \param function pointer to member method
171 * \param value value
172 * \return predicate
173 */
174 template<class T, class JResult_t>
175 JPredicate<const JResult_t& (T::*)() const, JComparison::eq> make_predicate(const JResult_t& (T::*function)() const,
176 const JResult_t& value)
177 {
179 }
180
181
182 /**
183 * Helper method to create predicate for return values of member method.
184 *
185 * \param function pointer to member method
186 * \param value value
187 * \param comparator comparator between return values
188 * \return predicate
189 */
190 template<class T, class JResult_t, class JComparator_t>
191 JPredicate<JResult_t (T::*)() const, JComparator_t> make_predicate(JResult_t (T::*function)() const,
192 const JResult_t value,
193 const JComparator_t& comparator)
194 {
195 return JPredicate<JResult_t (T::*)() const, JComparator_t>(function, value, comparator);
196 }
197
198
199 /**
200 * Helper method to create predicate for return values of member method.
201 *
202 * \param function pointer to member method
203 * \param value value
204 * \param comparator comparator between return values
205 * \return predicate
206 */
207 template<class T, class JResult_t, class JComparator_t>
208 JPredicate<const JResult_t& (T::*)() const, JComparator_t> make_predicate(const JResult_t& (T::*function)() const,
209 const JResult_t& value,
210 const JComparator_t& comparator)
211 {
212 return JPredicate<const JResult_t& (T::*)() const, JComparator_t>(function, value, comparator);
213 }
214}
215
216#endif
JComparator_t comparator_type
Type definition of comparator.
Definition JPredicate.hh:36
JPredicate(data_member member, argument_type value, const comparator_type &comparator=comparator_type())
Constructor.
Definition JPredicate.hh:46
JResult_t T::* data_member
Type definition of data member.
Definition JPredicate.hh:35
JClass< data_type >::argument_type argument_type
Definition JPredicate.hh:34
bool operator()(const T &object) const
Select objets.
Definition JPredicate.hh:61
JComparator_t comparator_type
Type definition of comparator.
Definition JPredicate.hh:83
JPredicate(member_method function, argument_type value, const comparator_type &comparator=comparator_type())
Constructor.
Definition JPredicate.hh:93
bool operator()(const T &object) const
Select objets.
Template definition of auxiliary class to select objects.
Definition JPredicate.hh:23
Auxiliary classes and methods for language specific functionality.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
Functional implementations of comparison operators.