MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
Mezzanine::Resource::MemoryStream Class Reference

This represents a stream to a buffer in memory. More...

#include <memorystream.h>

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

Public Member Functions

 MemoryStream (const size_t &BufferSize, bool FreeOnClose=true, bool ReadOnly=false)
 Buffer creation constructor. More...
 
 MemoryStream (void *Buffer, const size_t &BufferSize, bool FreeOnClose=false, bool ReadOnly=false)
 Pre-made buffer constructor. More...
 
virtual ~MemoryStream ()
 Class destructor.
 
virtual void Advance (const StreamOff Count)
 Advances the position in the stream. More...
 
virtual void Close ()
 Closes the stream to the resource. More...
 
virtual bool EoF () const
 Gets whether or not the current position is at the end of the file/stream. More...
 
UInt8GetBufferEnd () const
 Gets a pointer to the end of the memory buffer used by this stream. More...
 
UInt8GetBufferPosition () const
 Gets a pointer to the current position in the memory buffer used by this stream. More...
 
UInt8GetBufferStart () const
 Gets a pointer to the start of the memory buffer used by this stream. More...
 
virtual StreamPos GetStreamPosition (bool Read=true)
 Gets the current position in this stream. (bool Read = true) More...
 
virtual size_t Read (void *Buffer, const size_t &Count)
 Reads data from the stream, copying to a buffer. More...
 
virtual size_t ReadLine (Char8 *Buffer, size_t MaxCount, const String &Delim="\n")
 Reads a single line from a string. (Char8* Buffer, size_t MaxCount, const String& Delim = "\n") More...
 
void SetFreeOnClose (bool FreeOnClose)
 Sets whether or not you want this stream to free the memory buffer when it closes. More...
 
virtual void SetStreamPosition (StreamPos Position)
 Sets the position of the read and write cursors explicitly. More...
 
virtual void SetStreamPosition (StreamOff Offset, SeekOrigin Origin)
 Sets the position of the read and write cursors. More...
 
virtual size_t SkipLine (const String &Delim="\n")
 Moves the current position to the start of the next line. (const String& Delim = "\n") More...
 
virtual size_t Write (const void *Buffer, const size_t &Count)
 Writes data from the stream, copying from the provided buffer. More...
 
- Public Member Functions inherited from Mezzanine::Resource::DataStream
 DataStream (const UInt16 Flags=SF_Read)
 Class constructor. More...
 
virtual ~DataStream ()
 Class destructor.
 
virtual String GetAsString ()
 Gets the contents of the stream as a string. More...
 
virtual String GetLine (bool Trim=true)
 Gets the contents of the current line in the stream. More...
 
virtual StreamSize GetSize () const
 Gets the size of the stream. More...
 
virtual bool IsReadable () const
 Gets whether this stream can be read. More...
 
virtual bool IsWriteable () const
 Gets whether this stream can be written to. More...
 

Protected Attributes

UInt8BufferEnd
 
UInt8BufferPos
 
UInt8BufferStart
 
bool FreeBuffer
 
- Protected Attributes inherited from Mezzanine::Resource::DataStream
UInt16 SFlags
 The type of access this stream has to the resource.
 
StreamSize Size
 The size of the stream.
 

Additional Inherited Members

- Public Types inherited from Mezzanine::Resource::DataStream
enum  SeekOrigin { SO_Beginning = std::ios_base::beg, SO_Current = std::ios_base::cur, SO_End = std::ios_base::end }
 An enum describing which position should be considered the origin for changing the current position in a stream. More...
 
enum  StreamFlags {
  SF_None = 0, SF_Read = 1, SF_Write = 2, SF_Append = 4,
  SF_AtEnd = 8, SF_Binary = 16, SF_Truncate = 32
}
 This enum describes the flags that control certain behaviors of a stream. More...
 

Detailed Description

This represents a stream to a buffer in memory.

Definition at line 59 of file memorystream.h.

Constructor & Destructor Documentation

Mezzanine::Resource::MemoryStream::MemoryStream ( const size_t &  BufferSize,
bool  FreeOnClose = true,
bool  ReadOnly = false 
)

Buffer creation constructor.

Parameters
BufferSizeThe size of the buffer to be created.
FreeOnCloseIf true this will delete the memory buffer when the stream is closed.
ReadOnlyIf true, writing operations on this stream will be prohibited.

Definition at line 57 of file memorystream.cpp.

Mezzanine::Resource::MemoryStream::MemoryStream ( void *  Buffer,
const size_t &  BufferSize,
bool  FreeOnClose = false,
bool  ReadOnly = false 
)

Pre-made buffer constructor.

Parameters
BufferThe premade buffer to stream from.
BufferSizeThe size of the buffer to stream to/from.
FreeOnCloseIf true this will delete the memory buffer when the stream is closed.
ReadOnlyIf true, writing operations on this stream will be prohibited.

Definition at line 70 of file memorystream.cpp.

