Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
JIO::JBinaryFileReader< T > Class Template Reference

Object reading from binary file. More...

#include <JBinaryFileReader.hh>

Inheritance diagram for JIO::JBinaryFileReader< T >:
JLANG::JAccessibleBinaryInputStream JIO::JStreamReader JIO::JReaderObjectIterator< T > JLANG::JAccessibleObjectIterator< T > JLANG::JAccessibleInputStream JIO::JReader JLANG::JAbstractObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JAccessible JLANG::JBinaryInput JLANG::JAbstractObjectStatus JLANG::JObjectIterator< T > JLANG::JThrow< JAccessible > JLANG::JThrow< JAccessible > JSUPPORT::JDAQFileReader< T, true >

Public Types

typedef JObjectIterator< T >
::pointer_type 
pointer_type
 

Public Member Functions

 JBinaryFileReader ()
 Default constructor. More...
 
virtual void open (const char *file_name)
 Open file. More...
 
virtual bool is_open () const
 Check is file is open. More...
 
virtual void close ()
 Close file. More...
 
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 Member Functions

virtual bool getStatus () const
 Status of reader. More...
 
virtual void clear ()
 Clear status of reader. More...
 
virtual int read (char *buffer, const int length)
 Read byte array. More...
 
JReaderoperator>> (JSerialisable &object)
 Read serialisable data object. More...
 
JReaderoperator>> (bool &value)
 
JReaderoperator>> (char &value)
 
JReaderoperator>> (unsigned char &value)
 
JReaderoperator>> (short &value)
 
JReaderoperator>> (unsigned short &value)
 
JReaderoperator>> (int &value)
 
JReaderoperator>> (unsigned int &value)
 
JReaderoperator>> (long int &value)
 
JReaderoperator>> (unsigned long int &value)
 
JReaderoperator>> (long long int &value)
 
JReaderoperator>> (unsigned long long int &value)
 
JReaderoperator>> (float &value)
 
JReaderoperator>> (double &value)
 
JReaderoperator>> (long double &value)
 
JReaderload (JSerialisable &object)
 Read object. More...
 
template<class T >
JReaderload (T &object)
 Read object. More...
 
 operator bool () const
 Type conversion operator. More...
 
bool operator! () const
 Negated status of this object. More...
 

Protected Attributes

std::istream & in
 
T object
 object More...
 
bool has_next
 status More...
 

Static Protected Attributes

static bool do_throw
 throw option More...
 

Detailed Description

template<class T>
class JIO::JBinaryFileReader< T >

Object reading from binary file.

This class implements the JLANG::JAccessibleObjectIterator interface.

Definition at line 32 of file JBinaryFileReader.hh.

Member Typedef Documentation

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

template<class T>
JIO::JBinaryFileReader< T >::JBinaryFileReader ( )
inline

Default constructor.

Definition at line 42 of file JBinaryFileReader.hh.

42  :
44  JStreamReader (static_cast<std::istream&> (*this)),
45  JReaderObjectIterator<T>(static_cast<JStreamReader&>(*this))
46  {}
JAccessibleBinaryInputStream()
Default constructor.
Binary input based on std::istream.
Definition: JStreamIO.hh:24
JReader object iterator.
JStreamReader(std::istream &__in)
Constructor.
Definition: JStreamIO.hh:33

Member Function Documentation

virtual void JLANG::JAccessibleBinaryInputStream::open ( const char *  file_name)
inlinevirtualinherited

Open file.

Parameters
file_namefile name

Reimplemented from JLANG::JAccessibleInputStream.

Definition at line 52 of file JAccessibleBinaryStream.hh.

53  {
54  std::ifstream::open(file_name, std::ios::binary);
55  }
T * open(const std::string &file_name)
Open file.
Definition: JeepToolkit.hh:306
virtual bool JLANG::JAccessibleInputStream::is_open ( ) const
inlinevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 53 of file JAccessibleStream.hh.

54  {
55  return std::ifstream::is_open();
56  }
virtual void JLANG::JAccessibleInputStream::close ( )
inlinevirtualinherited

Close file.

Implements JLANG::JAccessible.

Definition at line 77 of file JAccessibleStream.hh.

78  {
80  }
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:346
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  }
static bool do_throw
throw option
Definition: JThrow.hh:28
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  }
static bool do_throw
throw option
Definition: JThrow.hh:28
virtual const char * what() const
Get error message.
Definition: JException.hh:48
virtual bool JIO::JStreamReader::getStatus ( ) const
inlinevirtualinherited

Status of reader.

Returns
status of this reader

Implements JLANG::JAbstractObjectStatus.

Definition at line 43 of file JStreamIO.hh.

44  {
45  return (bool) in;
46  }
std::istream & in
Definition: JStreamIO.hh:73
virtual void JIO::JStreamReader::clear ( )
inlinevirtualinherited

Clear status of reader.

Reimplemented from JIO::JReader.

Definition at line 52 of file JStreamIO.hh.

