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

This represents a stream to a piece of data, usually a file. More...

#include <datastream.h>

+ Inheritance diagram for Mezzanine::Resource::DataStream:

Public Types

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...
 

Public Member Functions

 DataStream (const UInt16 Flags=SF_Read)
 Class constructor. More...
 
virtual ~DataStream ()
 Class destructor.
 
virtual void Advance (const StreamOff Count)=0
 Advances the position in the stream. More...
 
virtual void Close ()=0
 Closes the stream to the resource.
 
virtual bool EoF () const =0
 Gets whether or not the current position is at the end of the file/stream. More...
 
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 StreamPos GetStreamPosition (bool Read=true)=0
 Gets the current position in this 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...
 
virtual size_t Read (void *Buffer, const size_t &Count)=0
 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. More...
 
virtual void SetStreamPosition (StreamPos Position)=0
 Sets the position of the read and write cursors explicitly. More...
 
virtual void SetStreamPosition (StreamOff Offset, SeekOrigin Origin)=0
 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. More...
 
virtual size_t Write (const void *Buffer, const size_t &Count)=0
 Writes data from the stream, copying from the provided buffer. More...
 

Protected Attributes

UInt16 SFlags
 The type of access this stream has to the resource.
 
StreamSize Size
 The size of the stream.
 

Detailed Description

This represents a stream to a piece of data, usually a file.

This is a base class that can be overriden to read from a variey of sources including data in memory, and archive files.

Definition at line 214 of file datastream.h.

Member Enumeration Documentation

An enum describing which position should be considered the origin for changing the current position in a stream.

Enumerator
SO_Beginning 

The beginning of the stream.

SO_Current 

The current position for read/write operations in the stream.

SO_End 

The end of the stream.

Definition at line 233 of file datastream.h.

This enum describes the flags that control certain behaviors of a stream.

It is important to note that not all of these flags are used by all streams.

Enumerator
SF_None 

Error/no special initialization.

SF_Read 

Permit read operations on the stream.

SF_Write 

Permit write operations on the stream.

SF_Append 

All write operations on the stream are done at the end of the stream.

SF_AtEnd 

Moves the starting position of the stream to the end upon initialization.

SF_Binary 

Tell the stream that the file in question is Binary.

SF_Truncate 

Clear the contents of the file when opening. Note that this will also create the file if it's not found.

Definition at line 220 of file datastream.h.

Constructor & Destructor Documentation

Mezzanine::Resource::DataStream::DataStream ( const UInt16  Flags = SF_Read)

Class constructor.

Parameters
FlagsThe flags to use when initializing the stream.

Definition at line 84 of file datastream.cpp.

Member Function Documentation

virtual void Mezzanine::Resource::DataStream::Advance ( const StreamOff  Count)
pure virtual

Advances the position in the stream.

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

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

virtual bool Mezzanine::Resource::DataStream::EoF ( ) const
pure 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.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

String Mezzanine::Resource::DataStream::GetAsString ( )
virtual

Gets the contents of the stream as a string.

Returns
Returns a string with the contents of the stream.

Definition at line 118 of file datastream.cpp.

String Mezzanine::Resource::DataStream::GetLine ( bool  Trim = true)
virtual

Gets the contents of the current line in the stream.

Parameters
TrimWhether or not to trim whitespaces on both sides of the string.
Returns
Returns a string containing characters from the current position in the stream to the end of the line.

Definition at line 178 of file datastream.cpp.

StreamSize Mezzanine::Resource::DataStream::GetSize ( ) const
virtual

Gets the size of the stream.

Returns
Returns the size of this stream in bytes.

Definition at line 97 of file datastream.cpp.

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

Gets the current position in this stream.

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.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

bool Mezzanine::Resource::DataStream::IsReadable ( ) const
virtual

Gets whether this stream can be read.

Returns
Returns true if this stream is in reading mode, false otherwise.

Definition at line 102 of file datastream.cpp.

bool Mezzanine::Resource::DataStream::IsWriteable ( ) const
virtual

Gets whether this stream can be written to.

Returns
Returns true if this stream is in writing mode, false otherwise.

Definition at line 107 of file datastream.cpp.

virtual size_t Mezzanine::Resource::DataStream::Read ( void *  Buffer,
const size_t &  Count 
)
pure 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.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

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

Reads a single line from a string.

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.

Reimplemented in Mezzanine::Resource::MemoryStream.

Definition at line 134 of file datastream.cpp.

virtual void Mezzanine::Resource::DataStream::SetStreamPosition ( StreamPos  Position)
pure virtual

Sets the position of the read and write cursors explicitly.

Parameters
PositionThe position to be set.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

virtual void Mezzanine::Resource::DataStream::SetStreamPosition ( StreamOff  Offset,
SeekOrigin  Origin 
)
pure 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.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.

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

Moves the current position to the start of the next line.

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

Reimplemented in Mezzanine::Resource::MemoryStream.

Definition at line 215 of file datastream.cpp.

virtual size_t Mezzanine::Resource::DataStream::Write ( const void *  Buffer,
const size_t &  Count 
)
pure 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.

Implemented in Mezzanine::Resource::MemoryStream, and Mezzanine::Resource::FileStream.


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