50 #ifndef COMMON_READSTREAM_H 51 #define COMMON_READSTREAM_H 61 class MemoryReadStream;
78 virtual bool eos()
const = 0;
87 virtual size_t read(
void *dataPtr,
size_t dataSize) = 0;
124 if (
read(&val, 2) != 2)
127 return FROM_LE_16(val);
135 if (
read(&val, 4) != 4)
138 return FROM_LE_32(val);
146 if (
read(&val, 8) != 8)
149 return FROM_LE_64(val);
157 if (
read(&val, 2) != 2)
160 return FROM_BE_16(val);
168 if (
read(&val, 4) != 4)
171 return FROM_BE_32(val);
179 if (
read(&val, 8) != 8)
182 return FROM_BE_64(val);
282 virtual size_t pos()
const = 0;
289 virtual size_t size()
const = 0;
317 virtual size_t skip(ptrdiff_t offset) {
340 size_t read(
void *dataPtr,
size_t dataSize);
362 bool disposeParentStream =
false);
389 bool bigEndian =
false,
bool disposeParentStream =
false);
427 #endif // COMMON_READSTREAM_H ~SeekableSubReadStreamEndian()
FORCEINLINE int64 readSint64LE()
Read a signed 64-bit word stored in little endian (LSB first) order from the stream and return it...
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
Generic interface for a readable data stream.
This is a wrapper around SeekableSubReadStream, but it adds non-endian read methods whose endianness ...
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
uint64 readUint64BE()
Read an unsigned 64-bit word stored in big endian (MSB first) order from the stream and return it...
static const size_t kPositionInvalid
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...
FORCEINLINE int32 readSint32BE()
Read a signed 32-bit word stored in big endian (MSB first) order from the stream and return it...
FORCEINLINE int8 readSByte()
Read a signed byte from the stream and return it.
virtual bool eos() const =0
Returns true if a read failed because the stream has been reached.
Low-level macros and functions to handle different endianness portably.
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.
FORCEINLINE double readIEEEDoubleBE()
Read a 64-bit IEEE double stored in big endian (MSB first) order from the stream and return it...
double convertIEEEDouble(uint64 data)
Convert a uint64 holding the bit pattern of a 64-bit IEEE 754 double precision floating point value i...
FORCEINLINE int32 readSint32LE()
Read a signed 32-bit word stored in little endian (LSB first) order from the stream and return it...
size_t size() const
Obtains the total size of the stream, measured in bytes.
Seek from the end of the stream.
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.
Utility templates and functions.
uint16 readUint16BE()
Read an unsigned 16-bit word stored in big endian (MSB first) order from the stream and return it...
SubReadStream(ReadStream *parentStream, size_t end, bool disposeParentStream=false)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
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...
Low-level type definitions to handle fixed width types portably.
static const size_t kSizeInvalid
const Exception kReadError("Read error")
Exception when reading from a stream failed.
FORCEINLINE int16 readSint16LE()
Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it...
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
uint64 readUint64LE()
Read an unsigned 64-bit word stored in little endian (LSB first) order from the stream and return it...
A disposable plain pointer, allowing pointer-y access and normal deletion.
size_t read(void *dataPtr, size_t dataSize)
Read data from the stream.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
Seek from the current position of the stream.
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
FORCEINLINE int16 readSint16BE()
Read a signed 16-bit word stored in big endian (MSB first) order from the stream and return it...
SeekableSubReadStreamEndian(SeekableReadStream *parentStream, size_t begin, size_t end, bool bigEndian=false, bool disposeParentStream=false)
A smart pointer with a deletion flag.
FORCEINLINE int64 readSint64BE()
Read a signed 64-bit word stored in big endian (MSB first) order from the stream and return it...
float convertIEEEFloat(uint32 data)
Convert a uint32 holding the bit pattern of a 32-bit IEEE 754 single precision floating point value i...
FORCEINLINE double readIEEEDoubleLE()
Read a 64-bit IEEE double stored in little endian (LSB first) order from the stream and return it...
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)
uint32 readChar()
Reads the next character from stream and returns it as an unsigned char cast to an uint32...
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.
byte readByte()
Read an unsigned byte from the stream and return it.
FORCEINLINE float readIEEEFloatBE()
Read a 32-bit IEEE float stored in big endian (MSB first) order from the stream and return it...