Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JGZFileReader< T > Class Template Reference

Object reading from gzipped file. More...

#include <JGZFileReader.hh>

Inheritance diagram for JLANG::JGZFileReader< T >:
igzstream JLANG::JStreamObjectIterator< T > JLANG::JAccessibleObjectIterator< T > gzstreambase JLANG::JAbstractObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JObjectIterator< T > JLANG::JThrow< JAccessible >

Public Types

typedef JObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

 JGZFileReader ()
 Default constructor.
 
 JGZFileReader (const char *file_name)
 Constructor.
 
virtual bool is_open () const override
 Check is file is open.
 
virtual void open (const char *file_name) override
 Open file.
 
virtual void close () override
 Close file.
 
void open (const char *name, int open_mode=std::ios::in)
 
gzstreambufrdbuf ()
 
virtual bool setObject (T &object) override
 Set object.
 
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)
 Skip items.
 

Static Public Member Functions

static void Throw (const bool option)
 Enable/disable throw option.
 
static int Throw (const JException_t &error, const int value=-1)
 Throw exception or return error.
 

Protected Attributes

gzstreambuf buf
 
std::istream & __in
 
object
 object
 
bool has_next
 status
 

Static Protected Attributes

static bool do_throw
 throw option
 

Private Attributes

pointer_type ps
 

Detailed Description

template<class T>
class JLANG::JGZFileReader< T >

Object reading from gzipped file.

This class implements the JAccessibleObjectIterator interface.

Definition at line 28 of file JGZFileReader.hh.

Member Typedef Documentation

◆ pointer_type

template<class T >
JObjectIterator<T>::pointer_type JLANG::JAbstractObjectIterator< T >::pointer_type
inherited

Definition at line 39 of file JAbstractObjectIterator.hh.

Constructor & Destructor Documentation

◆ JGZFileReader() [1/2]

template<class T >
JLANG::JGZFileReader< T >::JGZFileReader ( )
inline

Default constructor.

Definition at line 37 of file JGZFileReader.hh.

37 :
38 igzstream(),
39 JStreamObjectIterator<T>(static_cast<std::istream&>(*this))
40 {}
JStreamObjectIterator(std::istream &in)
Constructor.

◆ JGZFileReader() [2/2]

