Jpp 21.0.0-rc.1-88-g0130508c4
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 179 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 186 of file JSingleFileScanner.hh.

Constructor & Destructor Documentation

◆ JSingleFileScanner() [1/4]

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

Default constructor.

Definition at line 191 of file JSingleFileScanner.hh.

191 :
192 counter(0)
193 {}

◆ 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 204 of file JSingleFileScanner.hh.

204 :
205 counter(0)
206 {
207 this->configure(input.getFilename(), JLimit());
208 }
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 216 of file JSingleFileScanner.hh.

216 :
217 counter(0)
218 {
219 this->configure(file_name, JLimit());
220 }

◆ 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 229 of file JSingleFileScanner.hh.

229 :
230 counter(0)
231 {
232 this->configure(file_name, limit);
233 }

Member Function Documentation

◆ getCounter()

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

Get counter.

Returns
counter

Definition at line 241 of file JSingleFileScanner.hh.

242 {
243 return counter;
244 }

◆ 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 250 of file JSingleFileScanner.hh.

251 {
252 if (scanner.is_open()) {
253 scanner.close();
254 }
255
256 counter = 0;
257
258 scanner.reset();
259 }

◆ 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 267 of file JSingleFileScanner.hh.

268 {
269 if (is_valid()) {
270
271 if (counter < getUpperLimit()) {
272
273 // first time around
274
275 if (!scanner.is_open()) {
276 scanner.open(this->getFilename().c_str());
277 }
278
279 if (counter < getLowerLimit()) {
280 counter += scanner.skip(getLowerLimit() - counter);
281 }
282
283 if (!scanner.hasNext()) {
284
285 scanner.close();
286
287 return false;
288 }
289
290 return true;
291
292 } else {
293
294 // last time around
295
296 if (scanner.is_open()) {
297 scanner.close();
298 }
299
300 scanner.reset();
301 }
302 }
303
304 return false;
305 }
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 313 of file JSingleFileScanner.hh.

314 {
315 ++counter;
316
317 return scanner.next();
318 }

◆ 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 327 of file JSingleFileScanner.hh.

328 {
329 const skip_type previous = counter;
330
331 counter += scanner.skip(ns);
332
333 return counter - previous;
334 }
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 338 of file JSingleFileScanner.hh.

◆ counter

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

Definition at line 339 of file JSingleFileScanner.hh.


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