Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTypeSelector.hh
Go to the documentation of this file.
1#ifndef __JLANG__JTYPESELECTOR__
2#define __JLANG__JTYPESELECTOR__
3
5#include "JLang/JType.hh"
6
7/**
8 * \author mdejong
9 */
10
11namespace JLANG {}
12namespace JPP { using namespace JLANG; }
13
14namespace JLANG {
15
16 /**
17 * Auxiliary class for selection of data type.
18 *
19 * This class implements the JLANG::JObjectSelector interface.
20 */
21 template<class T>
23 public virtual JObjectSelector<T>
24 {
25 /**
26 * Type definition of argument of interface method.
27 */
29
30
31 /**
32 * Default constructor.
33 */
35 is_enabled(true)
36 {}
37
38
39 /**
40 * Constructor.
41 *
42 * \param selector selector
43 */
44 template<class JSelector_t>
45 JTypeSelector(const JSelector_t& selector)
46 {
47 (*this)(selector);
48 }
49
50
51 /**
52 * Accept data type.
53 *
54 * \return true if accepted; else false
55 */
56 virtual bool accept() const override
57 {
58 return is_enabled;
59 }
60
61
62 /**
63 * Accept object.
64 *
65 * \param object object
66 * \return true
67 */
68 virtual bool accept(argument_type object) const override
69 {
70 return true;
71 }
72
73
74 /**
75 * Set acceptance.
76 *
77 * \param status enabled status
78 */
79 void set(const bool status)
80 {
81 this->is_enabled = status;
82 }
83
84
85 /**
86 * Set selection.
87 *
88 * The template argument <tt>JSelector_t</tt> refers to a data structure
89 * which should provide for the function object operator:
90 * <pre>
91 * bool operator()(JType<T>& type) const; // get status of data type
92 * </pre>
93 *
94 * \param selector selector
95 */
96 template<class JSelector_t>
97 JTypeSelector& operator()(const JSelector_t& selector)
98 {
99 this->is_enabled = selector(JType<T>());
100
101 return *this;
102 }
103
105
106 protected:
108 };
109
110 /**
111 * Selector.
112 */
113 template<class T>
115
116
117 /**
118 * Auxiliary class for selection of multiple data types.
119 *
120 * This class recursively defines the JLANG::JTypeSelector interface
121 * for all data types by deriving from:
122 * - JTypeSelector<JHead_t>; and
123 * - JTypeSelector<JTail_t>.
124 */
125 template<class JHead_t, class JTail_t>
126 struct JTypeSelector< JTypeList<JHead_t, JTail_t> > :
127 public JTypeSelector<JHead_t>,
128 public JTypeSelector<JTail_t>,
129 public virtual JObjectSelector< JTypeList<JHead_t, JTail_t> >
130 {
131 /**
132 * Default constructor.
133 */
136
137
138 /**
139 * Constructor.
140 *
141 * \param selector selector
142 */
143 template<class JSelector_t>
144 JTypeSelector(const JSelector_t& selector)
145 {
146 (*this)(selector);
147 }
148
149
150 /**
151 * Set selection.
152 *
153 * The template argument <tt>JSelector_t</tt> refers to a data structure
154 * which should provide for the function object operator:
155 * <pre>
156 * bool operator()(JType<T>& type) const; // get status of data type
157 * </pre>
158 *
159 * \param selector selector
160 */
161 template<class JSelector_t>
162 JTypeSelector& operator()(const JSelector_t& selector)
163 {
164 static_cast<JTypeSelector<JHead_t>&>(*this)(selector);
165 static_cast<JTypeSelector<JTail_t>&>(*this)(selector);
166
167 return *this;
168 }
169
171 };
172
173 /**
174 * Selector.
175 */
176 template<class JHead_t, class JTail_t>
178
179
180 /**
181 * Terminator class of recursive JTypeSelector class.
182 */
183 template<class JHead_t>
184 struct JTypeSelector< JTypeList<JHead_t, JNullType> > :
185 public JTypeSelector<JHead_t>
186 {
187 /**
188 * Default constructor.
189 */
192
193
194 /**
195 * Constructor.
196 *
197 * \param selector selector
198 */
199 template<class JSelector_t>
200 JTypeSelector(const JSelector_t& selector)
201 {
202 (*this)(selector);
203 }
204 };
205}
206
207#endif
Interface for selection of objects.
JClass< T >::argument_type argument_type
Type definition of argument of interface method.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23
JTypeSelector(const JSelector_t &selector)
Constructor.
JTypeSelector & operator()(const JSelector_t &selector)
Set selection.
JTypeSelector(const JSelector_t &selector)
Constructor.
Auxiliary class for selection of data type.
JObjectSelector< T >::argument_type argument_type
Type definition of argument of interface method.
void set(const bool status)
Set acceptance.
JTypeSelector & operator()(const JSelector_t &selector)
Set selection.
JTypeSelector()
Default constructor.
static JTypeSelector selector
Selector.
virtual bool accept() const override
Accept data type.
JTypeSelector(const JSelector_t &selector)
Constructor.
virtual bool accept(argument_type object) const override
Accept object.
Auxiliary class for a type holder.
Definition JType.hh:19