Jpp  16.0.3
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::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 >

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< Tscanner
 
counter_type counter
 

Detailed Description

template<class T = JNullType>
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 75 of file JSingleFileScanner.hh.

Member Typedef Documentation

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

Definition at line 164 of file JSingleFileScanner.hh.

Definition at line 165 of file JSingleFileScanner.hh.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 170 of file JSingleFileScanner.hh.

170  :
171  counter(0)
172  {}
template<class T = JNullType>
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 183 of file JSingleFileScanner.hh.

183  :
184  counter(0)
185  {
186  this->configure(input.getFilename(), JLimit());
187  }
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::JSingleFileScanner< T >::JSingleFileScanner ( const input_type file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 195 of file JSingleFileScanner.hh.

195  :
196  counter(0)
197  {
198  this->configure(file_name, JLimit());
199  }
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::JSingleFileScanner< T >::JSingleFileScanner ( const input_type file_name,
const JLimit limit 
)
inline

Constructor.

Parameters
file_namefile name
limitlimit

Definition at line 208 of file JSingleFileScanner.hh.

208  :
209  counter(0)
210  {
211  this->configure(file_name, limit);
212  }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.

Member Function Documentation

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

Get counter.

Returns
counter

Definition at line 220 of file JSingleFileScanner.hh.

221  {
222  return counter;
223  }
template<class T = JNullType>
virtual void JSUPPORT::JSingleFileScanner< T >::rewind ( )
inlineoverridevirtual

Rewind.

Implements JLANG::JRewindable< T >.

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

Definition at line 229 of file JSingleFileScanner.hh.

230  {
231  if (scanner.is_open()) {
232  scanner.close();
233  }
234 
235  counter = 0;
236 
237  scanner.reset();
238  }
template<class T = JNullType>
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 246 of file JSingleFileScanner.hh.

247  {
248  if (is_valid()) {
249 
250  if (counter < getUpperLimit()) {
251 
252  // first time around
253 
254  if (!scanner.is_open()) {
255  scanner.open(this->getFilename().c_str());
256  }
257 
258  if (counter < getLowerLimit()) {
259  counter += scanner.skip(getLowerLimit() - counter);
260  }
261 
262  if (!scanner.hasNext()) {
263 
264  scanner.close();
265 
266  return false;
267  }
268 
269  return true;
270 
271  } else {
272 
273  // last time around
274 
275  if (scanner.is_open()) {
276  scanner.close();
277  }
278 
279  scanner.reset();
280  }
281  }
282 
283  return false;
284  }
bool is_valid(const json &js)
Check validity of JSon data.
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:88
template<class T = JNullType>
virtual const pointer_type& JSUPPORT::JSingleFileScanner< T >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 292 of file JSingleFileScanner.hh.

293  {
294  ++counter;
295 
296  return scanner.next();
297  }
template<class T = JNullType>
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 306 of file JSingleFileScanner.hh.

307  {
308  const skip_type previous = counter;
309 
310  counter += scanner.skip(ns);
311 
312  return counter - previous;
313  }
unsigned int skip_type
Type definition for number of objects to skip.
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::JSingleFileScanner< T >::scanner
protected

Definition at line 317 of file JSingleFileScanner.hh.

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

Definition at line 318 of file JSingleFileScanner.hh.


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