Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Mezzanine::Resource::MemoryStreamBuffer Class Reference

A stream buffer object to a chunk of memory. More...

#include <memorystream.h>

+ Inheritance diagram for Mezzanine::Resource::MemoryStreamBuffer:
+ Collaboration diagram for Mezzanine::Resource::MemoryStreamBuffer:

Public Member Functions

 MemoryStreamBuffer ()
 Class constructor.
 
virtual ~MemoryStreamBuffer ()
 Class destructor.
 
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 offset. More...
 
void CopyBuffer (const char *Buffer, const Whole BufferSize)
 Copies a pre-existing buffer to this buffer for streaming. More...
 
void CreateBuffer (const Whole Size)
 Convenience method for creating a new buffer to be used by this stream. More...
 
void DestroyBuffer ()
 Convenience method for deleting the existing buffer being streamed.
 
Char8GetBufferEnd () const
 Gets the end of this buffer. More...
 
std::streamsize GetBufferSize () const
 Gets the size of the current buffer being streamed to/from. More...
 
Char8GetBufferStart () const
 Gets the start of this buffer. More...
 
Boole GetFreeBuffer () const
 Gets if this should delete it's internal buffer when it is destroyed. More...
 
void SetBuffer (char *Buffer, const Whole BufferSize, const Boole FreeBuf)
 Wraps an external buffer for streaming. More...
 
void SetFreeBuffer (const Boole FreeBuf)
 Sets if this should delete it's internal buffer when it is destroyed. More...
 

Protected Member Functions

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. More...
 
std::streampos CheckStreamPosition (const std::streampos Position)
 Verifies a position in this stream is valid. More...
 
std::streampos GetReadPosition () const
 Gets the current position of the read cursor. More...
 
std::streampos GetWritePosition () const
 Gets the current position of the write cursor. More...
 
virtual void imbue (const std::locale &loc)
 Notifies this class that a new locale is being imbued to this streambuf. More...
 
virtual int overflow (int c=traits_type::eof())
 Writes a character at the current write position without advancing the write position. More...
 
virtual int pbackfail (int c=traits_type::eof())
 Reverse the last character extraction operation by decrementing the read position and placing the specified character in it's place. More...
 
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. More...
 
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. More...
 
virtual std::streambuf * setbuf (char *s, std::streamsize n)
 Sets the buffer to be streamed from. More...
 
virtual std::streamsize showmanyc ()
 Gets the number of characters remaining that can be safely extracted from this buffer. More...
 
virtual int sync ()
 Syncs this stream buffer with it's source. More...
 
virtual int uflow ()
 Gets the value at the current read position and then increments the read position. More...
 
virtual int underflow ()
 Gets the value at the current read position without incrementing the read position. More...
 
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. More...
 
virtual std::streamsize xsputn (const char *s, std::streamsize n)
 Writes a number of characters from a provided buffer to the stream. More...
 

Protected Attributes

Char8BufferEnd
 A pointer to one passed the last element in the range of this buffer. More...
 
Char8BufferStart
 A pointer to the start of this memory buffer. More...
 
Boole FreeBuffer
 Stores whether or not the memory allocated will be free'd when this buffer is deleted. More...
 
Whole OpenMode
 A bitfield describing the settings this buffer was opened with. More...
 

Detailed Description

A stream buffer object to a chunk of memory.

Definition at line 56 of file memorystream.h.

Member Function Documentation

std::streamoff Mezzanine::Resource::MemoryStreamBuffer::CheckStreamOffset ( const std::streamoff  CursorOffset,
const std::streamoff  Adjust 
)
protected

Verifies an offset in this stream is valid for a read or write cursor.

Parameters
CursorOffsetThe current read/write position in this stream.
AdjustThe amount of offset to be checked/applied to the provided read/write position.
Returns
Returns an std::streamoff containing the clamped offset for the given cursor in this stream.

Definition at line 81 of file memorystream.cpp.

std::streampos Mezzanine::Resource::MemoryStreamBuffer::CheckStreamPosition ( const std::streampos  Position)
protected

Verifies a position in this stream is valid.

Parameters
PositionThe position in this stream to check.
Returns
Returns an std::streampos containing the clamped position for this stream.

Definition at line 69 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::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 offset.

Parameters
PosThe offset to set the current read/write position to.
ModeAn open mode describing if this buffer will be configured for reading, writing, or both.

Definition at line 278 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::CopyBuffer ( const char *  Buffer,
const Whole  BufferSize 
)

