Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JParallelFileScanner.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JPARALLELFILESCANNER__
2 #define __JSUPPORT__JPARALLELFILESCANNER__
3 
4 #include "JLang/JTypeList.hh"
5 #include "JLang/JNullType.hh"
6 #include "JLang/JMultiPointer.hh"
7 #include "JLang/JException.hh"
8 
11 
12 
13 /**
14  * \file
15  * Parallel scanning of objects from a single file or multiple files according a format that follows from the file name extension.
16  * \author mdejong
17  */
18 namespace JSUPPORT {}
19 namespace JPP { using namespace JSUPPORT; }
20 
21 namespace JSUPPORT {
22 
23  using JLANG::JTypeList;
24  using JLANG::JNullType;
26  using JLANG::JException;
27 
28 
29  /**
30  * General purpose class for parallel reading of objects from a single file or multiple files.
31  */
32  template<class T, template<class> class JFileScanner_t = JSingleFileScanner>
34  public JFileScanner_t<T>
35  {
36  public:
37 
38  typedef typename JFileScanner_t<JNullType>::input_type input_type;
40 
41 
42  /**
43  * Default constructor.
44  */
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param input input
53  */
55  {
56  this->configure(input, JLimit());
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param input input
64  * \param limit limit
65  */
66  JParallelFileScanner(const input_type& input, const JLimit& limit)
67  {
68  this->configure(input, limit);
69  }
70 
71 
72  /**
73  * Get next element.
74  *
75  * \return multi-pointer to element
76  */
77  virtual const multi_pointer_type& next() override
78  {
79  ps.set(JFileScanner_t<T>::next());
80 
81  return ps;
82  }
83 
84  private:
86  };
87 
88 
89  /**
90  * Template specialisation of JParallelFileScanner for multiple data types.
91  */
92  template<class JHead_t, class JTail_t, template<class> class JFileScanner_t>
93  class JParallelFileScanner<JTypeList<JHead_t, JTail_t>, JFileScanner_t> :
94  public JParallelFileScanner<JHead_t, JFileScanner_t>,
95  public JParallelFileScanner<JTail_t, JFileScanner_t>
96  {
97  public:
98 
99  typedef typename JFileScanner_t<JNullType>::input_type input_type;
101 
104 
105 
106  /**
107  * Default constructor.
108  */
110  {}
111 
112 
113  /**
114  * Constructor.
115  *
116  * \param input input
117  */
119  {
120  this->configure(input, JLimit());
121  }
122 
123 
124  /**
125  * Constructor.
126  *
127  * \param input input
128  * \param limit limit
129  */
130  JParallelFileScanner(const input_type& input, const JLimit& limit)
131  {
132  this->configure(input, limit);
133  }
134 
135 
136  /**
137  * Rewind.\n
138  * This method rewinds the JParallelFileScanner for each data type.
139  */
140  virtual void rewind() override
141  {
144  }
145 
146 
147  /**
148  * Check availability of next element.\n
149  * Note that the availability of the next element is tested for each data type.
150  *
151  * \return true if each iteration has more elements; else false
152  */
153  virtual bool hasNext() override
154  {
157  }
158 
159 
160  /**
161  * Get next element.
162  *
163  * \return multi-pointer to elements
164  */
165  virtual const multi_pointer_type& next() override
166  {
169 
170  return ps;
171  }
172 
173 
174  /**
175  * Skip items.
176  *
177  * \param ns number of items to skip
178  * \return number of items skipped
179  */
180  virtual skip_type skip(const skip_type ns) override
181  {
184 
185  if (n1 == n2)
186  return n1;
187  else
188  THROW(JException, "JParallelFileScanner<>::skip(): inconsistency.");
189  }
190 
191  private:
193  };
194 
195 
196  /**
197  * Terminator class of recursive JParallelFileScanner class.
198  */
199  template<class JHead_t, template<class> class JFileScanner_t>
200  class JParallelFileScanner<JTypeList<JHead_t, JNullType>, JFileScanner_t> :
201  public JParallelFileScanner<JHead_t, JFileScanner_t>
202  {
203  public:
204 
207 
208 
209  /**
210  * Default constructor.
211  */
213  JParallelFileScanner<JHead_t, JFileScanner_t>()
214  {}
215 
216 
217  /**
218  * Constructor.
219  *
220  * \param input input
221  */
223  {
224  this->configure(input, JLimit());
225  }
226 
227 
228  /**
229  * Constructor.
230  *
231  * \param input input
232  * \param limit limit
233  */
234  JParallelFileScanner(const input_type& input, const JLimit& limit)
235  {
236  this->configure(input, limit);
237  }
238  };
239 }
240 
241 #endif
General exception.
Definition: JException.hh:23
Exceptions.
virtual const multi_pointer_type & next() override
Get next element.
void reset(const JMultiPointer< JClass_t > &pointer)
Reset multi-pointer.
unsigned int skip_type
Type definition for number of objects to skip.
JParallelFileScanner(const input_type &input)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
General purpose class for parallel reading of objects from a single file or multiple files...
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
Type list.
Definition: JTypeList.hh:22
Scanning of objects from a single file according a format that follows from the extension of each fil...
std::ostream & rewind(std::ostream &out)
Rewind character.
Definition: JManip.hh:221
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Implementation of multiple pointers for multiple data types.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
virtual bool hasNext() override
Check availability of next element.
JParallelFileScanner< JHead_t, JFileScanner_t >::input_type input_type
virtual const multi_pointer_type & next() override
Get next element.
virtual skip_type skip(const skip_type ns) override
Skip items.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
JParallelFileScanner()
Default constructor.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
JParallelFileScanner< JHead_t, JFileScanner_t >::multi_pointer_type multi_pointer_type
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
Object reading from a list of files.
JFileScanner_t< JNullType >::input_type input_type
General purpose class for multiple pointers.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75