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