Copies a pre-existing buffer to this buffer for streaming.

Parameters
BufferThe buffer to be copied.
BufferSizeThe size of the buffer to be copied.

Definition at line 254 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::CreateBuffer ( const Whole  Size)

Convenience method for creating a new buffer to be used by this stream.

Remarks
No changes will be made if the Size is set to 0 or less.
Parameters
SizeThe size of the buffer to be allocated.
ModeAn open mode describing if this buffer will be configured for reading, writing, or both.

Definition at line 238 of file memorystream.cpp.

Char8 * Mezzanine::Resource::MemoryStreamBuffer::GetBufferEnd ( ) const

Gets the end of this buffer.

Returns
Returns a pointer to one passed the last valid element in this buffer.

Definition at line 267 of file memorystream.cpp.

std::streamsize Mezzanine::Resource::MemoryStreamBuffer::GetBufferSize ( ) const

Gets the size of the current buffer being streamed to/from.

Returns
Returns a std::streamsize representing the size of the current buffer, or 0 if one hasn't been initialized.

Definition at line 273 of file memorystream.cpp.

Char8 * Mezzanine::Resource::MemoryStreamBuffer::GetBufferStart ( ) const

Gets the start of this buffer.

Returns
Returns a pointer to the first valid element in this buffer.

Definition at line 261 of file memorystream.cpp.

Boole Mezzanine::Resource::MemoryStreamBuffer::GetFreeBuffer ( ) const

Gets if this should delete it's internal buffer when it is destroyed.

Returns
Returns true if the internal buffer will be deleted when this is destroyed.

Definition at line 308 of file memorystream.cpp.

std::streampos Mezzanine::Resource::MemoryStreamBuffer::GetReadPosition ( ) const
protected

Gets the current position of the read cursor.

Returns
Returns a std::streampos representing the offset of the read position from the start of the stream.

Definition at line 93 of file memorystream.cpp.

std::streampos Mezzanine::Resource::MemoryStreamBuffer::GetWritePosition ( ) const
protected

Gets the current position of the write cursor.

Returns
Returns a std::streampos representing the offset of the write position from the start of the stream.

Definition at line 96 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::imbue ( const std::locale &  loc)
protectedvirtual

Notifies this class that a new locale is being imbued to this streambuf.

Remarks
Does nothing, implemented for ease of future coding.
Parameters
locThe new locale being imbued.

Definition at line 102 of file memorystream.cpp.

int Mezzanine::Resource::MemoryStreamBuffer::overflow ( int  c = traits_type::eof())
protectedvirtual

Writes a character at the current write position without advancing the write position.

Remarks
Generally this method is called when the available writing positions in the stream have been depleted and additional writing spaces can made. In our case, we can't buffer additional data so in the event the stream is expecting more, we should return the error result of EOF.
Parameters
cThe character to be written to the stream.
Returns
Returns the written character, or EOF if there was a failure.

Definition at line 229 of file memorystream.cpp.

int Mezzanine::Resource::MemoryStreamBuffer::pbackfail ( int  c = traits_type::eof())
protectedvirtual

Reverse the last character extraction operation by decrementing the read position and placing the specified character in it's place.

Parameters
cThe character to place into the stream after decrementing the read position.
Returns
Returns the current character at the read position after the operation completes, or EOF in the event of a failure.

Definition at line 206 of file memorystream.cpp.

std::streampos Mezzanine::Resource::MemoryStreamBuffer::seekoff ( std::streamoff  off,
std::ios_base::seekdir  way,
std::ios_base::openmode  which = std::ios_base::in | std::ios_base::out 
)
protectedvirtual

Moves the read and/or write pointers in the stream.

Remarks
Out of bounds positions will be clamped to the closest limit.
Parameters
offThe amount of advance the current position for the operation specified. Negative values will reverse the position.
wayThe base point in the stream to apply the offset to.
whichWhether this should move the read pointer, write pointer, or both.
Returns
Returns the updated read or write position, based on which was provided. Returns the Read position if both were specified.

Definition at line 124 of file memorystream.cpp.

std::streampos Mezzanine::Resource::MemoryStreamBuffer::seekpos ( std::streampos  sp,
std::ios_base::openmode  which = std::ios_base::in | std::ios_base::out 
)
protectedvirtual

Moves the read and/or write pointers to the specified position in the stream.

