Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JIO::JFileStreamReader Class Reference

Binary buffered file input. More...

#include <JFileStreamIO.hh>

Inheritance diagram for JIO::JFileStreamReader:
JIO::JBufferedReader JIO::JReader JLANG::JBinaryInput JLANG::JAbstractObjectStatus

Public Member Functions

 JFileStreamReader ()
 Default constructor. More...
 
 JFileStreamReader (const char *file_name, const int size=1048576)
 Constructor. More...
 
void open (const char *file_name)
 Open file. More...
 
virtual void clear () override
 Clear status of reader. More...
 
void rewind ()
 Rewind. More...
 
virtual bool getStatus () const override
 Status of reader. More...
 
virtual int read (char *zbuf, int n) override
 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)
 
JReaderoperator>> (JLANG::JObjectID &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 Member Functions

void reset ()
 Reset. More...
 

Protected Attributes

JLANG::JSinglePointer< JReaderin
 
char * buffer
 internal buffer More...
 
int size
 size of internal buffer More...
 
int pos
 pointer to begin of available data More...
 
int ls
 pointer to end of available data More...
 
bool eof
 end of file More...
 

Detailed Description

Binary buffered file input.

Definition at line 22 of file JFileStreamIO.hh.

Constructor & Destructor Documentation

JIO::JFileStreamReader::JFileStreamReader ( )
inline

Default constructor.

Definition at line 36 of file JFileStreamIO.hh.

36  :
37  std::ifstream(),
38  JBufferedReader(new JStreamReader(static_cast<std::ifstream&>(*this)))
39  {}
JBufferedReader(JReader *__in, const int __size=1048576)
Constructor.
Definition: JBufferedIO.hh:36
Binary input based on std::istream.
Definition: JStreamIO.hh:24
JIO::JFileStreamReader::JFileStreamReader ( const char *  file_name,
const int  size = 1048576 
)
inline

Constructor.

Parameters
file_namefile name
sizesize of internal buffer

Definition at line 48 of file JFileStreamIO.hh.

49  :
50  std::ifstream (),
51  JBufferedReader(new JStreamReader(static_cast<std::ifstream&>(*this)), size)
52  {
53  open(file_name);
54  }
JBufferedReader(JReader *__in, const int __size=1048576)
Constructor.
Definition: JBufferedIO.hh:36
void open(const char *file_name)
Open file.
Binary input based on std::istream.
Definition: JStreamIO.hh:24
int size
size of internal buffer
Definition: JBufferedIO.hh:134

Member Function Documentation

void JIO::JFileStreamReader::open ( const char *  file_name)
inline

Open file.

Parameters
file_namefile name

Definition at line 62 of file JFileStreamIO.hh.

63  {
64  static_cast<std::ifstream*>(this)->open(file_name, std::ios::binary);
65  }
void open(const char *file_name)
Open file.
virtual void JIO::JFileStreamReader::clear ( )
inlineoverridevirtual

Clear status of reader.

Reimplemented from JIO::JBufferedReader.

Definition at line 71 of file JFileStreamIO.hh.

72  {
73  std::ifstream ::clear();
75  }
virtual void clear() override
Clear status of reader.
Definition: JBufferedIO.hh:69
void JIO::JFileStreamReader::rewind ( )
inline

Rewind.

Definition at line 81 of file JFileStreamIO.hh.

82  {
83  seekg(0); // rewind file stream
84 
85  reset(); // reset buffer
86  }
void reset()
Reset.
Definition: JBufferedIO.hh:124
virtual bool JIO::JBufferedReader::getStatus ( ) const
inlineoverridevirtualinherited

Status of reader.

Returns
status of this reader

Implements JLANG::JAbstractObjectStatus.

Definition at line 60 of file JBufferedIO.hh.

61  {
62  return in->getStatus() || !eof;
63  }
bool eof
end of file
Definition: JBufferedIO.hh:137
JLANG::JSinglePointer< JReader > in
Definition: JBufferedIO.hh:131
virtual int JIO::JBufferedReader::read ( char *  zbuf,
int  n 
)
inlineoverridevirtualinherited

Read byte array.

Parameters
zbufpointer to byte array
nnumber of bytes
Returns
number of bytes

Implements JLANG::JBinaryInput.

Definition at line 82 of file JBufferedIO.hh.

83  {
84  for (int i = 0; i != n; ) {
85 
86  int m = n - i;
87 
88  if (m > ls - pos) {
89 
90  memmove(buffer, buffer + pos, ls - pos);
91 
92  ls -= pos;
93  pos = 0;
94  ls += in->read(buffer + ls, size - ls);
95 
96  if (m > ls) {
97 
98  if (ls == 0) {
99 
100  eof = true;
101 
102  return n - i;
103  }
104 
105  m = ls;
106  }
107  }
108 
109  memcpy(zbuf + i, buffer + pos, m);
110 
111  i += m;
112  pos += m;
113  }
114 
115  eof = false;
116 
117  return n;
118  }
int pos
pointer to begin of available data
Definition: JBufferedIO.hh:135
int ls
pointer to end of available data
Definition: JBufferedIO.hh:136
const int n
Definition: JPolint.hh:676
bool eof
end of file
Definition: JBufferedIO.hh:137
JLANG::JSinglePointer< JReader > in
Definition: JBufferedIO.hh:131
int size
size of internal buffer
Definition: JBufferedIO.hh:134
char * buffer
internal buffer
Definition: JBufferedIO.hh:133
void JIO::JBufferedReader::reset ( )
inlineprotectedinherited

Reset.

Definition at line 124 of file JBufferedIO.hh.

125  {
126  pos = 0;
127  ls = 0;
128  eof = true;
129  }
int pos
pointer to begin of available data
Definition: JBufferedIO.hh:135
int ls
pointer to end of available data
Definition: JBufferedIO.hh:136
bool eof
end of file
Definition: JBufferedIO.hh:137
JReader& JIO::JReader::operator>> ( JSerialisable object)
inlineinherited

Read serialisable data object.

Parameters
objectserialisable data object
Returns
JReader

Definition at line 81 of file JSerialisable.hh.

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

Definition at line 87 of file JSerialisable.hh.

87 { 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 88 of file JSerialisable.hh.

88 { 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 89 of file JSerialisable.hh.

89 { 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 90 of file JSerialisable.hh.

90 { 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 91 of file JSerialisable.hh.

91 { 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 92 of file JSerialisable.hh.

92 { 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 93 of file JSerialisable.hh.

93 { 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 94 of file JSerialisable.hh.

94 { 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 95 of file JSerialisable.hh.

95 { 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 96 of file JSerialisable.hh.

96 { 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 97 of file JSerialisable.hh.

97 { 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 98 of file JSerialisable.hh.

98 { 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 99 of file JSerialisable.hh.

99 { 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 100 of file JSerialisable.hh.

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

Definition at line 101 of file JSerialisable.hh.

101 { return (*this) >> value.getID(); }
int getID() const
Get identifier.
Definition: JObjectID.hh:50
JReader& JIO::JReader::load ( JSerialisable object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 110 of file JSerialisable.hh.

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

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 123 of file JSerialisable.hh.

124  {
125  return *this >> object;
126  }
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.

Member Data Documentation

JLANG::JSinglePointer<JReader> JIO::JBufferedReader::in
protectedinherited

Definition at line 131 of file JBufferedIO.hh.

char* JIO::JBufferedReader::buffer
protectedinherited

internal buffer

Definition at line 133 of file JBufferedIO.hh.

int JIO::JBufferedReader::size
protectedinherited

size of internal buffer

Definition at line 134 of file JBufferedIO.hh.

int JIO::JBufferedReader::pos
protectedinherited

pointer to begin of available data

Definition at line 135 of file JBufferedIO.hh.

int JIO::JBufferedReader::ls
protectedinherited

pointer to end of available data

Definition at line 136 of file JBufferedIO.hh.

bool JIO::JBufferedReader::eof
protectedinherited

end of file

Definition at line 137 of file JBufferedIO.hh.


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