1 #ifndef JUGIMAP_STREAMS_H
2 #define JUGIMAP_STREAMS_H
44 virtual int Pos() = 0;
47 virtual void Seek(
int _pos) = 0;
50 virtual int Size() = 0;
53 virtual void Close() = 0;
56 virtual unsigned char ReadByte() = 0;
83 bool IsOpen()
override {
return fs.is_open();}
84 int Pos()
override {
return fs.tellg();}
85 void Seek(
int _pos)
override {fs.seekg(_pos);}
86 int Size()
override {
return size;}
87 void Close()
override {fs.close();}
93 fs.read(reinterpret_cast<char*>(&value), 1);
100 fs.read(reinterpret_cast<char*>(&value), 4);
107 fs.read(reinterpret_cast<char*>(&value), 4);
134 BinaryBufferStreamReader(
unsigned char *_buff,
int _size,
bool _ownedBuffer) : buff(_buff), size(_size), ownedBuffer(_ownedBuffer){}
139 if(ownedBuffer && buff!=
nullptr){
144 bool IsOpen()
override {
return size > 0; }
145 int Pos()
override {
return pos;}
146 void Seek(
int _pos)
override { pos = _pos; }
147 int Size()
override {
return size;}
149 unsigned char* GetBuffer() {
return buff;}
154 unsigned char value = (buff+pos)[0];
161 int value = reinterpret_cast<int*>(buff+pos)[0];
168 float value = reinterpret_cast<float*>(buff+pos)[0];
177 std::string value(reinterpret_cast<char*>(buff+pos), length);
184 unsigned char* buff =
nullptr;
187 bool ownedBuffer =
false;
202 virtual bool IsOpen() = 0;
205 virtual void ReadLine(std::string &s) = 0;
208 virtual bool Eof() = 0;
211 virtual void Close() = 0;
227 virtual bool IsOpen()
override {
return fs.is_open();}
230 virtual void ReadLine(std::string &s)
override { std::getline(fs, s); };
233 virtual bool Eof()
override {
return fs.eof(); }
236 virtual void Close()
override { fs.close(); }
void Close() override
Close the stream.
Definition: jmStreams.h:87
virtual void Close()=0
Close the stream.
Extended BinaryStreamReader class which reads from a memory buffer.
Definition: jmStreams.h:125
BinaryBufferStreamReader(unsigned char *_buff, int _size, bool _ownedBuffer)
Constructor.
Definition: jmStreams.h:134
virtual int Size()=0
Returns the size of the stream.
virtual void Close()=0
Close the stream.
virtual float ReadFloat()=0
Read and returns the float number (4 bytes).
int Pos() override
Returns the current reading position of the stream.
Definition: jmStreams.h:145
virtual void Close() override
Close the stream.
Definition: jmStreams.h:236
std::string ReadString() override
Read and returns the string. The length of string is written as the integer at the start.
Definition: jmStreams.h:174
bool IsOpen() override
Returns true if the stream of this object is open for reading; if not it returns false.
Definition: jmStreams.h:83
virtual bool IsOpen()=0
Returns true if the stream of this object is open for reading; if not it returns false.
virtual bool Eof()=0
Returns true if the end of file is reached; if not it returns false.
virtual void ReadLine(std::string &s)=0
Returns true if the stream of this object is open for reading; if not it returns false.
int Pos() override
Returns the current reading position of the stream.
Definition: jmStreams.h:84
virtual int ReadInt()=0
Read and returns the integer number (4 bytes).
int ReadInt() override
Read and returns the integer number (4 bytes).
Definition: jmStreams.h:159
virtual bool IsOpen() override
Returns true if the stream of this object is open for reading; if not it returns false.
Definition: jmStreams.h:227
The base abstract class for reading binary streams.
Definition: jmStreams.h:33
virtual bool Eof() override
Returns true if the end of file is reached; if not it returns false.
Definition: jmStreams.h:233
The base abstract class for reading text streams.
Definition: jmStreams.h:194
Extended TextStreamReader class which utilizes the standard library ifstream class for reading.
Definition: jmStreams.h:218
virtual void ReadLine(std::string &s) override
Returns true if the stream of this object is open for reading; if not it returns false.
Definition: jmStreams.h:230
StdBinaryFileStreamReader(const std::string &fileName)
Constructor.
Definition: jmStreams.cpp:24
virtual int Pos()=0
Returns the current reading position of the stream.
Extended BinaryStreamReader class which utilizes the standard library ifstream class for reading.
Definition: jmStreams.h:73
virtual bool IsOpen()=0
Returns true if the stream of this object is open for reading; if not it returns false.
void Seek(int _pos) override
Set the current reading position of the stream.
Definition: jmStreams.h:85
unsigned char ReadByte() override
Read and returns the byte number.
Definition: jmStreams.h:90
float ReadFloat() override
Read and returns the float number (4 bytes).
Definition: jmStreams.h:166
std::string ReadString() override
Read and returns the string. The length of string is written as the integer at the start.
Definition: jmStreams.cpp:37
bool IsOpen() override
Returns true if the stream of this object is open for reading; if not it returns false.
Definition: jmStreams.h:144
virtual ~BinaryStreamReader()
Destructor.
Definition: jmStreams.h:38
unsigned char ReadByte() override
Read and returns the byte number.
Definition: jmStreams.h:152
void Close() override
Close the stream.
Definition: jmStreams.h:148
virtual void Seek(int _pos)=0
Set the current reading position of the stream.
int Size() override
Returns the size of the stream.
Definition: jmStreams.h:147
int Size() override
Returns the size of the stream.
Definition: jmStreams.h:86
int ReadInt() override
Read and returns the integer number (4 bytes).
Definition: jmStreams.h:97
float ReadFloat() override
Read and returns the float number (4 bytes).
Definition: jmStreams.h:104
virtual std::string ReadString()=0
Read and returns the string. The length of string is written as the integer at the start.
virtual ~TextStreamReader()
Destructor.
Definition: jmStreams.h:199
virtual unsigned char ReadByte()=0
Read and returns the byte number.
void Seek(int _pos) override
Set the current reading position of the stream.
Definition: jmStreams.h:146