Remarks
Out of bounds positions will be clamped to the closest limit.
Parameters
spThe index the current position will be moved to.
whichWhether this should move the read pointer, write pointer, or both.
Returns
Returns the updated read or write position, based on which was provided. Returns the Read position if both were specified.

Definition at line 152 of file memorystream.cpp.

std::streambuf * Mezzanine::Resource::MemoryStreamBuffer::setbuf ( char *  s,
std::streamsize  n 
)
protectedvirtual

Sets the buffer to be streamed from.

Parameters
sThe buffer to be wrapped.
nThe size of the buffer being wrapped.
Returns
Returns this on success, or NULL if there is a failure.

Definition at line 108 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::SetBuffer ( char *  Buffer,
const Whole  BufferSize,
const Boole  FreeBuf 
)

Wraps an external buffer for streaming.

Parameters
BufferThe buffer to be wrapped.
BufferSizeThe size of the buffer being wrapped.
FreeBufWhether or not the buffer passed in should be deleted when this stream is destroyed.

Definition at line 246 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStreamBuffer::SetFreeBuffer ( const Boole  FreeBuf)

Sets if this should delete it's internal buffer when it is destroyed.

Parameters
FreeBufWhether or not the buffer passed in should be deleted when this stream is destroyed.

Definition at line 305 of file memorystream.cpp.

std::streamsize Mezzanine::Resource::MemoryStreamBuffer::showmanyc ( )
protectedvirtual

Gets the number of characters remaining that can be safely extracted from this buffer.

Returns
Returns either the number of characters between the current read position and the end of the buffer, or -1 if no buffer is allocated.

Definition at line 173 of file memorystream.cpp.

int Mezzanine::Resource::MemoryStreamBuffer::sync ( )
protectedvirtual

Syncs this stream buffer with it's source.

Remarks
This buffer is the source for this type of stream, so syncing isn't required; making this an empty implementation.

Definition at line 167 of file memorystream.cpp.

int Mezzanine::Resource::MemoryStreamBuffer::uflow ( )
protectedvirtual

Gets the value at the current read position and then increments the read position.

Remarks
Under normal circumstances this method will be used along with underflow to get characters at the end of the sequence safely in the event that more data needs to be buffered. However the spec requires it to always return EOF if underflow also returns EOF. So because of how we have to implement underflow, this methods behavior is quite limited.
Returns
Returns EOF, always.

Definition at line 201 of file memorystream.cpp.

int Mezzanine::Resource::MemoryStreamBuffer::underflow ( )
protectedvirtual

Gets the value at the current read position without incrementing the read position.

Remarks
This method us used by the std::streambuf implementation for some limited amount of error checking for when the end of a stream is reached and it may be possible to access more (such as streaming a file from disk). This functionality doesn't make sense for a buffer located entirely in memory, so we must return the End-Of-File value each time we're at the end of the buffer.
Returns
Returns the current character at the read position or EOF.

Definition at line 191 of file memorystream.cpp.

std::streamsize Mezzanine::Resource::MemoryStreamBuffer::xsgetn ( char *  s,
std::streamsize  n 
)
protectedvirtual

Gets a number of characters starting at the read position and populates an array with them.

Parameters
sA pointer to the array where the read characters will be placed.
nThe number of characters to read.
Returns
This returns the amount of characters retrieved

Definition at line 183 of file memorystream.cpp.

std::streamsize Mezzanine::Resource::MemoryStreamBuffer::xsputn ( const char *  s,
std::streamsize  n 
)
protectedvirtual

Writes a number of characters from a provided buffer to the stream.

Parameters
sThe buffer of characters that will be written to the stream.
nThe number of characters from the provided buffer that will be written to the stream.
Returns
Returns the number of characters successfully written.

Definition at line 221 of file memorystream.cpp.

Member Data Documentation

Char8* Mezzanine::Resource::MemoryStreamBuffer::BufferEnd
protected

A pointer to one passed the last element in the range of this buffer.

Definition at line 70 of file memorystream.h.

Char8* Mezzanine::Resource::MemoryStreamBuffer::BufferStart
protected

A pointer to the start of this memory buffer.

Definition at line 61 of file memorystream.h.

Boole Mezzanine::Resource::MemoryStreamBuffer::FreeBuffer
protected

Stores whether or not the memory allocated will be free'd when this buffer is deleted.

Definition at line 76 of file memorystream.h.

Whole Mezzanine::Resource::MemoryStreamBuffer::OpenMode
protected

A bitfield describing the settings this buffer was opened with.

Definition at line 73 of file memorystream.h.


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