Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JObjectIterator.hh
Go to the documentation of this file.
1#ifndef __JLANG__JOBJECTITERATOR__
2#define __JLANG__JOBJECTITERATOR__
3
4#include "JLang/JType.hh"
5#include "JLang/JTypeList.hh"
6#include "JLang/JNullType.hh"
7#include "JLang/JPointer.hh"
10#include "JLang/JAccessible.hh"
11
12
13/**
14 * \author mdejong
15 */
16
17namespace JLANG {}
18namespace JPP { using namespace JLANG; }
19
20namespace JLANG {
21
22 /**
23 * Type definition for number of objects to skip.
24 */
25 typedef unsigned int skip_type;
26
27
28 /**
29 * \cond NEVER
30 * Forward declarations for definitions of I/O redirect and pipe operators.
31 * \endcond
32 */
33 template<class T> class JObjectOutput;
34 template<class T> class JValve;
35 template<class T> class JObjectSelector;
36 class JRegulator;
37 template<class JDerived_t, class JBase_t> class JObjectMultiplexer;
38 template<class T, int N> class JMultiPipe;
39
40
41 /**
42 * Interface of object iteration for a single data type.
43 */
44 template<class T>
46 protected:
47 /**
48 * Default constructor.
49 */
52
53
54 public:
55 /**
56 * Type definition of pointer_type.
57 */
59
60
61 /**
62 * Virtual destructor.
63 */
65 {}
66
67
68 /**
69 * Check availability of next element.
70 *
71 * \return true if the iteration has more elements; else false
72 */
73 virtual bool hasNext() = 0;
74
75
76 /**
77 * Get next element.
78 *
79 * \return pointer to element
80 */
81 virtual const pointer_type& next() = 0;
82
83
84 /**
85 * Skip items.
86 *
87 * \param ns number of items to skip
88 * \return number of items skipped
89 */
90 virtual skip_type skip(const skip_type ns)
91 {
92 skip_type i = 0;
93
94 for ( ; i != ns && hasNext(); ++i) {
95 next();
96 }
97
98 return i;
99 }
100
101
102 /**
103 * Copy to object output.
104 *
105 * \param in object iterator
106 * \param out object output
107 * \return object iterator
108 */
110 JObjectOutput <T>& out)
111 {
112 while (in.hasNext()) {
113
114 const T* p = in.next();
115
116 if (p != NULL)
117 out.put(*p);
118 else
119 break;
120 }
121
122 return in;
123 }
124
125
126 /**
127 * Pipe terminator.
128 *
129 * \param left object iterator
130 * \param right object output
131 */
132 friend inline void operator|(JObjectIterator<T>& left, JObjectOutput<T>& right)
133 {
134 left >> right;
135 }
136
137
138 /**
139 * Pipe operator.
140 *
141 * \param left object iterator
142 * \param right valve
143 * \return pipe object
144 */
145 friend inline JMultiPipe<T,0>& operator|(JObjectIterator<T>& left, const JValve<T>& right)
146 {
147 JMultiPipe<T,0>::pipe.reset(new JMultiPipe<T,0>(left, right));
148
149 return *JMultiPipe<T,0>::pipe;
150 }
151
152
153 /**
154 * Pipe operator.
155 *
156 * \param left object iterator
157 * \param right object selector
158 * \return pipe object
159 */
161 {
162 JMultiPipe<T,0>::pipe.reset(new JMultiPipe<T,0>(left, right));
163
164 return *JMultiPipe<T,0>::pipe;
165 }
166
167
168 /**
169 * Pipe operator.
170 *
171 * \param left object iterator
172 * \param right regulator
173 * \return pipe object
174 */
175 friend inline JMultiPipe<T,0>& operator|(JObjectIterator<T>& left, const JRegulator& right)
176 {
177 JMultiPipe<T,0>::pipe.reset(new JMultiPipe<T,0>(left, right));
178
179 return *JMultiPipe<T,0>::pipe;
180 }
181
182
183 /**
184 * Pipe operator.
185 *
186 * \param left object iterator
187 * \param right data type
188 * \return object multiplexer
189 */
190 template<class JBase_t>
197 };
198
199
200 /**
201 * Implementation of object iterator for multiple data types.
202 *
203 * This class recursively defines the JLANG::JObjectIterator interface
204 * for all data types by deriving from:
205 * - JObjectIterator<JHead_t>; and
206 * - JObjectIterator<JTail_t>.
207 */
208 template<class JHead_t, class JTail_t>
209 class JObjectIterator< JTypeList<JHead_t, JTail_t> > :
210 public virtual JObjectIterator<JHead_t>,
211 public virtual JObjectIterator<JTail_t>
212 {
213 public:
214
216
217 /**
218 * Copy to object output.
219 *
220 * Note that all data types of the input are copied to the output.
221 *
222 * \param in object iterator
223 * \param out object output
224 * \return object iterator
225 */
226 template<class JOutputIterator_t>
227 friend inline JObjectIterator& operator>>(JObjectIterator<typelist>& in, JOutputIterator_t& out)
228 {
229 static_cast<JObjectIterator<JHead_t>&>(in) >> static_cast<JObjectOutput<JHead_t>&>(out);
230 static_cast<JObjectIterator<JTail_t>&>(in) >> out;
231
232 return in;
233 }
234
235
236 /**
237 * Pipe terminator.
238 *
239 * \param left object iterator
240 * \param right object output
241 */
243 {
244 left >> right;
245 }
246
247
248 /**
249 * Pipe operator.
250 *
251 * \param left object iterator
252 * \param right valve
253 * \return pipe object
254 */
255 friend inline JMultiPipe<typelist,0>&
262
263
264 /**
265 * Pipe operator.
266 *
267 * \param left object iterator
268 * \param right object selector
269 * \return pipe object
270 */
271 friend inline JMultiPipe<typelist,0>&
278
279
280 /**
281 * Pipe operator.
282 *
283 * \param left object iterator
284 * \param right regulator
285 * \return pipe object
286 */
287 friend inline JMultiPipe<typelist,0>&
289 {
291
293 }
294
295
296 /**
297 * Pipe operator.
298 *
299 * \param left object iterator
300 * \param right data type
301 * \return object multiplexer
302 */
303 template<class JBase_t>
311 };
312
313
314 /**
315 * Terminator class of recursive JObjectIterator class.
316 */
317 template<class JHead_t>
319 public virtual JObjectIterator<JHead_t>
320 {};
321
322
323 /**
324 * Implementation for null iteration.
325 */
326 template<class T>
328 public virtual JObjectIterator<T>
329 {
330
332
333
334 /**
335 * Check availability of next element.
336 *
337 * \return false
338 */
339 virtual bool hasNext()
340 {
341 return false;
342 }
343
344
345 /**
346 * Get next element.
347 *
348 * \return NULL
349 */
350 virtual const pointer_type& next()
351 {
352 return ps;
353 }
354
355 private:
357 };
358
359
360 /**
361 * Interface for object iteration with rewinding.
362 */
363 template<class T>
365 public virtual JObjectIterator<T>,
366 public virtual JRewindable <T>
367 {};
368
369
370 /**
371 * Interface for object iteration with named access.
372 */
373 template<class T>
375 public virtual JObjectIterator<T>,
376 public virtual JAccessible
377 {};
378}
379
380#endif
Interface for object iteration with named access.
Interface for named access of a device.
Auxiliary class for object iteration via multiple pipes, e.g. operator:
Definition JPipe.hh:206
friend JMultiPipe< typelist, 0 > & operator|(JObjectIterator< typelist > &left, const JRegulator &right)
Pipe operator.
friend JObjectIterator & operator>>(JObjectIterator< typelist > &in, JOutputIterator_t &out)
Copy to object output.
friend JMultiPipe< typelist, 0 > & operator|(JObjectIterator< typelist > &left, const JObjectSelector< typelist > &right)
Pipe operator.
friend JMultiPipe< typelist, 0 > & operator|(JObjectIterator< typelist > &left, const JValve< typelist > &right)
Pipe operator.
friend void operator|(JObjectIterator< typelist > &left, JObjectOutput< typelist > &right)
Pipe terminator.
friend JObjectMultiplexer< typelist, JBase_t > & operator|(JObjectIterator< typelist > &left, const JType< JBase_t > &right)
Pipe operator.
Interface of object iteration for a single data type.
JObjectIterator()
Default constructor.
virtual skip_type skip(const skip_type ns)
Skip items.
friend JMultiPipe< T, 0 > & operator|(JObjectIterator< T > &left, const JValve< T > &right)
Pipe operator.
friend JObjectMultiplexer< T, JBase_t > & operator|(JObjectIterator< T > &left, const JType< JBase_t > &right)
Pipe operator.
friend JMultiPipe< T, 0 > & operator|(JObjectIterator< T > &left, const JRegulator &right)
Pipe operator.
friend JObjectIterator< T > & operator>>(JObjectIterator< T > &in, JObjectOutput< T > &out)
Copy to object output.
virtual bool hasNext()=0
Check availability of next element.
JPointer< T > pointer_type
Type definition of pointer_type.
friend void operator|(JObjectIterator< T > &left, JObjectOutput< T > &right)
Pipe terminator.
virtual const pointer_type & next()=0
Get next element.
friend JMultiPipe< T, 0 > & operator|(JObjectIterator< T > &left, const JObjectSelector< T > &right)
Pipe operator.
virtual ~JObjectIterator()
Virtual destructor.
Auxiliary class for multiplexing object iterators.
Template interface of object output for single data type.
virtual bool put(const T &object)=0
Object output.
Interface for selection of objects.
Template implementation of class that holds pointer to object(s).
Definition JPointer.hh:24
Interface for controlling object throughput.
Definition JRegulator.hh:20
Interface for object iteration with rewinding.
Template interface of rewindable object.
Auxiliary class for selection of data type.
Definition JValve.hh:23
Auxiliary classes and methods for language specific functionality.
unsigned int skip_type
Type definition for number of objects to skip.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Implementation for null iteration.
JObjectIterator< T >::pointer_type pointer_type
virtual bool hasNext()
Check availability of next element.
virtual const pointer_type & next()
Get next element.
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19