Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JAbstractObjectIterator.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JABSTRACTOBJECTITERATOR__
2 #define __JLANG__JABSTRACTOBJECTITERATOR__
3 
5 
6 
7 /**
8  * \author mdejong
9  */
10 
11 namespace JLANG {}
12 namespace JPP { using namespace JLANG; }
13 
14 namespace JLANG {
15 
16  /**
17  * Abstract object iterator.
18  *
19  * This class implements the JObjectIterator interface via a single interface method setObject().\n
20  * An internal object is used for which the default constructor should exist.
21  */
22  template<class T>
24  public virtual JObjectIterator<T>
25  {
26  protected:
27  /**
28  * Default constructor.
29  */
31  has_next(false)
32  {}
33 
34  T object; //!< object
35  bool has_next; //!< status
36 
37  public:
38 
40 
41 
42  /**
43  * Set object.
44  *
45  * \param object reference to object to be set
46  * \return true if set; else false
47  */
48  virtual bool setObject(T& object) = 0;
49 
50 
51  /**
52  * Check availability of next element.
53  *
54  * \return true if the iteration has more elements; else false
55  */
56  virtual bool hasNext() override
57  {
58  if (!has_next) {
59  has_next = this->setObject(object);
60  }
61 
62  return has_next;
63  }
64 
65 
66  /**
67  * Get next element.
68  *
69  * \return pointer to element
70  */
71  virtual const pointer_type& next() override
72  {
73  if (has_next)
74  ps.reset(&this->object);
75  else
76  ps.reset(NULL);
77 
78  has_next = false;
79 
80  return ps;
81  }
82 
83  private:
85  };
86 
87 
88  /**
89  * Abstract object iterator with rewinding.
90  */
91  template<class T>
93  public JRewindableObjectIterator<T>,
94  public JAbstractObjectIterator<T>
95  {};
96 
97 
98  /**
99  * Abstract object iterator with named access.
100  */
101  template<class T>
103  public JAccessibleObjectIterator<T>,
104  public JAbstractObjectIterator<T>
105  {};
106 }
107 
108 #endif
virtual const pointer_type & next() override
Get next element.
JAbstractObjectIterator()
Default constructor.
JObjectIterator< T >::pointer_type pointer_type
virtual bool setObject(T &object)=0
Set object.
virtual bool hasNext() override
Check availability of next element.
Abstract object iterator with named access.
Interface for object iteration with named access.
Interface of object iteration for a single data type.
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
Abstract object iterator with rewinding.
Interface for object iteration with rewinding.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).