template<class T >
JLANG::JGZFileReader< T >::JGZFileReader ( const char * file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 48 of file JGZFileReader.hh.

48 :
50 igzstream(file_name),
51 JStreamObjectIterator<T>(static_cast<std::istream&>(*this))
52 {}
JAccessible()
Default constructor.

Member Function Documentation

◆ is_open()

template<class T >
virtual bool JLANG::JGZFileReader< T >::is_open ( ) const
inlineoverridevirtual

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 60 of file JGZFileReader.hh.

61 {
62 return igzstream::is_open();
63 }
bool is_open() const
Definition gzstream.h:194

◆ open() [1/2]

template<class T >
virtual void JLANG::JGZFileReader< T >::open ( const char * file_name)
inlineoverridevirtual

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Definition at line 71 of file JGZFileReader.hh.

72 {
73 igzstream::open(file_name);
74
75 if (!this->is_open()) {
76 this->Throw(JFileOpenException(std::string("Error opening file ") + file_name));
77 }
78 }
virtual bool is_open() const override
Check is file is open.
static void Throw(const bool option)
Definition JThrow.hh:37
void open(const char *name, int open_mode=std::ios::in)
Definition gzstream.h:208

◆ close()

template<class T >
virtual void JLANG::JGZFileReader< T >::close ( )
inlineoverridevirtual

Close file.

Implements JLANG::JAccessible.

Definition at line 84 of file JGZFileReader.hh.

85 {
87 }
void close()
Definition gzstream.h:185

◆ open() [2/2]

void igzstream::open ( const char * name,
int open_mode = std::ios::in )
inlineinherited

Definition at line 208 of file gzstream.h.

208 {
209 gzstreambase::open( name, open_mode);
210 }
void open(const char *name, int open_mode)
Definition gzstream.h:180

◆ rdbuf()

gzstreambuf * gzstreambase::rdbuf ( )
inlineinherited

Definition at line 193 of file gzstream.h.

193{ return &buf; }
gzstreambuf buf
Definition gzstream.h:169

◆ setObject()

template<class T >
virtual bool JLANG::JStreamObjectIterator< T >::setObject ( T & object)
inlineoverridevirtualinherited

Set object.

Parameters
objectreference to object to be set
Returns
true if set; else false

Implements JLANG::JAbstractObjectIterator< T >.

Definition at line 45 of file JStreamObjectIterator.hh.

46 {
47 return (bool) (__in && __in >> object);
48 }

◆ hasNext()

template<class T >
virtual bool JLANG::JAbstractObjectIterator< 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 56 of file JAbstractObjectIterator.hh.

57 {
58 if (!has_next) {
59 has_next = this->setObject(object);
60 }
61
62 return has_next;
63 }
virtual bool setObject(T &object)=0
Set object.

◆ next()

template<class T >
virtual const pointer_type & JLANG::JAbstractObjectIterator< T >::next ( )
inlineoverridevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 71 of file JAbstractObjectIterator.hh.

72 {
73 if (has_next)
74 ps.reset(&this->object);
75 else
76 ps.reset(NULL);
77
78 has_next = false;
79
80 return ps;
81 }
virtual void reset() override
Reset pointer.
Definition JPointer.hh:84

◆ 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::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< const event_type >, JLANG::JAbstractObjectReader< Evt >, JLANG::JAbstractObjectReader< JDAQSummaryslice >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JTypeList< JDAQEvent, JNullType > >, JLANG::JAbstractObjectReader< KM3NETDAQ::JDAQEvent >, JLANG::JPipe< T >, JLANG::JPipe< JHead_t >, JLANG::JPipe< JTail_t >, JLANG::JSTDObjectIterator< T >, JROOT::JRootFileReader< T, false >, JROOT::JTreeReaderObjectIterator< T >, JSUPPORT::JMultipleFileScanner< T >, JSUPPORT::JMultipleFileScanner< Evt >, JSUPPORT::JMultipleFileScanner< JDAQSummaryslice >, JSUPPORT::JMultipleFileScanner< JHead_t >, JSUPPORT::JMultipleFileScanner< JTail_t >, JSUPPORT::JMultipleFileScanner< JTypeList< JDAQEvent, JNullType > >, JSUPPORT::JMultipleFileScanner< JTypeList< JHead_t, JTail_t > >, JSUPPORT::JMultipleFileScanner< KM3NETDAQ::JDAQEvent >, JSUPPORT::JMultipleFileScanner<>, JSUPPORT::JSingleFileScanner< T >, JSUPPORT::JSingleFileScanner< JHead_t >, JSUPPORT::JSingleFileScanner< JTail_t >, JSUPPORT::JSingleFileScanner< JTypeList< JHead_t, JTail_t > >, and JSUPPORT::JSingleFileScanner<>.

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

◆ Throw() [1/2]

static void JLANG::JThrow< JAccessible >::Throw ( const bool option)
inlinestaticinherited

Enable/disable throw option.

Parameters
optiontrue enable; false disable

Definition at line 37 of file JThrow.hh.

38 {
39 do_throw = option;
40 }

◆ Throw() [2/2]

static int JLANG::JThrow< JAccessible >::Throw ( const JException_t & error,
const int value = -1 )
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 51 of file JThrow.hh.

52 {
53 using namespace std;
54
55 if (do_throw) {
56 throw error;
57 }
58
59 cerr << error.what() << endl;
60
61 return value;
62 }

Member Data Documentation

◆ buf

gzstreambuf gzstreambase::buf
protectedinherited

Definition at line 169 of file gzstream.h.

◆ __in

template<class T >
std::istream& JLANG::JStreamObjectIterator< T >::__in
protectedinherited

Definition at line 51 of file JStreamObjectIterator.hh.

◆ object

template<class T >
T JLANG::JAbstractObjectIterator< T >::object
protectedinherited

object

Definition at line 34 of file JAbstractObjectIterator.hh.

◆ has_next

template<class T >
bool JLANG::JAbstractObjectIterator< T >::has_next
protectedinherited

status

Definition at line 35 of file JAbstractObjectIterator.hh.

◆ ps

template<class T >
pointer_type JLANG::JAbstractObjectIterator< T >::ps
privateinherited

Definition at line 84 of file JAbstractObjectIterator.hh.

◆ do_throw

bool JLANG::JThrow< JAccessible >::do_throw
staticprotectedinherited

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.


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