Member Function Documentation

void Mezzanine::Resource::MemoryStream::Advance ( const StreamOff  Count)
virtual

Advances the position in the stream.

Parameters
CountThe number of bytes to skip/advance in the stream from the current position.

Implements Mezzanine::Resource::DataStream.

Definition at line 146 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStream::Close ( )
virtual

Closes the stream to the resource.

Implements Mezzanine::Resource::DataStream.

Definition at line 201 of file memorystream.cpp.

bool Mezzanine::Resource::MemoryStream::EoF ( ) const
virtual

Gets whether or not the current position is at the end of the file/stream.

Returns
Returns true if the current position has reached the end of the stream, false otherwise.

Implements Mezzanine::Resource::DataStream.

Definition at line 196 of file memorystream.cpp.

UInt8 * Mezzanine::Resource::MemoryStream::GetBufferEnd ( ) const

Gets a pointer to the end of the memory buffer used by this stream.

Returns
Returns a pointer to the end of the memory buffer.

Definition at line 100 of file memorystream.cpp.

UInt8 * Mezzanine::Resource::MemoryStream::GetBufferPosition ( ) const

Gets a pointer to the current position in the memory buffer used by this stream.

Returns
Returns a pointer to the current position in the memory buffer.

Definition at line 95 of file memorystream.cpp.

UInt8 * Mezzanine::Resource::MemoryStream::GetBufferStart ( ) const

Gets a pointer to the start of the memory buffer used by this stream.

Returns
Returns a pointer to the start of the memory buffer.

Definition at line 90 of file memorystream.cpp.

StreamPos Mezzanine::Resource::MemoryStream::GetStreamPosition ( bool  Read = true)
virtual

Gets the current position in this stream. (bool Read = true)

Parameters
ReadWhether or not to get the Read position. If false this will get the write position instead.
Returns
Returns a StreamPos representing the current position specified from the beginning of the stream.

(bool Read = true)

Implements Mezzanine::Resource::DataStream.

Definition at line 191 of file memorystream.cpp.

size_t Mezzanine::Resource::MemoryStream::Read ( void *  Buffer,
const size_t &  Count 
)
virtual

Reads data from the stream, copying to a buffer.

Parameters
BufferThe buffer to place data from the stream.
CountThe number of bytes to read from the stream.
Returns
Returns the number of bytes read.

Implements Mezzanine::Resource::DataStream.

Definition at line 113 of file memorystream.cpp.

size_t Mezzanine::Resource::MemoryStream::ReadLine ( Char8 Buffer,
size_t  MaxCount,
const String Delim = "\n" 
)
virtual

Reads a single line from a string. (Char8* Buffer, size_t MaxCount, const String& Delim = "\n")

Parameters
BufferPointer to the buffer to copy to.
MaxCountThe maximum number of bytes to read. Usually you want this to be your buffer size.
DelimThe character that marks the end of a line.
Returns
Returns the number of bytes actually read, not including the Delimiter.

(Char8* Buffer, size_t MaxCount, const String& Delim = "\n")

Reimplemented from Mezzanine::Resource::DataStream.

Definition at line 215 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStream::SetFreeOnClose ( bool  FreeOnClose)

Sets whether or not you want this stream to free the memory buffer when it closes.

Parameters
Trueif you want this stream to free the buffer when it closes, false if you want it preserved.

Definition at line 105 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStream::SetStreamPosition ( StreamPos  Position)
virtual

Sets the position of the read and write cursors explicitly.

Parameters
PositionThe position to be set.

Implements Mezzanine::Resource::DataStream.

Definition at line 155 of file memorystream.cpp.

void Mezzanine::Resource::MemoryStream::SetStreamPosition ( StreamOff  Offset,
SeekOrigin  Origin 
)
virtual

Sets the position of the read and write cursors.

Parameters
OffsetThe number of bytes to move the cursors back(if negative) or forward(if positive).
OriginThe starting point to be considered for the offset.

Implements Mezzanine::Resource::DataStream.

Definition at line 163 of file memorystream.cpp.

size_t Mezzanine::Resource::MemoryStream::SkipLine ( const String Delim = "\n")
virtual

Moves the current position to the start of the next line. (const String& Delim = "\n")

Parameters
DelimThe character that marks the end of a line.
Returns
Returns the number of bytes skipped.

(const String& Delim = "\n")

Reimplemented from Mezzanine::Resource::DataStream.

Definition at line 242 of file memorystream.cpp.

size_t Mezzanine::Resource::MemoryStream::Write ( const void *  Buffer,
const size_t &  Count 
)
virtual

Writes data from the stream, copying from the provided buffer.

Parameters
BufferThe buffer of data to be written.
CountThe number of bytes to write from the buffer to the stream.
Returns
Returns the number of bytes written.

Implements Mezzanine::Resource::DataStream.

Definition at line 129 of file memorystream.cpp.


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