70 if (
read(buf.
get(), dataSize) != dataSize)
86 offset =
size + offset;
89 return begin + offset;
97 throw Exception(
"Invalid whence (%d)", (
int) whence);
102 _parentStream(parentStream, disposeParentStream), _pos(0), _end(end), _eos(false) {
104 assert(parentStream);
115 if (dataSize > (
size_t)(
_end -
_pos)) {
128 size_t end,
bool disposeParentStream) :
129 SubReadStream(parentStream, end, disposeParentStream), _parentStream(parentStream), _begin(begin) {
152 const size_t oldPos =
_pos;
167 size_t begin,
size_t end,
bool bigEndian,
bool disposeParentStream) :
~SeekableSubReadStreamEndian()
Generic interface for a readable data stream.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
DisposablePtr< ReadStream > _parentStream
MemoryReadStream * readStream(size_t dataSize)
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStrea...
Implementing the reading stream interfaces for plain memory blocks.
size_t pos() const
Obtains the current value of the stream position indicator of the stream.
static const uint32 kEOF
Return value for end-of-file.
size_t size() const
Obtains the total size of the stream, measured in bytes.
Seek from the end of the stream.
A simple scoped smart pointer template.
Origin
The position a seeking offset takes as a base.
Basic exceptions to throw.
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
SubReadStream(ReadStream *parentStream, size_t end, bool disposeParentStream=false)
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
Simple memory based 'stream', which implements the ReadStream interface for a plain memory block...
const Exception kReadError("Read error")
Exception when reading from a stream failed.
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
Basic reading stream interfaces.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
size_t read(void *dataPtr, size_t dataSize)
Read data from the stream.
Seek from the current position of the stream.
#define XOREOS_FALLTHROUGH
SeekableSubReadStreamEndian(SeekableReadStream *parentStream, size_t begin, size_t end, bool bigEndian=false, bool disposeParentStream=false)
PointerType get() const
Returns the plain pointer value.
const Exception kSeekError("Seek error")
Exception when seeking a stream failed.
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.
SeekableSubReadStream(SeekableReadStream *parentStream, size_t begin, size_t end, bool disposeParentStream=false)
bool eos() const
Returns true if a read failed because the stream has been reached.
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
Seek from the begin of the stream.
SeekableReadStream * _parentStream
SubReadStream provides access to a ReadStream restricted to the range [currentPosition, currentPosition+end).
Interface for a seekable & readable data stream.