xoreos  0.0.5
Public Member Functions | Private Attributes | List of all members
Common::MemoryReadStream Class Reference

Simple memory based 'stream', which implements the ReadStream interface for a plain memory block. More...

#include <memreadstream.h>

Inheritance diagram for Common::MemoryReadStream:
Inheritance graph
[legend]
Collaboration diagram for Common::MemoryReadStream:
Collaboration graph
[legend]

Public Member Functions

 MemoryReadStream (const byte *dataPtr, size_t dataSize, bool disposeMemory=false)
 This constructor takes a pointer to a memory buffer and a length, and wraps it. More...
 
 MemoryReadStream (const char *str, bool useTerminator=false)
 Create a MemoryReadStream around a static string buffer, optionally including the terminating \0. More...
 
template<size_t N>
 MemoryReadStream (const byte(&array)[N])
 Template constructor to create a MemoryReadStream around a static array buffer. More...
 
 ~MemoryReadStream ()
 
size_t read (void *dataPtr, size_t dataSize)
 Read data from the stream. More...
 
bool eos () const
 Returns true if a read failed because the stream has been reached. More...
 
size_t pos () const
 Obtains the current value of the stream position indicator of the stream. More...
 
size_t size () const
 Obtains the total size of the stream, measured in bytes. More...
 
size_t seek (ptrdiff_t offset, Origin whence=kOriginBegin)
 Sets the stream position indicator for the stream. More...
 
const bytegetData () const
 
- Public Member Functions inherited from Common::SeekableReadStream
 SeekableReadStream ()
 
 ~SeekableReadStream ()
 
virtual size_t skip (ptrdiff_t offset)
 Skip the specified number of bytes, adding that offset to the current position in the stream. More...
 
- Public Member Functions inherited from Common::ReadStream
 ReadStream ()
 
virtual ~ReadStream ()
 
byte readByte ()
 Read an unsigned byte from the stream and return it. More...
 
FORCEINLINE int8 readSByte ()
 Read a signed byte from the stream and return it. More...
 
uint32 readChar ()
 Reads the next character from stream and returns it as an unsigned char cast to an uint32, or kEOF on end of file or error. More...
 
uint16 readUint16LE ()
 Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint32 readUint32LE ()
 Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint64 readUint64LE ()
 Read an unsigned 64-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint16 readUint16BE ()
 Read an unsigned 16-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
uint32 readUint32BE ()
 Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
uint64 readUint64BE ()
 Read an unsigned 64-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int16 readSint16LE ()
 Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int32 readSint32LE ()
 Read a signed 32-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int64 readSint64LE ()
 Read a signed 64-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int16 readSint16BE ()
 Read a signed 16-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int32 readSint32BE ()
 Read a signed 32-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int64 readSint64BE ()
 Read a signed 64-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE float readIEEEFloatLE ()
 Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE float readIEEEFloatBE ()
 Read a 32-bit IEEE float stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE double readIEEEDoubleLE ()
 Read a 64-bit IEEE double stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE double readIEEEDoubleBE ()
 Read a 64-bit IEEE double stored in big endian (MSB first) order from the stream and return it. More...
 
MemoryReadStreamreadStream (size_t dataSize)
 Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStream. More...
 

Private Attributes

DisposableArray< const byte_ptrOrig
 
const byte_ptr
 
const size_t _size
 
size_t _pos
 
bool _eos
 

Additional Inherited Members

- Public Types inherited from Common::SeekableReadStream
enum  Origin { kOriginBegin = 0, kOriginCurrent = 1, kOriginEnd = 2, kOriginMAX }
 The position a seeking offset takes as a base. More...
 
- Static Public Member Functions inherited from Common::SeekableReadStream
static size_t evalSeek (ptrdiff_t offset, Origin whence, size_t pos, size_t begin, size_t size)
 Evaluate the seek offset relative to whence into a position from the beginning. More...
 
- Static Public Attributes inherited from Common::ReadStream
static const uint32 kEOF = 0xFFFFFFFF
 Return value for end-of-file. More...
 
static const size_t kSizeInvalid = SIZE_MAX
 
static const size_t kPositionInvalid = SIZE_MAX
 

Detailed Description

Simple memory based 'stream', which implements the ReadStream interface for a plain memory block.

Definition at line 66 of file memreadstream.h.

Constructor & Destructor Documentation

◆ MemoryReadStream() [1/3]

Common::MemoryReadStream::MemoryReadStream ( const byte dataPtr,
size_t  dataSize,
bool  disposeMemory = false 
)
inline

This constructor takes a pointer to a memory buffer and a length, and wraps it.

If disposeMemory is true, the MemoryReadStream takes ownership of the buffer and hence delete[]'s it when destructed.

Definition at line 71 of file memreadstream.h.

◆ MemoryReadStream() [2/3]

