40 #ifndef _resourcedatastream_cpp
41 #define _resourcedatastream_cpp
44 #include "stringtool.h"
51 #define TEMP_STREAM_SIZE 128
71 {
return this->eof(); }
74 {
return this->bad(); }
77 {
return this->fail(); }
80 {
return this->good(); }
90 this->read(static_cast<char*>(Buffer),Size);
91 return this->gcount();
95 { this->seekg(Position); }
98 { this->seekg(Offset,static_cast<std::ios_base::seekdir>(Origin)); }
101 {
return this->tellg(); }
117 {
return this->eof(); }
120 {
return this->bad(); }
123 {
return this->fail(); }
126 {
return this->good(); }
136 this->write(static_cast<const char*>(Buffer),Size);
137 return ( this->fail() ? 0 : Size );
141 { this->seekp(Position); }
144 { this->seekp(Offset,static_cast<std::ios_base::seekdir>(Origin)); }
147 {
return this->tellp(); }
163 {
return this->eof(); }
166 {
return this->bad(); }
169 {
return this->fail(); }
172 {
return this->good(); }
182 this->read(static_cast<char*>(Buffer),Size);
183 return this->gcount();
187 { this->seekg(Position); }
190 { this->seekg(Offset,static_cast<std::ios_base::seekdir>(Origin)); }
193 {
return this->tellg(); }
200 this->write(static_cast<const char*>(Buffer),Size);
201 return ( this->fail() ? 0 : Size );
205 { this->seekp(Position); }
208 { this->seekp(Offset,static_cast<std::ios_base::seekdir>(Origin)); }
211 {
return this->tellp(); }
221 this->seekg(Position);
222 this->seekp(Position);
227 this->seekg(Offset,static_cast<std::ios_base::seekdir>(Origin));
228 this->seekp(Offset,static_cast<std::ios_base::seekdir>(Origin));
242 size_t BufferSize = ( this->
GetSize() > 0 ? this->
GetSize() : 4096 );
243 char* Buffer =
new char[BufferSize];
247 while( !this->
EoF() )
249 size_t BytesRead =
Read(Buffer,BufferSize);
250 Ret.append(Buffer,BytesRead);
258 Boole TrimCR =
false;
259 if( Delim.find_first_of(
'\n') != String::npos ) {
263 char Temp[TEMP_STREAM_SIZE];
264 size_t ChunkSize = std::min(MaxCount,(
size_t)TEMP_STREAM_SIZE - 1);
265 size_t TotalCount = 0;
266 size_t ReadCount = 0;
268 while( ChunkSize && ( ReadCount =
Read(Temp,ChunkSize) ) != 0 )
270 Temp[ReadCount] =
'\0';
271 size_t Pos = std::strcspn(Temp,Delim.c_str());
273 if( Pos < ReadCount ) {
274 this->
Advance((
long)(Pos + 1 - ReadCount));
278 std::memcpy(Buffer + TotalCount,Temp,Pos);
282 if( Pos < ReadCount ) {
283 if( TrimCR && TotalCount && Buffer[TotalCount - 1] ==
'\r' ) {
289 ChunkSize = std::min(MaxCount - TotalCount,(
size_t)TEMP_STREAM_SIZE - 1);
291 Buffer[TotalCount] =
'\0';
297 char Temp[TEMP_STREAM_SIZE];
301 while( ( ReadCount =
Read(Temp,TEMP_STREAM_SIZE - 1) ) != 0 )
303 Temp[ReadCount] =
'\0';
305 char* Pos = std::strchr(Temp,
'\n');
307 this->
Advance( (
long)(Pos + 1 - Temp - ReadCount) );
314 if( Ret.length() && Ret[Ret.length() - 1] ==
'\r' ) {
315 Ret.erase(Ret.length() - 1, 1);
330 char Temp[TEMP_STREAM_SIZE];
331 size_t TotalBytes = 0;
332 size_t ReadCount = 0;
334 while( ( ReadCount =
Read(Temp,TEMP_STREAM_SIZE - 1) ) != 0 )
336 Temp[ReadCount] =
'\0';
337 size_t Position = std::strcspn(Temp,Delim.c_str());
339 if( Position < ReadCount ) {
340 this->
Advance( (
long)(Position + 1 - ReadCount) );
341 TotalBytes += Position + 1;
345 TotalBytes += ReadCount;
virtual size_t Read(void *Buffer, StreamSize Size)
Reads from the stream and copies that data to a buffer.
virtual StreamPos GetReadPosition()
Gets the current read position in this stream.
virtual Boole Fail() const
Gets whether or not an otherwise silent and recoverable error was detected in a previous operation in...
virtual size_t ReadLine(Char8 *Buffer, size_t MaxCount, const String &Delim="\n")
Reads a single line from a string.
OStream(std::streambuf *Buf)
Class constructor.
virtual Boole IsValid() const
Gets whether or not this stream is intact and ready for operations.
bool Boole
Generally acts a single bit, true or false.
virtual String GetLine(Boole Trim=true)
Gets the contents of the current line in the stream.
virtual ~IOStream()
Class destructor.
virtual size_t Write(const void *Buffer, StreamSize Size)
Writes data to the stream.
virtual Boole Bad() const
Gets whether or not a critical error was detected in a previous operation in the stream.
virtual void SetReadPosition(StreamPos Position)
Sets the position of the read cursor explicitly.
virtual void SetWritePosition(StreamPos Position)
Sets the position of the write cursor explicitly.
virtual void SetWritePosition(StreamPos Position)
Sets the position of the write cursor explicitly.
The current position for read/write operations in the stream.
virtual Boole Fail() const
Gets whether or not an otherwise silent and recoverable error was detected in a previous operation in...
virtual Boole EoF() const
Gets whether or not the current position is at the end of the stream.
This implements the exception hiearchy for Mezzanine.
virtual StreamPos GetReadPosition()
Gets the current read position in this stream.
virtual StreamPos GetWritePosition()
Gets the current write position in this stream.
char Char8
A datatype to represent one character.
virtual size_t Read(void *Buffer, StreamSize Size)
Reads from the stream and copies that data to a buffer.
virtual Boole Fail() const
Gets whether or not an otherwise silent and recoverable error was detected in a previous operation in...
virtual void ClearErrors()
Clears any stored error state on the stream.
virtual void SetReadPosition(StreamPos Position)
Sets the position of the read cursor explicitly.
virtual Boole Bad() const
Gets whether or not a critical error was detected in a previous operation in the stream.
virtual ~OStream()
Class destructor.
virtual Boole EoF() const
Gets whether or not the current position is at the end of the stream.
virtual size_t SkipLine(const String &Delim="\n")
Moves the current position to the start of the next line.
SeekOrigin
An enum describing which position should be considered the origin for changing the current position i...
IStream(std::streambuf *Buf)
Class constructor.
virtual void ClearErrors()
Clears any stored error state on the stream.
virtual StreamSize GetSize() const =0
Gets the size of the stream.
virtual void Advance(const StreamOff Count)
Advances the position in the stream.
virtual void ClearErrors()
Clears any stored error state on the stream.
virtual StreamPos GetWritePosition()
Gets the current write position in this stream.
virtual Boole EoF() const
Gets whether or not the current position is at the end of the stream.
virtual Boole Bad() const
Gets whether or not a critical error was detected in a previous operation in the stream.
The bulk of the engine components go in this namspace.
IOStream(std::streambuf *Buf)
Class constructor.
virtual String GetAsString()
Gets the contents of the stream as a string.
std::streamsize StreamSize
Convenience define for the stream size datatype.
virtual Boole IsValid() const
Gets whether or not this stream is intact and ready for operations.
std::streampos StreamPos
Convenience define for the stream position datatype.
std::streamoff StreamOff
Convenience define for the stream offset datatype.
virtual size_t Write(const void *Buffer, StreamSize Size)
Writes data to the stream.
virtual ~IStream()
Class destructor.
virtual void SetStreamPosition(StreamPos Position)
Sets the position of the read and write cursors explicitly.
std::string String
A datatype used to a series of characters.
virtual Boole IsValid() const
Gets whether or not this stream is intact and ready for operations.
virtual StreamPos GetStreamPosition(const Boole Read=true)
Gets the current position in this stream.
Declaration of DataStream.