Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public 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 bool getStatus () const
 Status of reader. More...
 
virtual void clear ()
 Clear status of reader. More...
 
virtual int read (char *zbuf, int n)
 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

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:127

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 bool JIO::JBufferedReader::getStatus ( ) const
inlinevirtualinherited

Status of reader.

Returns
status of this reader

Implements JLANG::JAbstractObjectStatus.

Definition at line 62 of file JBufferedIO.hh.

63  {
64  return in->getStatus() || !eof;
65  }
bool eof
end of file
Definition: JBufferedIO.hh:130
JLANG::JSinglePointer< JReader > in
Definition: JBufferedIO.hh:124
virtual void JIO::JBufferedReader::clear ( )
inlinevirtualinherited

Clear status of reader.

Reimplemented from JIO::JReader.

Definition at line 71 of file JBufferedIO.hh.

72  {
73  in->clear();
74  }
JLANG::JSinglePointer< JReader > in
Definition: JBufferedIO.hh:124
virtual int JIO::JBufferedReader::read ( char *  zbuf,
int  n 
)
inlinevirtualinherited

Read byte array.

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

Implements JLANG::JBinaryInput.

Definition at line 84 of file JBufferedIO.hh.

85  {
86  for (int i = 0; i != n; ) {
87 
88  int m = n - i;
89 
90  if (m > ls - pos) {
91 
92  memmove(buffer, buffer + pos, ls - pos);
93 
94  ls -= pos;
95  pos = 0;
96  ls += in->read(buffer + ls, size - ls);
97 
98  if (m > ls) {
99 
100  if (ls == 0) {
101 
102  eof = true;
103 
104  return n - i;
105  }
106 
107  m = ls;
108  }
109  }
110 
111  memcpy(zbuf + i, buffer + pos, m);
112 
113  i += m;
114  pos += m;
115  }
116 
117  eof = false;
118 
119  return n;
120  }
int pos
pointer to begin of available data
Definition: JBufferedIO.hh:128
int ls
pointer to end of available data
Definition: JBufferedIO.hh:129
bool eof
end of file
Definition: JBufferedIO.hh:130
JLANG::JSinglePointer< JReader > in
Definition: JBufferedIO.hh:124
int size
size of internal buffer
Definition: JBufferedIO.hh:127
alias put_queue eval echo n
Definition: qlib.csh:19
char * buffer
internal buffer
Definition: JBufferedIO.hh:126
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.

Member Data Documentation

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

Definition at line 124 of file JBufferedIO.hh.

char* JIO::JBufferedReader::buffer
protectedinherited

internal buffer

Definition at line 126 of file JBufferedIO.hh.

int JIO::JBufferedReader::size
protectedinherited

size of internal buffer

Definition at line 127 of file JBufferedIO.hh.

int JIO::JBufferedReader::pos
protectedinherited

pointer to begin of available data

Definition at line 128 of file JBufferedIO.hh.

int JIO::JBufferedReader::ls
protectedinherited

pointer to end of available data

Definition at line 129 of file JBufferedIO.hh.

bool JIO::JBufferedReader::eof
protectedinherited

end of file

Definition at line 130 of file JBufferedIO.hh.


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