Common::MemoryReadStream::MemoryReadStream ( const char *  str,
bool  useTerminator = false 
)
inline

Create a MemoryReadStream around a static string buffer, optionally including the terminating \0.

Never disposes its memory.

Definition at line 78 of file memreadstream.h.

◆ MemoryReadStream() [3/3]

template<size_t N>
Common::MemoryReadStream::MemoryReadStream ( const byte(&)  array[N])
inline

Template constructor to create a MemoryReadStream around a static array buffer.

Never disposes its memory.

Definition at line 87 of file memreadstream.h.

◆ ~MemoryReadStream()

Common::MemoryReadStream::~MemoryReadStream ( )
inline

Definition at line 92 of file memreadstream.h.

Member Function Documentation

◆ eos()

bool Common::MemoryReadStream::eos ( ) const
virtual

Returns true if a read failed because the stream has been reached.

For a SeekableReadStream, it is cleared by a successful seek.

Implements Common::ReadStream.

Definition at line 92 of file memreadstream.cpp.

References _eos.

◆ getData()

const byte * Common::MemoryReadStream::getData ( ) const

Definition at line 104 of file memreadstream.cpp.

References _ptrOrig, and Common::DisposablePtrBase< T, Deallocator >::get().

Referenced by Aurora::ERFFile::decompressBiowareZlib(), Aurora::ERFFile::decompressHeaderlessZlib(), Aurora::ERFFile::decompressStandardZlib(), and Aurora::Lua::ScriptManager::executeFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pos()

size_t Common::MemoryReadStream::pos ( ) const
virtual

Obtains the current value of the stream position indicator of the stream.

Returns
the current position indicator, or kPositionInvalid if an error occurred.

Implements Common::SeekableReadStream.

Definition at line 96 of file memreadstream.cpp.

References _pos.

◆ read()

size_t Common::MemoryReadStream::read ( void *  dataPtr,
size_t  dataSize 
)
virtual

Read data from the stream.

Subclasses must implement this method; all other read methods are implemented using it.

Parameters
dataPtrpointer to a buffer into which the data is read.
dataSizenumber of bytes to be read.
Returns
the number of bytes which were actually read.

Implements Common::ReadStream.

Definition at line 59 of file memreadstream.cpp.

References _eos, _pos, _ptr, and _size.

◆ seek()

size_t Common::MemoryReadStream::seek ( ptrdiff_t  offset,
Origin  whence = kOriginBegin 
)
virtual

Sets the stream position indicator for the stream.

The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to kOriginBegin, kOriginCurrent, or kOriginEnd, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively. A successful call to the seek() method clears the end-of-file indicator for the stream.

On error, or when trying to seek outside the stream, a kSeekError exception is thrown.

Parameters
offsetthe relative offset in bytes.
whencethe seek reference: kOriginBegin, kOriginCurrent or kOriginEnd.
Returns
the previous position of the stream, before seeking.

Implements Common::SeekableReadStream.

Definition at line 75 of file memreadstream.cpp.

References _eos, _pos, _ptr, _ptrOrig, _size, Common::SeekableReadStream::evalSeek(), Common::DisposablePtrBase< T, Deallocator >::get(), Common::kSeekError, and size().

Here is the call graph for this function:

◆ size()

size_t Common::MemoryReadStream::size ( ) const
virtual

Obtains the total size of the stream, measured in bytes.

If this value is unknown or can not be computed, kSizeInvalid is returned.

Returns
the size of the stream, or kSizeInvalid if an error occurred.

Implements Common::SeekableReadStream.

Definition at line 100 of file memreadstream.cpp.

References _size.

Referenced by Aurora::ERFFile::decompress(), Aurora::ERFFile::decompressBiowareZlib(), Aurora::ERFFile::decompressHeaderlessZlib(), Aurora::ERFFile::decompressStandardZlib(), Aurora::Lua::ScriptManager::executeFile(), and seek().

Here is the caller graph for this function:

Member Data Documentation

◆ _eos

bool Common::MemoryReadStream::_eos
private

Definition at line 113 of file memreadstream.h.

Referenced by eos(), read(), and seek().

◆ _pos

size_t Common::MemoryReadStream::_pos
private

Definition at line 111 of file memreadstream.h.

Referenced by pos(), read(), and seek().

◆ _ptr

const byte* Common::MemoryReadStream::_ptr
private

Definition at line 107 of file memreadstream.h.

Referenced by read(), and seek().

◆ _ptrOrig

DisposableArray<const byte> Common::MemoryReadStream::_ptrOrig
private

Definition at line 106 of file memreadstream.h.

Referenced by getData(), and seek().

◆ _size

const size_t Common::MemoryReadStream::_size
private

Definition at line 109 of file memreadstream.h.

Referenced by read(), seek(), and size().


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