53  {
54  in.clear();
55  }
std::istream & in
Definition: JStreamIO.hh:73
virtual int JIO::JStreamReader::read ( char *  buffer,
const int  length 
)
inlinevirtualinherited

Read byte array.

Parameters
bufferpointer to byte array
lengthnumber of bytes
Returns
number of bytes read

Implements JLANG::JBinaryInput.

Definition at line 65 of file JStreamIO.hh.

66  {
67  in.read(buffer, length);
68 
69  return in.gcount();
70  }
std::istream & in
Definition: JStreamIO.hh:73
JReader& JIO::JReader::operator>> ( JSerialisable object)
inlineinherited

Read serialisable data object.

Parameters
objectserialisable data object
Returns
JReader

Definition at line 80 of file JSerialisable.hh.

81  {
82  return object.read(*this);
83  }
JReader& JIO::JReader::operator>> ( bool &  value)
inlineinherited

Definition at line 86 of file JSerialisable.hh.

86 { read((char*) &value, sizeof(bool)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( char &  value)
inlineinherited

Definition at line 87 of file JSerialisable.hh.

87 { read((char*) &value, sizeof(char)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( unsigned char &  value)
inlineinherited

Definition at line 88 of file JSerialisable.hh.

88 { read((char*) &value, sizeof(unsigned char)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( short &  value)
inlineinherited

Definition at line 89 of file JSerialisable.hh.

89 { read((char*) &value, sizeof(short)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( unsigned short &  value)
inlineinherited

Definition at line 90 of file JSerialisable.hh.

90 { read((char*) &value, sizeof(unsigned short)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( int &  value)
inlineinherited

Definition at line 91 of file JSerialisable.hh.

91 { read((char*) &value, sizeof(int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( unsigned int &  value)
inlineinherited

Definition at line 92 of file JSerialisable.hh.

92 { read((char*) &value, sizeof(unsigned int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( long int &  value)
inlineinherited

Definition at line 93 of file JSerialisable.hh.

93 { read((char*) &value, sizeof(long int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( unsigned long int &  value)
inlineinherited

Definition at line 94 of file JSerialisable.hh.

94 { read((char*) &value, sizeof(unsigned long int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( long long int &  value)
inlineinherited

Definition at line 95 of file JSerialisable.hh.

95 { read((char*) &value, sizeof(long long int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( unsigned long long int &  value)
inlineinherited

Definition at line 96 of file JSerialisable.hh.

96 { read((char*) &value, sizeof(unsigned long long int)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( float &  value)
inlineinherited

Definition at line 97 of file JSerialisable.hh.

97 { read((char*) &value, sizeof(float)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( double &  value)
inlineinherited

Definition at line 98 of file JSerialisable.hh.

98 { read((char*) &value, sizeof(double)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::operator>> ( long double &  value)
inlineinherited

Definition at line 99 of file JSerialisable.hh.

99 { read((char*) &value, sizeof(long double)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.
JReader& JIO::JReader::load ( JSerialisable object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 108 of file JSerialisable.hh.

109  {
110  return object.read(*this);
111  }
template<class T >
JReader& JIO::JReader::load ( T object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 121 of file JSerialisable.hh.

122  {
123  return *this >> object;
124  }
JLANG::JAbstractObjectStatus::operator bool ( ) const
inlineinherited

Type conversion operator.

Returns
status of this object

Definition at line 33 of file JAbstractObjectStatus.hh.

34  {
35  return this->getStatus();
36  }
virtual bool getStatus() const =0
Get status of object.
bool JLANG::JAbstractObjectStatus::operator! ( ) const
inlineinherited

Negated status of this object.

Returns
negated status of this object

Definition at line 44 of file JAbstractObjectStatus.hh.

45  {
46  return !(this->getStatus());
47  }
virtual bool getStatus() const =0
Get status of object.
template<class T>
virtual bool JIO::JReaderObjectIterator< T >::setObject ( T object)
inlinevirtualinherited

Set object.

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

Implements JLANG::JAbstractObjectIterator< T >.

Reimplemented in JSUPPORT::JDAQFileReader< T, true >.

Definition at line 46 of file JReaderObjectIterator.hh.

47  {
48  return (bool) (in >> object);
49  }
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  }
virtual bool setObject(T &object)=0
Set object.
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  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
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 >, JLANG::JAbstractObjectReader< JDAQSummaryslice >, and JLANG::JAbstractObjectReader< JTypeList< JDAQEvent, JTypelist_t > >.

Definition at line 88 of file JObjectIterator.hh.

89  {
90  skip_type i = 0;
91 
92  for ( ; i != ns && hasNext(); ++i) {
93  next();
94  }
95 
96  return i;
97  }
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

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

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.

std::istream& JIO::JStreamReader::in
protectedinherited

Definition at line 73 of file JStreamIO.hh.

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

object

Definition at line 34 of file JAbstractObjectIterator.hh.

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

status

Definition at line 35 of file JAbstractObjectIterator.hh.


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