Jpp
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
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. More...
 
 JGZFileReader (const char *file_name)
 Constructor. More...
 
virtual bool is_open () const
 Check is file is open. More...
 
virtual void open (const char *file_name)
 Open file. More...
 
virtual void close ()
 Close file. More...
 
void open (const char *name, int open_mode=std::ios::in)
 
gzstreambufrdbuf ()
 
virtual bool setObject (T &object)
 Set object. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

Static Public Member Functions

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

Protected Attributes

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

Static Protected Attributes

static bool do_throw
 throw option More...
 

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>
typedef 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  {}

◆ 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  :
49  JAccessible(),
50  igzstream(file_name),
51  JStreamObjectIterator<T>(static_cast<std::istream&>(*this))
52  {}

Member Function Documentation

◆ is_open()

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

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  }

◆ open() [1/2]

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

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  }

◆ close()

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

Close file.

Implements JLANG::JAccessible.

Definition at line 84 of file JGZFileReader.hh.

85  {
87  }

◆ 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  }

◆ rdbuf()

gzstreambuf* gzstreambase::rdbuf ( )
inlineinherited

Definition at line 193 of file gzstream.h.

193 { return &buf; }

◆ setObject()

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

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

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  }

◆ next()

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

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  }

◆ skip()

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

◆ 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 error,
const int  value = -1 
)
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 50 of file JThrow.hh.

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

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:
JLANG::JAbstractObjectIterator::object
T object
object
Definition: JAbstractObjectIterator.hh:34
JLANG::skip_type
unsigned int skip_type
Type definition for number of objects to skip.
Definition: JObjectIterator.hh:25
igzstream::open
void open(const char *name, int open_mode=std::ios::in)
Definition: gzstream.h:208
gzstreambase::close
void close()
Definition: gzstream.h:185
JLANG::JFileOpenException
Exception for opening of file.
Definition: JException.hh:342
igzstream::igzstream
igzstream()
Definition: gzstream.h:205
JLANG::JObjectIterator::hasNext
virtual bool hasNext()=0
Check availability of next element.
JLANG::JStreamObjectIterator::__in
std::istream & __in
Definition: JStreamObjectIterator.hh:51
JLANG::JPointer::reset
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
JLANG::JAbstractObjectIterator::has_next
bool has_next
status
Definition: JAbstractObjectIterator.hh:35
JLANG::JAbstractObjectIterator::ps
pointer_type ps
Definition: JAbstractObjectIterator.hh:84
JLANG::JThrow< JAccessible >::Throw
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
JLANG::JStreamObjectIterator
Stream object iterator.
Definition: JStreamObjectIterator.hh:25
std
Definition: jaanetDictionary.h:36
gzstreambase::is_open
bool is_open() const
Definition: gzstream.h:194
JLANG::JAbstractObjectIterator::setObject
virtual bool setObject(T &object)=0
Set object.
JLANG::JThrow< JAccessible >::do_throw
static bool do_throw
throw option
Definition: JThrow.hh:28
gzstreambase::buf
gzstreambuf buf
Definition: gzstream.h:169
JLANG::JException::what
virtual const char * what() const
Get error message.
Definition: JException.hh:48
JLANG::JAccessible::JAccessible
JAccessible()
Default constructor.
Definition: JAccessible.hh:27
gzstreambase::open
void open(const char *name, int open_mode)
Definition: gzstream.h:180
JLANG::JGZFileReader::is_open
virtual bool is_open() const
Check is file is open.
Definition: JGZFileReader.hh:60
JLANG::JObjectIterator::next
virtual const pointer_type & next()=0
Get next element.