Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAbstractObjectReader.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JABSTRACTOBJECTREADER__
2 #define __JLANG__JABSTRACTOBJECTREADER__
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 interface for object reading.
18  *
19  * This class implements the JObjectIterator interface by transferring
20  * the interface methods to a helper object via a single interface method getHelper().
21  */
22  template<class T>
24  public virtual JObjectIterator<T>
25  {
26 
28 
29 
30  /**
31  * Get helper.
32  *
33  * \return pointer to helper
34  */
35  virtual JObjectIterator<T>* getHelper() const = 0;
36 
37 
38  /**
39  * Check availability of next element.
40  *
41  * \return true if the iteration has more elements; else false
42  */
43  virtual bool hasNext() override
44  {
45  return (this->getHelper() != NULL && this->getHelper()->hasNext());
46  }
47 
48 
49  /**
50  * Get next element.
51  *
52  * \return pointer to element
53  */
54  virtual const pointer_type& next() override
55  {
56  if (this->getHelper() != NULL)
57  return this->getHelper()->next();
58  else
59  return ps;
60  }
61 
62 
63  /**
64  * Skip items.
65  *
66  * \param ns number of items to skip
67  * \return number of items skipped
68  */
69  virtual skip_type skip(const skip_type ns) override
70  {
71  if (this->getHelper() != NULL)
72  return this->getHelper()->skip(ns);
73  else
74  return 0;
75  }
76 
77  private:
79  };
80 
81 
82  /**
83  * Abstract interface for object reading with rewinding.
84  *
85  * This class implements the JRewindableObjectIterator interface by transferring
86  * the interface methods to a helper object via a single interface method getHelper().
87  */
88  template<class T>
90  public virtual JRewindableObjectIterator<T>,
91  public JAbstractObjectReader <T>
92  {
93  /**
94  * Get helper.
95  *
96  * \return pointer to helper
97  */
98  virtual JRewindableObjectIterator<T>* getHelper() const = 0;
99 
100 
101  /**
102  * Rewind.
103  */
104  virtual void rewind() override
105  {
106  if (this->getHelper() != NULL) {
107  this->getHelper()->rewind();
108  }
109  }
110  };
111 
112 
113  /**
114  * Abstract interface for object reading with named access.
115  *
116  * This class implements the JAccessibleObjectIterator interface by transferring
117  * the interface methods to a helper object via a single interface method getHelper().
118  */
119  template<class T>
121  public virtual JAccessibleObjectIterator<T>,
122  public JAbstractObjectReader <T>
123  {
124  /**
125  * Get helper.
126  *
127  * \return pointer to helper
128  */
129  virtual JAccessibleObjectIterator<T>* getHelper() const = 0;
130 
131 
132  /**
133  * Check is device is open.
134  *
135  * \return true if open; else false
136  */
137  virtual bool is_open() const override
138  {
139  if (this->getHelper() != NULL)
140  return this->getHelper()->is_open();
141  else
142  return false;
143  }
144 
145 
146  /**
147  * Open device.
148  *
149  * \param file_name file name
150  */
151  virtual void open(const char* file_name) override
152  {
153  if (this->getHelper() != NULL) {
154  this->getHelper()->open(file_name);
155  }
156  }
157 
158 
159  /**
160  * Close device.
161  */
162  virtual void close() override
163  {
164  if (this->getHelper() != NULL) {
165  this->getHelper()->close();
166  }
167  }
168  };
169 }
170 
171 #endif
Interface for object iteration with rewinding.
virtual void rewind() override
Rewind.
unsigned int skip_type
Type definition for number of objects to skip.
Interface of object iteration for a single data type.
virtual bool hasNext() override
Check availability of next element.
virtual JObjectIterator< T > * getHelper() const =0
Get helper.
Abstract interface for object reading.
JObjectIterator< T >::pointer_type pointer_type
virtual bool is_open() const override
Check is device is open.
virtual void open(const char *file_name) override
Open device.
virtual skip_type skip(const skip_type ns) override
Skip items.
virtual JAccessibleObjectIterator< T > * getHelper() const =0
Get helper.
Interface for object iteration with named access.
virtual void close() override
Close device.
virtual const pointer_type & next() override
Get next element.
Abstract interface for object reading with rewinding.
virtual JRewindableObjectIterator< T > * getHelper() const =0
Get helper.
Abstract interface for object reading with named access.