Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
JSUPPORT::JMultipleFileScanner< T > Class Template Reference

General purpose class for object reading from a list of file names. More...

#include <JMultipleFileScanner.hh>

Inheritance diagram for JSUPPORT::JMultipleFileScanner< T >:
JLANG::JRewindableObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JRewindable< T >

Public Types

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

Public Member Functions

 JMultipleFileScanner ()
 Default constructor. More...
 
template<class JTypelist_t >
 JMultipleFileScanner (const JMultipleFileScanner< JTypelist_t > &input)
 Copy constructor. More...
 
 JMultipleFileScanner (const input_type &file_list)
 Constructor. More...
 
 JMultipleFileScanner (const input_type &file_list, const JLimit &limit)
 Constructor. More...
 
const std::string & getFilename () const
 Get current file name. 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< Tscanner
 
unsigned int index
 
counter_type counter
 

Detailed Description

template<class T = JNullType>
class JSUPPORT::JMultipleFileScanner< T >

General purpose class for object reading from a list of file names.

Implementation of object reading for single data type from a list of file names.

This class extends the JMultipleFileScanner<JNullType> class and implements the JLANG::JRewindableObjectIterator interface.
When the method hasNext() is called, the next file in the list is opened when the previous file is exhausted.

Definition at line 199 of file JMultipleFileScanner.hh.

Member Typedef Documentation

template<class T = JNullType>
typedef JMultipleFileScanner ::input_type JSUPPORT::JMultipleFileScanner< T >::input_type

Definition at line 295 of file JMultipleFileScanner.hh.

Definition at line 296 of file JMultipleFileScanner.hh.

Constructor & Destructor Documentation

template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( )
inline

Default constructor.

Definition at line 301 of file JMultipleFileScanner.hh.

301  :
302  index (0),
303  counter(0)
304  {}
template<class T = JNullType>
template<class JTypelist_t >
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const JMultipleFileScanner< JTypelist_t > &  input)
inline

Copy constructor.

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

Parameters
inputinput

Definition at line 315 of file JMultipleFileScanner.hh.

315  :
316  index (0),
317  counter(0)
318  {
319  this->configure(input.getFilelist(), JLimit());
320  }
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const input_type file_list)
inline

Constructor.

Parameters
file_listlist of file names

Definition at line 328 of file JMultipleFileScanner.hh.

328  :
329  index (0),
330  counter(0)
331  {
332  configure(file_list, JLimit());
333  }
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
template<class T = JNullType>
JSUPPORT::JMultipleFileScanner< T >::JMultipleFileScanner ( const input_type file_list,
const JLimit limit 
)
inline

Constructor.

Parameters
file_listlist of file names
limitlimit

Definition at line 342 of file JMultipleFileScanner.hh.

342  :
343  index (0),
344  counter(0)
345  {
346  configure(file_list, limit);
347  }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.

Member Function Documentation

template<class T = JNullType>
const std::string& JSUPPORT::JMultipleFileScanner< T >::getFilename ( ) const
inline

Get current file name.

Note that this method should only be called when method hasNext() returns true.

Returns
file name

Definition at line 357 of file JMultipleFileScanner.hh.

358  {
359  return this->at(index);
360  }
template<class T = JNullType>
counter_type JSUPPORT::JMultipleFileScanner< T >::getCounter ( ) const
inline

Get counter.

Returns
counter

Definition at line 368 of file JMultipleFileScanner.hh.

369  {
370  return counter;
371  }
template<class T = JNullType>
virtual void JSUPPORT::JMultipleFileScanner< T >::rewind ( )
inlineoverridevirtual

Rewind.

Implements JLANG::JRewindable< T >.

Reimplemented in JSUPPORT::JMultipleFileScanner< JTypeList< JHead_t, JTail_t > >, JSUPPORT::JMultipleFileScanner< Head >, and JSUPPORT::JMultipleFileScanner< JTriggerParameters >.

Definition at line 377 of file JMultipleFileScanner.hh.

378  {
379  if (scanner.is_open()) {
380  scanner.close();
381  }
382 
383  index = 0;
384  counter = 0;
385 
386  scanner.reset();
387  }
template<class T = JNullType>
virtual bool JSUPPORT::JMultipleFileScanner< 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 395 of file JMultipleFileScanner.hh.

396  {
397  if (is_valid()) {
398 
399  if (counter < getUpperLimit() && index != this->size()) {
400 
401  // first time around
402 
403  if (!scanner.is_open()) {
404  scanner.open(getFilename().c_str());
405  }
406 
407  if (counter < getLowerLimit()) {
408  counter += scanner.skip(getLowerLimit() - counter);
409  }
410 
411  if (!scanner.hasNext()) {
412 
413  scanner.close();
414 
415  ++index;
416 
417  return hasNext();
418  }
419 
420  return true;
421 
422  } else {
423 
424  // last time around
425 
426  if (scanner.is_open()) {
427  scanner.close();
428  }
429 
430  scanner.reset();
431  }
432  }
433 
434  return false;
435  }
virtual bool hasNext() override
Check availability of next element.
bool is_valid(const json &js)
Check validity of JSon data.
const std::string & getFilename() const
Get current file name.
template<class T = JNullType>
virtual const pointer_type& JSUPPORT::JMultipleFileScanner< T >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 443 of file JMultipleFileScanner.hh.

444  {
445  ++counter;
446 
447  return scanner.next();
448  }
template<class T = JNullType>
virtual skip_type JSUPPORT::JMultipleFileScanner< T >::skip ( const skip_type  ns)
inlineoverridevirtual

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

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

Definition at line 457 of file JMultipleFileScanner.hh.

458  {
459  skip_type i = 0;
460 
461  while (this->hasNext() && i != ns) {
462  i += scanner.skip(ns - i);
463  }
464 
465  counter += i;
466 
467  return i;
468  }
unsigned int skip_type
Type definition for number of objects to skip.
virtual bool hasNext() override
Check availability of next element.
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::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, JLANG::JSTDObjectIterator< T >, JLANG::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, and JLANG::JAbstractObjectReader< JDAQSummaryslice >.

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  }
unsigned int skip_type
Type definition for number of objects to skip.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.

Member Data Documentation

template<class T = JNullType>
JFileScanner<T> JSUPPORT::JMultipleFileScanner< T >::scanner
protected

Definition at line 472 of file JMultipleFileScanner.hh.

template<class T = JNullType>
unsigned int JSUPPORT::JMultipleFileScanner< T >::index
protected

Definition at line 473 of file JMultipleFileScanner.hh.

template<class T = JNullType>
counter_type JSUPPORT::JMultipleFileScanner< T >::counter
protected

Definition at line 474 of file JMultipleFileScanner.hh.


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