Jpp
JPredicate.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JPREDICATE__
2 #define __JLANG__JPREDICATE__
3 
4 #include "JLang/JClass.hh"
5 #include "JLang/JComparison.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JLANG {}
13 namespace JPP { using namespace JLANG; }
14 
15 namespace 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>
23  class JPredicate;
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  * \param comparator comparator between return values
173  * \return predicate
174  */
175  template<class T, class JResult_t, class JComparator_t>
176  JPredicate<JResult_t (T::*)() const, JComparator_t> make_predicate(JResult_t (T::*function)() const,
177  const JResult_t value,
178  const JComparator_t& comparator)
179  {
180  return JPredicate<JResult_t (T::*)() const, JComparator_t>(function, value, comparator);
181  }
182 }
183 
184 #endif
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::data_type
JResult_t data_type
Definition: JPredicate.hh:80
JLANG::JPredicate< JResult_t T::*, JComparator_t >::JPredicate
JPredicate(data_member member, argument_type value, const comparator_type &comparator=comparator_type())
Constructor.
Definition: JPredicate.hh:46
JLANG::JPredicate< JResult_t T::*, JComparator_t >::data_type
JResult_t data_type
Definition: JPredicate.hh:33
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >
Template specialisation of JPredicate for selection of objects via member method.
Definition: JPredicate.hh:77
JLANG::JPredicate< JResult_t T::*, JComparator_t >::member
data_member member
Definition: JPredicate.hh:67
JLANG::JPredicate
Template definition of auxiliary class to select objects.
Definition: JPredicate.hh:23
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::argument_type
JClass< data_type >::argument_type argument_type
Definition: JPredicate.hh:81
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::JPredicate
JPredicate(member_method function, argument_type value, const comparator_type &comparator=comparator_type())
Constructor.
Definition: JPredicate.hh:93
JLANG::JPredicate< JResult_t T::*, JComparator_t >::operator()
bool operator()(const T &object) const
Select objets.
Definition: JPredicate.hh:61
JComparison.hh
JLANG::JClass::argument_type
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JLANG::JPredicate< JResult_t T::*, JComparator_t >::comparator
comparator_type comparator
Definition: JPredicate.hh:69
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JPredicate< JResult_t T::*, JComparator_t >::value
data_type value
Definition: JPredicate.hh:68
JLANG::JPredicate< JResult_t T::*, JComparator_t >::comparator_type
JComparator_t comparator_type
Type definition of comparator.
Definition: JPredicate.hh:36
JLANG::make_predicate
JPredicate< JResult_t(T::*)() const, JComparator_t > make_predicate(JResult_t(T::*function)() const, const JResult_t value, const JComparator_t &comparator)
Helper method to create predicate for return values of member method.
Definition: JPredicate.hh:176
JLANG::JComparison::eq
Equal.
Definition: JComparison.hh:25
JLANG::JPredicate< JResult_t T::*, JComparator_t >::data_member
JResult_t T::* data_member
Type definition of data member.
Definition: JPredicate.hh:35
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::operator()
bool operator()(const T &object) const
Select objets.
Definition: JPredicate.hh:108
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::value
data_type value
Definition: JPredicate.hh:115
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::comparator_type
JComparator_t comparator_type
Type definition of comparator.
Definition: JPredicate.hh:83
JLANG::JPredicate< JResult_t(T::*)() const, JComparator_t >::comparator
comparator_type comparator
Definition: JPredicate.hh:116
JLANG::JPredicate< JResult_t T::*, JComparator_t >
Template specialisation of JPredicate for selection of objects via data member.
Definition: JPredicate.hh:30
JClass.hh
JLANG::JPredicate< JResult_t T::*, JComparator_t >::argument_type
JClass< data_type >::argument_type argument_type
Definition: JPredicate.hh:34
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10