Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JSUPPORT::JSingleFileScanner< T > Class Template Reference

Object reading from a list of files. More...

#include <JSingleFileScanner.hh>

Inheritance diagram for JSUPPORT::JSingleFileScanner< T >:
JLANG::JRewindableObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JRewindable< T > JSUPPORT::JParallelFileScanner< T, JFileScanner_t >

Public Types

typedef JSingleFileScanner ::input_type input_type
 
typedef JRewindableObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

 JSingleFileScanner ()
 Default constructor.
 
template<class JTypelist_t >
 JSingleFileScanner (const JSingleFileScanner< JTypelist_t > &input)
 Copy constructor.
 
 JSingleFileScanner (const input_type &file_name)
 Constructor.
 
 JSingleFileScanner (const input_type &file_name, const JLimit &limit)
 Constructor.
 
counter_type getCounter () const
 Get counter.
 
virtual void rewind () override
 Rewind.
 
virtual bool hasNext () override
 Check availability of next element.
 
virtual const pointer_typenext () override
 Get next element.
 
virtual skip_type skip (const skip_type ns) override
 Skip items.
 

Protected Attributes

JFileScanner< T > scanner
 
counter_type counter
 

Detailed Description

template<class T>
class JSUPPORT::JSingleFileScanner< T >

Object reading from a list of files.

Object reading from a single file name.

This class implements the JLANG::JRewindableObjectIterator interface.

Definition at line 171 of file JSingleFileScanner.hh.

Member Typedef Documentation

◆ input_type

◆ pointer_type

template<class T >
JRewindableObjectIterator<T>::pointer_type JSUPPORT::JSingleFileScanner< T >::pointer_type

Definition at line 178 of file JSingleFileScanner.hh.

Constructor & Destructor Documentation

◆ JSingleFileScanner() [1/4]

template<class T >
JSUPPORT::JSingleFileScanner< T >::JSingleFileScanner ( )
inline

Default constructor.

Definition at line 183 of file JSingleFileScanner.hh.

183 :
184 counter(0)
185 {}

◆ JSingleFileScanner() [2/4]

template<class T >
template<class JTypelist_t >
JSUPPORT::JSingleFileScanner< T >::JSingleFileScanner ( const JSingleFileScanner< JTypelist_t > & input)
inline

Copy constructor.

Note that the counter limit is not copied and the counter is set to zero.

Parameters
inputinput

Definition at line 196 of file JSingleFileScanner.hh.

196 :
197 counter(0)
198 {
199 this->configure(input.getFilename(), JLimit());
200 }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, std::false_type option)
Configuration of value.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45

◆ JSingleFileScanner() [3/4]

template<class T >
JSUPPORT::JSingleFileScanner< T >::JSingleFileScanner ( const input_type & file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 208 of file JSingleFileScanner.hh.

208 :
209 counter(0)
210 {
211 this->configure(file_name, JLimit());
212 }

◆ JSingleFileScanner() [4/4]

template<class T >
JSUPPORT::JSingleFileScanner< T >::JSingleFileScanner ( const input_type & file_name,
const JLimit & limit )
inline

Constructor.

Parameters
file_namefile name
limitlimit

Definition at line 221 of file JSingleFileScanner.hh.

221 :
222 counter(0)
223 {
224 this->configure(file_name, limit);
225 }

Member Function Documentation

◆ getCounter()

template<class T >
counter_type JSUPPORT::JSingleFileScanner< T >::getCounter ( ) const
inline

Get counter.

Returns
counter

Definition at line 233 of file JSingleFileScanner.hh.

234 {
235 return counter;
236 }

◆ rewind()

template<class T >
virtual void JSUPPORT::JSingleFileScanner< T >::rewind ( )
inlineoverridevirtual

Rewind.

Implements JLANG::JRewindable< T >.

Reimplemented in JSUPPORT::JSingleFileScanner< JTypeList< JHead_t, JTail_t > >.

Definition at line 242 of file JSingleFileScanner.hh.

243 {
244 if (scanner.is_open()) {
245 scanner.close();
246 }
247
248 counter = 0;
249
250 scanner.reset();
251 }

◆ hasNext()

template<class T >
virtual bool JSUPPORT::JSingleFileScanner< T >::hasNext ( )
inlineoverridevirtual

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 259 of file JSingleFileScanner.hh.

260 {
261 if (is_valid()) {
262
263 if (counter < getUpperLimit()) {
264
265 // first time around
266
267 if (!scanner.is_open()) {
268 scanner.open(this->getFilename().c_str());
269 }
270
271 if (counter < getLowerLimit()) {
272 counter += scanner.skip(getLowerLimit() - counter);
273 }
274
275 if (!scanner.hasNext()) {
276
277 scanner.close();
278
279 return false;
280 }
281
282 return true;
283
284 } else {
285
286 // last time around
287
288 if (scanner.is_open()) {
289 scanner.close();
290 }
291
292 scanner.reset();
293 }
294 }
295
296 return false;
297 }
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
bool is_valid(const json &js)
Check validity of JSon data.

◆ next()

template<class T >
virtual const pointer_type & JSUPPORT::JSingleFileScanner< T >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Reimplemented in JSUPPORT::JParallelFileScanner< T, JFileScanner_t >.

Definition at line 305 of file JSingleFileScanner.hh.

306 {
307 ++counter;
308
309 return scanner.next();
310 }

◆ skip()

template<class T >
virtual skip_type JSUPPORT::JSingleFileScanner< T >::skip ( const skip_type ns)
inlineoverridevirtual

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented from JLANG::JObjectIterator< T >.

Reimplemented in JSUPPORT::JSingleFileScanner< JTypeList< JHead_t, JTail_t > >.

Definition at line 319 of file JSingleFileScanner.hh.

320 {
321 const skip_type previous = counter;
322
323 counter += scanner.skip(ns);
324
325 return counter - previous;
326 }
unsigned int skip_type
Type definition for number of objects to skip.

Member Data Documentation

◆ scanner

template<class T >
JFileScanner<T> JSUPPORT::JSingleFileScanner< T >::scanner
protected

Definition at line 330 of file JSingleFileScanner.hh.

◆ counter

template<class T >
counter_type JSUPPORT::JSingleFileScanner< T >::counter
protected

Definition at line 331 of file JSingleFileScanner.hh.


The documentation for this class was generated from the following file: