ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Common::MemoryReadStream Class Reference

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

#include <memstream.h>

Inheritance diagram for Common::MemoryReadStream:
Collaboration diagram for Common::MemoryReadStream:

List of all members.

Public Member Functions

 MemoryReadStream (const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory=DisposeAfterUse::NO)
 This constructor takes a pointer to a memory buffer and a length, and wraps it.
 ~MemoryReadStream ()
uint32 read (void *dataPtr, uint32 dataSize)
 Read data from the stream.
bool eos () const
 Returns true if a read failed because the stream end has been reached.
void clearErr ()
 Reset the I/O error status as returned by err().
int32 pos () const
 Obtains the current value of the stream position indicator of the stream.
int32 size () const
 Obtains the total size of the stream, measured in bytes.
bool seek (int32 offs, int whence=SEEK_SET)
 Sets the stream position indicator for the stream.

Private Attributes

const byte *const _ptrOrig
const byte_ptr
const uint32 _size
uint32 _pos
DisposeAfterUse::Flag _disposeMemory
bool _eos

Detailed Description

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

Definition at line 36 of file memstream.h.


Constructor & Destructor Documentation

Common::MemoryReadStream::MemoryReadStream ( const byte dataPtr,
uint32  dataSize,
DisposeAfterUse::Flag  disposeMemory = DisposeAfterUse::NO 
) [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 free's it when destructed.

Definition at line 52 of file memstream.h.

Common::MemoryReadStream::~MemoryReadStream (  )  [inline]

Definition at line 60 of file memstream.h.


Member Function Documentation

void Common::MemoryReadStream::clearErr (  )  [inline, virtual]

Reset the I/O error status as returned by err().

For a ReadStream, also reset the end-of-stream status returned by eos().

Note:
The semantics of any implementation of this method are supposed to match those of ISO C clearerr().

Reimplemented from Common::Stream.

Definition at line 68 of file memstream.h.

bool Common::MemoryReadStream::eos (  )  const [inline, virtual]

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

This flag is cleared by clearErr(). For a SeekableReadStream, it is also cleared by a successful seek.

Note:
The semantics of any implementation of this method are supposed to match those of ISO C feof(). In particular, in a stream with N bytes, reading exactly N bytes from the start should *not* set eos; only reading *beyond* the available data should set it.

Implements Common::ReadStream.

Definition at line 67 of file memstream.h.

int32 Common::MemoryReadStream::pos (  )  const [inline, virtual]

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

Returns:
the current position indicator, or -1 if an error occurred.

Implements Common::SeekableReadStream.

Definition at line 70 of file memstream.h.

uint32 Common::MemoryReadStream::read ( void *  dataPtr,
uint32  dataSize 
) [virtual]

Read data from the stream.

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

Note:
The semantics of any implementation of this method are supposed to match those of ISO C fread(), in particular where it concerns setting error and end of file/stream flags.
Parameters:
dataPtr pointer to a buffer into which the data is read
dataSize number of bytes to be read
Returns:
the number of bytes which were actually read.

Implements Common::ReadStream.

Definition at line 64 of file stream.cpp.

bool Common::MemoryReadStream::seek ( int32  offset,
int  whence = SEEK_SET 
) [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 SEEK_SET, SEEK_CUR, or SEEK_END, 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.

Note:
The semantics of any implementation of this method are supposed to match those of ISO C fseek().
Parameters:
offset the relative offset in bytes
whence the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
Returns:
true on success, false in case of a failure

Implements Common::SeekableReadStream.

Definition at line 78 of file stream.cpp.

int32 Common::MemoryReadStream::size (  )  const [inline, virtual]

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

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

Returns:
the size of the stream, or -1 if an error occurred

Implements Common::SeekableReadStream.

Definition at line 71 of file memstream.h.


Member Data Documentation

Definition at line 43 of file memstream.h.

Definition at line 41 of file memstream.h.

Definition at line 39 of file memstream.h.

const byte* const Common::MemoryReadStream::_ptrOrig [private]

Definition at line 38 of file memstream.h.

Definition at line 40 of file memstream.h.


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


Generated on Sat Jul 20 2019 05:02:50 for ResidualVM by doxygen 1.7.1
curved edge   curved edge