Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSTDObjectIterator.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JSTDOBJECTITERATOR__
2 #define __JLANG__JSTDOBJECTITERATOR__
3 
4 #include <iterator>
5 #include <algorithm>
6 
8 #include "JLang/JClass.hh"
9 #include "JLang/JCategory.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JLANG {}
17 namespace JPP { using namespace JLANG; }
18 
19 namespace JLANG {
20 
21  /**
22  * Implementation of object iteration from STD container.
23  */
24  template<class T>
26  public JRewindableObjectIterator<typename JCategory<typename T::value_type,
27  JClass<typename T::reference>::is_constant>::value_type>
28  {
29  typedef typename JCategory<typename T::value_type,
32 
33  /**
34  * Default constructor.
35  */
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param begin begin of data
44  * \param end end of data
45  */
47  T end) :
48  __begin(begin),
49  __end (end),
50  __i (begin)
51  {}
52 
53 
54  /**
55  * Rewind.
56  */
57  virtual void rewind() override
58  {
59  __i = __begin;
60  }
61 
62 
63  /**
64  * Check availability of next element.
65  *
66  * \return true if the iteration has more elements; else false
67  */
68  virtual bool hasNext() override
69  {
70  return __i != __end;
71  }
72 
73 
74  /**
75  * Get next element.
76  *
77  * \return pointer to element
78  */
79  virtual const pointer_type& next() override
80  {
81  if (hasNext())
82  ps.reset(&(*__i++));
83  else
84  ps.reset(NULL);
85 
86  return ps;
87  }
88 
89 
90  /**
91  * Skip items.
92  *
93  * \param ns number of items to skip
94  * \return number of items skipped
95  */
96  virtual skip_type skip(const skip_type ns) override
97  {
98  using namespace std;
99 
100  skip_type i = min(ns, (skip_type) distance(__i, __end));
101 
102  advance(__i, i);
103 
104  return i;
105  }
106 
107  protected:
111  private:
113  };
114 }
115 
116 #endif
Interface for object iteration with rewinding.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
unsigned int skip_type
Type definition for number of objects to skip.
virtual bool hasNext() override
Check availability of next element.
JSTDObjectIterator()
Default constructor.
virtual skip_type skip(const skip_type ns) override
Skip items.
virtual void rewind() override
Rewind.
Implementation of object iteration from STD container.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
JSTDObjectIterator(T begin, T end)
Constructor.
virtual const pointer_type & next() override
Get next element.
Template for generic class types.
Definition: JClass.hh:80
JRewindableObjectIterator< value_type >::pointer_type pointer_type
JCategory< typename T::value_type, JClass< typename T::reference >::is_constant >::value_type value_type
Auxiliary class to define value, reference and pointer types for given data type and category...
Definition: JCategory.hh:18