40 #ifndef _resourcememorystream_cpp
41 #define _resourcememorystream_cpp
44 #include "stringtool.h"
75 if( Position > BufferSize ) {
84 if( CursorOffset + Adjust < 0 ) {
87 if( CursorOffset + Adjust > BufferSize ) {
88 return BufferSize - CursorOffset;
94 {
return static_cast<std::streampos
>( this->gptr() - this->eback() ); }
97 {
return static_cast<std::streampos
>( this->pptr() - this->pbase() ); }
110 if( s != NULL && n > 0 ) {
128 if( which & std::ios_base::in ) {
132 case std::ios_base::beg: this->gbump( this->
CheckStreamPosition( off ) - ReadPosition );
break;
133 case std::ios_base::end: this->gbump( this->
CheckStreamPosition( BufferSize + off ) - ReadPosition );
break;
134 case std::ios_base::cur:
139 if( which & std::ios_base::out ) {
143 case std::ios_base::beg: this->pbump( this->
CheckStreamPosition( off ) - WritePosition );
break;
144 case std::ios_base::end: this->pbump( this->
CheckStreamPosition( BufferSize + off ) - WritePosition );
break;
145 case std::ios_base::cur:
155 if( which & std::ios_base::in ) {
160 if( which & std::ios_base::out ) {
176 assert( std::less_equal<Char8*>()(this->gptr(),this->egptr()) );
178 return this->egptr() - this->gptr();
185 if( this->
OpenMode & std::ios_base::in ) {
186 return std::streambuf::xsgetn(s,n);
193 if( this->gptr() == this->egptr() ) {
195 return traits_type::eof();
198 return traits_type::to_int_type( *(this->egptr()) );
203 return std::streambuf::uflow();
209 if( this->gptr() == this->eback() || ( c != traits_type::eof() && c != *( this->gptr() - 1 ) ) ) {
210 return traits_type::eof();
215 return this->sgetc();
223 if( this->
OpenMode & std::ios_base::out ) {
224 return std::streambuf::xsputn(s,n);
232 return traits_type::eof();
248 if( this->
setbuf(Buffer,BufferSize) ) {
256 char* NewBuf =
new char[BufferSize];
257 memcpy(NewBuf,Buffer,BufferSize);
264 return this->eback();
270 return this->egptr();
275 return this->egptr() - this->eback();
281 if( Mode & std::ios_base::in ) {
285 if( Mode & std::ios_base::out ) {
328 { this->
SetBuffer(Buffer,BufferSize,FreeAfter,Mode); }
340 { this->Buffer.SetBuffer(static_cast<char*>(Buffer),BufferSize,FreeBuf); this->Buffer.ConfigureBuffer(0,static_cast<std::ios_base::openmode>(Mode)); }
343 { this->Buffer.CopyBuffer(static_cast<const char*>(Buffer),BufferSize); this->Buffer.ConfigureBuffer(0,static_cast<std::ios_base::openmode>(Mode)); }
void CreateBuffer(const Whole Size, const Whole Mode=Resource::SF_Read|Resource::SF_Write)
Creates a new memory buffer to stream to/from.
std::streamoff CheckStreamOffset(const std::streamoff CursorOffset, const std::streamoff Adjust)
Verifies an offset in this stream is valid for a read or write cursor.
virtual int overflow(int c=traits_type::eof())
Writes a character at the current write position without advancing the write position.
Char8 * BufferStart
A pointer to the start of this memory buffer.
bool Boole
Generally acts a single bit, true or false.
virtual ~MemoryStream()
Class destructor.
virtual std::streampos seekpos(std::streampos sp, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
Moves the read and/or write pointers to the specified position in the stream.
void SetFreeBuffer(const Boole FreeBuf)
Sets if this should delete it's internal buffer when it is destroyed.
virtual std::streambuf * setbuf(char *s, std::streamsize n)
Sets the buffer to be streamed from.
Whole OpenMode
A bitfield describing the settings this buffer was opened with.
Boole GetFreeBuffer() const
Gets if this should delete it's internal buffer when it is destroyed.
MemoryStream()
Blank constructor.
void CopyBuffer(const void *Buffer, const Whole BufferSize, const Whole Mode=Resource::SF_Read|Resource::SF_Write)
Copies a pre-existing buffer to this buffer for streaming.
void DestroyBuffer()
Convenience method for deleting the existing buffer being streamed.
Char8 * GetBufferStart() const
Gets the start of this buffer.
std::streampos GetReadPosition() const
Gets the current position of the read cursor.
Base class for streams that support both read and write operations.
This implements the exception hiearchy for Mezzanine.
virtual int pbackfail(int c=traits_type::eof())
Reverse the last character extraction operation by decrementing the read position and placing the spe...
void SetFreeBuffer(const Boole FreeBuf)
Sets if this should delete it's internal buffer when it is destroyed.
char Char8
A datatype to represent one character.
std::streampos GetWritePosition() const
Gets the current position of the write cursor.
virtual ~MemoryStreamBuffer()
Class destructor.
void CopyBuffer(const char *Buffer, const Whole BufferSize)
Copies a pre-existing buffer to this buffer for streaming.
virtual std::streamsize showmanyc()
Gets the number of characters remaining that can be safely extracted from this buffer.
void ConfigureBuffer(const std::streampos Pos, std::ios_base::openmode Mode=std::ios_base::in|std::ios_base::out)
Sets the get and put pointers for the streambuffer and assigns the current position to the specified ...
Char8 * GetBufferEnd() const
Gets the end of this buffer.
virtual StreamSize GetSize() const
Boole GetFreeBuffer() const
Gets if this should delete it's internal buffer when it is destroyed.
Declaration of MemoryStream.
void SetBuffer(char *Buffer, const Whole BufferSize, const Boole FreeBuf)
Wraps an external buffer for streaming.
virtual int uflow()
Gets the value at the current read position and then increments the read position.
std::streampos CheckStreamPosition(const std::streampos Position)
Verifies a position in this stream is valid.
void SetBuffer(void *Buffer, const Whole BufferSize, const Boole FreeBuf, const Whole Mode=Resource::SF_Read|Resource::SF_Write)
Wraps an external buffer for streaming.
virtual int sync()
Syncs this stream buffer with it's source.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual std::streamsize xsgetn(char *s, std::streamsize n)
Gets a number of characters starting at the read position and populates an array with them...
std::streamsize StreamSize
Convenience define for the stream size datatype.
MemoryStreamBuffer()
Class constructor.
std::streamsize GetBufferSize() const
Gets the size of the current buffer being streamed to/from.
virtual std::streamsize xsputn(const char *s, std::streamsize n)
Writes a number of characters from a provided buffer to the stream.
Char8 * GetBufferEnd() const
Gets the end of this buffer.
virtual std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
Moves the read and/or write pointers in the stream.
Char8 * BufferEnd
A pointer to one passed the last element in the range of this buffer.
MemoryStreamBuffer Buffer
The buffer object being streamed to/from.
virtual void imbue(const std::locale &loc)
Notifies this class that a new locale is being imbued to this streambuf.
Char8 * GetBufferStart() const
Gets the start of this buffer.
void CreateBuffer(const Whole Size)
Convenience method for creating a new buffer to be used by this stream.
virtual int underflow()
Gets the value at the current read position without incrementing the read position.
Boole FreeBuffer
Stores whether or not the memory allocated will be free'd when this buffer is deleted.