Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Public Types | Public Member Functions | Protected Attributes | Private Attributes | List of all members
JSUPPORT::JParallelFileScanner< T, JFileScanner_t > Class Template Reference

General purpose class for parallel reading of objects from a single file or multiple files. More...

#include <JParallelFileScanner.hh>

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

Public Types

typedef JFileScanner_t< JNullType >::input_type input_type
 
typedef JMultiPointer< T > multi_pointer_type
 
typedef JRewindableObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

 JParallelFileScanner ()
 Default constructor. More...
 
 JParallelFileScanner (const input_type &input)
 Constructor. More...
 
 JParallelFileScanner (const input_type &input, const JLimit &limit)
 Constructor. More...
 
virtual const multi_pointer_typenext () override
 Get next element. 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 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
 

Private Attributes

multi_pointer_type ps
 

Detailed Description

template<class T, template< class > class JFileScanner_t = JSingleFileScanner>
class JSUPPORT::JParallelFileScanner< T, JFileScanner_t >

General purpose class for parallel reading of objects from a single file or multiple files.

Definition at line 33 of file JParallelFileScanner.hh.

Member Typedef Documentation

◆ input_type

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
typedef JFileScanner_t<JNullType>::input_type JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::input_type

Definition at line 38 of file JParallelFileScanner.hh.

◆ multi_pointer_type

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
typedef JMultiPointer<T> JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::multi_pointer_type

Definition at line 39 of file JParallelFileScanner.hh.

◆ pointer_type

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

Definition at line 176 of file JSingleFileScanner.hh.

Constructor & Destructor Documentation

◆ JParallelFileScanner() [1/3]

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::JParallelFileScanner ( )
inline

Default constructor.

Definition at line 45 of file JParallelFileScanner.hh.

46  {}

◆ JParallelFileScanner() [2/3]

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::JParallelFileScanner ( const input_type input)
inline

Constructor.

Parameters
inputinput

Definition at line 54 of file JParallelFileScanner.hh.

55  {
56  this->configure(input, JLimit());
57  }
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

◆ JParallelFileScanner() [3/3]

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::JParallelFileScanner ( const input_type input,
const JLimit limit 
)
inline

Constructor.

Parameters
inputinput
limitlimit

Definition at line 66 of file JParallelFileScanner.hh.

67  {
68  this->configure(input, limit);
69  }

Member Function Documentation

◆ next()

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
virtual const multi_pointer_type& JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::next ( )
inlineoverridevirtual

Get next element.

Returns
multi-pointer to element

Reimplemented from JSUPPORT::JSingleFileScanner< T >.

Reimplemented in JSUPPORT::JTriggeredFileScanner< JTypelist_t, JFileScanner_t >, and JSUPPORT::JParallelFileScanner< JTypeList< JHead_t, JTail_t >, JFileScanner_t >.

Definition at line 77 of file JParallelFileScanner.hh.

78  {
79  ps.set(JFileScanner_t<T>::next());
80 
81  return ps;
82  }
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75

◆ getCounter()

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

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 ( )
inlineoverridevirtualinherited

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 ( )
inlineoverridevirtualinherited

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.

◆ skip() [1/2]

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

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

◆ ps

template<class T , template< class > class JFileScanner_t = JSingleFileScanner>
multi_pointer_type JSUPPORT::JParallelFileScanner< T, JFileScanner_t >::ps
private

Definition at line 85 of file JParallelFileScanner.hh.

◆ scanner

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

Definition at line 328 of file JSingleFileScanner.hh.

◆ counter

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

Definition at line 329 of file JSingleFileScanner.hh.


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