Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Public Types | Public Member Functions | Protected Attributes | List of all members
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. More...
 
template<class JTypelist_t >
 JSingleFileScanner (const JSingleFileScanner< JTypelist_t > &input)
 Copy constructor. More...
 
 JSingleFileScanner (const input_type &file_name)
 Constructor. More...
 
 JSingleFileScanner (const input_type &file_name, const JLimit &limit)
 Constructor. More...
 
counter_type getCounter () const
 Get counter. More...
 
virtual void rewind () override
 Rewind. More...
 
virtual bool hasNext () override
 Check availability of next element. More...
 
virtual const pointer_typenext () override
 Get next element. More...
 
virtual skip_type skip (const skip_type ns) override
 Skip items. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

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

Member Typedef Documentation

◆ input_type

Definition at line 175 of file JSingleFileScanner.hh.

◆ pointer_type

Definition at line 176 of file JSingleFileScanner.hh.

Constructor & Destructor Documentation

◆ JSingleFileScanner() [1/4]

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

Default constructor.

Definition at line 181 of file JSingleFileScanner.hh.

181  :
182  counter(0)
183  {}

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

194  :
195  counter(0)
196  {
197  this->configure(input.getFilename(), JLimit());
198  }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > 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 206 of file JSingleFileScanner.hh.

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

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

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

Member Function Documentation

◆ getCounter()

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

Get counter.

Returns
counter

Definition at line 231 of file JSingleFileScanner.hh.

232  {
233  return counter;
234  }

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

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

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

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

304  {
305  ++counter;
306 
307  return scanner.next();
308  }

◆ skip() [1/2]

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 in JSUPPORT::JSingleFileScanner< JTypeList< JHead_t, JTail_t > >.

Definition at line 317 of file JSingleFileScanner.hh.

318  {
319  const skip_type previous = counter;
320 
321  counter += scanner.skip(ns);
322 
323  return counter - previous;
324  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns

◆ skip() [2/2]

template<class T >
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JLANG::JSTDObjectIterator< T >, JLANG::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, and JLANG::JAbstractObjectReader< T >.

Definition at line 90 of file JObjectIterator.hh.

91  {
92  skip_type i = 0;
93 
94  for ( ; i != ns && hasNext(); ++i) {
95  next();
96  }
97 
98  return i;
99  }
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.

Member Data Documentation

◆ scanner

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

Definition at line 328 of file JSingleFileScanner.hh.

◆ counter

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

Definition at line 329 of file JSingleFileScanner.hh.


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