Abstract seekable stream class. More...
#include <mitsuba/core/stream.h>
Public Types | |
enum | EByteOrder { EBigEndian = 0, ELittleEndian = 1, ENetworkByteOrder = EBigEndian } |
Defines the byte order to use in this Stream. More... | |
Public Member Functions | |
Stream () | |
Create a new stream. More... | |
virtual std::string | toString () const |
Return a string representation. More... | |
virtual const Class * | getClass () const |
Retrieve this object's class. More... | |
Abstract methods that need to be implemented by subclasses | |
virtual void | read (void *ptr, size_t size)=0 |
Read a specified amount of data from the stream. More... | |
virtual void | write (const void *ptr, size_t size)=0 |
Write a specified amount of data into the stream. More... | |
virtual void | seek (size_t pos)=0 |
Seek to a position inside the stream. More... | |
virtual void | truncate (size_t size)=0 |
Truncate the stream to a given size. More... | |
virtual size_t | getPos () const =0 |
Get the current position inside the stream. More... | |
virtual size_t | getSize () const =0 |
Return the size of the stream. More... | |
virtual void | flush ()=0 |
Flush the stream's buffers. More... | |
virtual bool | canWrite () const =0 |
Can we write to the stream? More... | |
virtual bool | canRead () const =0 |
Can we read from the stream? More... | |
Convenience functions with automatic endianness conversion | |
void | skip (size_t amount) |
Skip the given number of bytes. More... | |
void | writeString (const std::string &value) |
Write a null-terminated string to the stream. More... | |
void | writeLine (const std::string &value) |
Write a string followed by a newline. More... | |
void | writeShort (short value) |
Write a signed short (16 bit) to the stream. More... | |
void | writeShortArray (const short *values, size_t size) |
Write an array of signed shorts (16 bit) to the stream. More... | |
template<size_t N> | |
void | writeShortArray (const short(&values)[N]) |
Write an array of known size of signed shorts (16 bit) to the stream. More... | |
void | writeUShort (unsigned short value) |
Write an unsigned short (16 bit) to the stream. More... | |
void | writeUShortArray (const unsigned short *values, size_t size) |
Write an array of unsigned shorts (16 bit) to the stream. More... | |
template<size_t N> | |
void | writeUShortArray (const unsigned short(&values)[N]) |
Write an array of known size of unsigned shorts (16 bit) to the stream. More... | |
void | writeInt (int value) |
Write a signed int (32 bit) to the stream. More... | |
void | writeIntArray (const int *values, size_t size) |
Write an array of signed ints (32 bit) to the stream. More... | |
template<size_t N> | |
void | writeIntArray (const int(&values)[N]) |
Write an array of known size of signed ints (32 bit) to the stream. More... | |
void | writeUInt (unsigned int value) |
Write an unsigned int (32 bit) to the stream. More... | |
void | writeUIntArray (const unsigned int *values, size_t size) |
Write an array of unsigned ints (32 bit) to the stream. More... | |
template<size_t N> | |
void | writeUIntArray (const unsigned int(&values)[N]) |
Write an array of known size of unsigned ints (32 bit) to the stream. More... | |
void | writeLong (int64_t value) |
Write a signed int (64 bit) to the stream. More... | |
void | writeLongArray (const int64_t *values, size_t size) |
Write an array of signed ints (64 bit) to the stream. More... | |
template<size_t N> | |
void | writeLongArray (const int64_t(&values)[N]) |
Write an array of known size of signed ints (64 bit) to the stream. More... | |
void | writeULong (uint64_t value) |
Write an unsigned int (64 bit) to the stream. More... | |
void | writeSize (size_t value) |
Write a size value to the stream. More... | |
void | writeULongArray (const uint64_t *values, size_t size) |
Write an array of unsigned ints (64 bit) to the stream. More... | |
template<size_t N> | |
void | writeULongArray (const uint64_t(&values)[N]) |
Write an array of known size of unsigned ints (64 bit) to the stream. More... | |
void | writeChar (char value) |
Write a signed character (8 bit) to the stream. More... | |
void | writeUChar (unsigned char value) |
Write an unsigned character (8 bit) to the stream. More... | |
void | writeBool (bool value) |
Write a boolean (8 bit) to the stream. More... | |
void | writeHalf (half value) |
Write a half-precision floating point number (16 bit) to the stream. More... | |
void | writeHalfArray (const half *data, size_t size) |
Write a half-precision floating point array (16 bit) to the stream. More... | |
template<size_t N> | |
void | writeHalfArray (const half(&values)[N]) |
Write a known size half-precision floating point array (16 bit) to the stream. More... | |
void | writeSingle (float value) |
Write a single-precision floating point number (32 bit) to the stream. More... | |
void | writeSingleArray (const float *data, size_t size) |
Write a single-precision floating point array (32 bit) to the stream. More... | |
template<size_t N> | |
void | writeSingleArray (const float(&values)[N]) |
Write a known size single-precision floating point array (32 bit) to the stream. More... | |
void | writeDouble (double value) |
Write a double-precision floating point number (64 bit) to the stream. More... | |
void | writeDoubleArray (const double *data, size_t size) |
Write a double-precision floating point array (64 bit) to the stream. More... | |
template<size_t N> | |
void | writeDoubleArray (const double(&values)[N]) |
Write a known size double-precision floating point array (64 bit) to the stream. More... | |
void | writeFloat (Float value) |
Write a floating point number (configured precision) to the stream. More... | |
void | writeFloatArray (const Float *data, size_t size) |
Write an array of floating point values (configured precision) to the stream. More... | |
template<size_t N> | |
void | writeFloatArray (const Float(&values)[N]) |
Write a known size array of floating point values (configured precision) to the stream. More... | |
bool | isEOF () const |
Return whether we are at the end of the stream. More... | |
std::string | readLine () |
Read a line from the stream and return it as a string. More... | |
std::string | readString () |
Read a null-terminated string from the stream. More... | |
short | readShort () |
Read a signed short (16 bit) from the stream. More... | |
void | readShortArray (short *dest, size_t size) |
Read an array of signed shorts (16 bit) from the stream. More... | |
template<size_t N> | |
void | readShortArray (short(&values)[N]) |
Read an array of known size of signed shorts (16 bit) from the stream. More... | |
unsigned short | readUShort () |
Read an unsigned short (16 bit) from the stream. More... | |
void | readUShortArray (unsigned short *dest, size_t size) |
Read an array of unsigned shorts (16 bit) from the stream. More... | |
template<size_t N> | |
void | readUShortArray (short(&values)[N]) |
Read an array of known size of unsigned shorts (16 bit) from the stream. More... | |
int | readInt () |
Read a signed int (32 bit) from the stream. More... | |
void | readIntArray (int *dst, size_t size) |
Read an array of signed ints (32 bit) from the stream. More... | |
template<size_t N> | |
void | readIntArray (int(&values)[N]) |
Read an array of known size of signed ints (32 bit) from the stream. More... | |
unsigned int | readUInt () |
Read an unsigned int (32 bit) from the stream. More... | |
void | readUIntArray (unsigned int *dest, size_t size) |
Read an array of unsigned ints (32 bit) from the stream. More... | |
template<size_t N> | |
void | readUIntArray (int(&values)[N]) |
Read an array of known size of unsigned ints (32 bit) from the stream. More... | |
int64_t | readLong () |
Read a signed int (64 bit) from the stream. More... | |
void | readLongArray (int64_t *dst, size_t size) |
Read an array of signed ints (64 bit) from the stream. More... | |
template<size_t N> | |
void | readLongArray (int64_t(&values)[N]) |
Read an array of known size of signed ints (64 bit) from the stream. More... | |
uint64_t | readULong () |
Read an unsigned int (64 bit) from the stream. More... | |
size_t | readSize () |
Read a size value from the stream. More... | |
void | readULongArray (uint64_t *dst, size_t size) |
Read an array of unsigned ints (64 bit) from the stream. More... | |
template<size_t N> | |
void | readULongArray (uint64_t(&values)[N]) |
Read an array of known size of unsigned ints (64 bit) from the stream. More... | |
char | readChar () |
Read a signed character (8 bit) from the stream. More... | |
unsigned char | readUChar () |
Read an unsigned character (8 bit) from the stream. More... | |
bool | readBool () |
Read a boolean (8 bit) from the stream. More... | |
half | readHalf () |
Read a half-precision floating point number (16 bit) from the stream. More... | |
void | readHalfArray (half *data, size_t size) |
Read a half-precision floating point array (16 bit) from the stream. More... | |
template<size_t N> | |
void | readHalfArray (half(&values)[N]) |
Read a known-size half-precision floating point array (16 bit) from the stream. More... | |
float | readSingle () |
Read a single-precision floating point number (32 bit) from the stream. More... | |
void | readSingleArray (float *data, size_t size) |
Read a single-precision floating point array (32 bit) from the stream. More... | |
template<size_t N> | |
void | readSingleArray (float(&values)[N]) |
Read a known-size single-precision floating point array (32 bit) from the stream. More... | |
double | readDouble () |
Read a double-precision floating point number (64 bit) from the stream. More... | |
void | readDoubleArray (double *data, size_t size) |
Read a double-precision floating point array (64 bit) from the stream. More... | |
template<size_t N> | |
void | readDoubleArray (double(&values)[N]) |
Read a known-size double-precision floating point array (64 bit) from the stream. More... | |
Float | readFloat () |
Write a floating point number (configured precision) to the stream. More... | |
void | readFloatArray (Float *data, size_t size) |
Write an array of floating point values (configured precision) to the stream. More... | |
template<size_t N> | |
void | readFloatArray (Float(&values)[N]) |
Read a known-size array of floating point values (configured precision) to the stream. More... | |
void | copyTo (Stream *stream, int64_t numBytes=-1) |
Copy content from this stream into another stream. More... | |
template<typename T > | |
T | readElement () |
Read an element from the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
template<typename T > | |
void | writeElement (T value) |
Write an element to the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
template<typename T > | |
void | readArray (T *array, size_t count) |
Read an array from the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
template<typename T , size_t N> | |
void | readArray (T(&arr)[N]) |
Read a known-size array from the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
template<typename T > | |
void | writeArray (const T *array, size_t count) |
Write an array to the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
template<typename T , size_t N> | |
void | writeArray (const T(&arr)[N]) |
Write a known-size array to the stream (uses partial template specialization to select a method appropriate to the data type) More... | |
Public Member Functions inherited from Object | |
Object () | |
Construct a new object. More... | |
int | getRefCount () const |
Return the current reference count. More... | |
void | incRef () const |
Increase the reference count of the object by one. More... | |
void | decRef (bool autoDeallocate=true) const |
Decrease the reference count of the object and possibly deallocate it. More... | |
Static Public Attributes | |
static Class * | m_theClass |
Static Public Attributes inherited from Object | |
static Class * | m_theClass |
Pointer to the object's class descriptor. More... | |
Protected Member Functions | |
virtual | ~Stream () |
Virtual destructor. More... | |
Protected Member Functions inherited from Object | |
virtual | ~Object () |
Virtual private deconstructor. (Will only be called by ref) More... | |
Endianness-related | |
void | setByteOrder (EByteOrder byteOrder) |
Set the stream byte order. More... | |
EByteOrder | getByteOrder () const |
Return the byte order of this stream. More... | |
static EByteOrder | getHostByteOrder () |
Return the byte order of the underlying machine. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from Object | |
static void | staticInitialization () |
Initializes the built-in reference count debugger (if enabled) More... | |
static void | staticShutdown () |
Free the memory taken by staticInitialization() More... | |
Abstract seekable stream class.
Specifies all functions to be implemented by stream subclasses and provides various convenience functions layered on top of on them.
All readX() and writeX() methods support transparent conversion based on the endianness of the underlying system and the value passed to setByteOrder(). Whenever getHostByteOrder() and getByteOrder() disagree, the endianness is swapped.
Defines the byte order to use in this Stream.
Enumerator | |
---|---|
EBigEndian |
PowerPC, SPARC, Motorola 68K. |
ELittleEndian |
x86, x86_64 |
ENetworkByteOrder |
Network byte order (an alias for big endian) |
mitsuba::Stream::Stream | ( | ) |
Create a new stream.
By default, it assumes the byte order of the underlying system, i.e. no endianness conversion is performed.
|
inlineprotectedvirtual |
Virtual destructor.
|
pure virtual |
Can we read from the stream?
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
pure virtual |
Can we write to the stream?
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
void mitsuba::Stream::copyTo | ( | Stream * | stream, |
int64_t | numBytes = -1 |
||
) |
Copy content from this stream into another stream.
stream | Destination stream |
numBytes | The number of bytes to copy. When -1 is specified, copying proceeds until the end of the source stream. |
|
pure virtual |
Flush the stream's buffers.
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
inline |
Return the byte order of this stream.
|
virtual |
Retrieve this object's class.
Reimplemented from Object.
Reimplemented in mitsuba::FileStream, mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
inlinestatic |
Return the byte order of the underlying machine.
|
pure virtual |
Get the current position inside the stream.
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
pure virtual |
Return the size of the stream.
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
bool mitsuba::Stream::isEOF | ( | ) | const |
Return whether we are at the end of the stream.
|
pure virtual |
Read a specified amount of data from the stream.
Throws an exception when the stream ended prematurely
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
inline |
Read an array from the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Read a known-size array from the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Read a boolean (8 bit) from the stream.
char mitsuba::Stream::readChar | ( | ) |
Read a signed character (8 bit) from the stream.
double mitsuba::Stream::readDouble | ( | ) |
Read a double-precision floating point number (64 bit) from the stream.
void mitsuba::Stream::readDoubleArray | ( | double * | data, |
size_t | size | ||
) |
Read a double-precision floating point array (64 bit) from the stream.
|
inline |
Read a known-size double-precision floating point array (64 bit) from the stream.
|
inline |
Read an element from the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Write a floating point number (configured precision) to the stream.
|
inline |
Write an array of floating point values (configured precision) to the stream.
|
inline |
Read a known-size array of floating point values (configured precision) to the stream.
half mitsuba::Stream::readHalf | ( | ) |
Read a half-precision floating point number (16 bit) from the stream.
void mitsuba::Stream::readHalfArray | ( | half * | data, |
size_t | size | ||
) |
Read a half-precision floating point array (16 bit) from the stream.
|
inline |
Read a known-size half-precision floating point array (16 bit) from the stream.
int mitsuba::Stream::readInt | ( | ) |
Read a signed int (32 bit) from the stream.
void mitsuba::Stream::readIntArray | ( | int * | dst, |
size_t | size | ||
) |
Read an array of signed ints (32 bit) from the stream.
|
inline |
Read an array of known size of signed ints (32 bit) from the stream.
std::string mitsuba::Stream::readLine | ( | ) |
Read a line from the stream and return it as a string.
int64_t mitsuba::Stream::readLong | ( | ) |
Read a signed int (64 bit) from the stream.
void mitsuba::Stream::readLongArray | ( | int64_t * | dst, |
size_t | size | ||
) |
Read an array of signed ints (64 bit) from the stream.
|
inline |
Read an array of known size of signed ints (64 bit) from the stream.
short mitsuba::Stream::readShort | ( | ) |
Read a signed short (16 bit) from the stream.
void mitsuba::Stream::readShortArray | ( | short * | dest, |
size_t | size | ||
) |
Read an array of signed shorts (16 bit) from the stream.
|
inline |
Read an array of known size of signed shorts (16 bit) from the stream.
float mitsuba::Stream::readSingle | ( | ) |
Read a single-precision floating point number (32 bit) from the stream.
void mitsuba::Stream::readSingleArray | ( | float * | data, |
size_t | size | ||
) |
Read a single-precision floating point array (32 bit) from the stream.
|
inline |
Read a known-size single-precision floating point array (32 bit) from the stream.
|
inline |
Read a size value from the stream.
std::string mitsuba::Stream::readString | ( | ) |
Read a null-terminated string from the stream.
unsigned char mitsuba::Stream::readUChar | ( | ) |
Read an unsigned character (8 bit) from the stream.
unsigned int mitsuba::Stream::readUInt | ( | ) |
Read an unsigned int (32 bit) from the stream.
void mitsuba::Stream::readUIntArray | ( | unsigned int * | dest, |
size_t | size | ||
) |
Read an array of unsigned ints (32 bit) from the stream.
|
inline |
Read an array of known size of unsigned ints (32 bit) from the stream.
uint64_t mitsuba::Stream::readULong | ( | ) |
Read an unsigned int (64 bit) from the stream.
void mitsuba::Stream::readULongArray | ( | uint64_t * | dst, |
size_t | size | ||
) |
Read an array of unsigned ints (64 bit) from the stream.
|
inline |
Read an array of known size of unsigned ints (64 bit) from the stream.
unsigned short mitsuba::Stream::readUShort | ( | ) |
Read an unsigned short (16 bit) from the stream.
void mitsuba::Stream::readUShortArray | ( | unsigned short * | dest, |
size_t | size | ||
) |
Read an array of unsigned shorts (16 bit) from the stream.
|
inline |
Read an array of known size of unsigned shorts (16 bit) from the stream.
|
pure virtual |
Seek to a position inside the stream.
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
void mitsuba::Stream::setByteOrder | ( | EByteOrder | byteOrder | ) |
Set the stream byte order.
void mitsuba::Stream::skip | ( | size_t | amount | ) |
Skip the given number of bytes.
|
virtual |
Return a string representation.
Reimplemented from Object.
Reimplemented in mitsuba::SSHStream, mitsuba::MemoryStream, mitsuba::ZStream, mitsuba::FileStream, mitsuba::SocketStream, and mitsuba::ConsoleStream.
|
pure virtual |
Truncate the stream to a given size.
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
pure virtual |
Write a specified amount of data into the stream.
Throws an exception when not all data could be written
Implemented in mitsuba::SSHStream, mitsuba::SocketStream, mitsuba::FileStream, mitsuba::MemoryStream, mitsuba::ZStream, and mitsuba::ConsoleStream.
|
inline |
Write an array to the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Write a known-size array to the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Write a boolean (8 bit) to the stream.
void mitsuba::Stream::writeChar | ( | char | value | ) |
Write a signed character (8 bit) to the stream.
void mitsuba::Stream::writeDouble | ( | double | value | ) |
Write a double-precision floating point number (64 bit) to the stream.
void mitsuba::Stream::writeDoubleArray | ( | const double * | data, |
size_t | size | ||
) |
Write a double-precision floating point array (64 bit) to the stream.
|
inline |
Write a known size double-precision floating point array (64 bit) to the stream.
|
inline |
Write an element to the stream (uses partial template specialization to select a method appropriate to the data type)
|
inline |
Write a floating point number (configured precision) to the stream.
|
inline |
Write an array of floating point values (configured precision) to the stream.
|
inline |
Write a known size array of floating point values (configured precision) to the stream.
void mitsuba::Stream::writeHalf | ( | half | value | ) |
Write a half-precision floating point number (16 bit) to the stream.
void mitsuba::Stream::writeHalfArray | ( | const half * | data, |
size_t | size | ||
) |
Write a half-precision floating point array (16 bit) to the stream.
|
inline |
Write a known size half-precision floating point array (16 bit) to the stream.
void mitsuba::Stream::writeInt | ( | int | value | ) |
Write a signed int (32 bit) to the stream.
void mitsuba::Stream::writeIntArray | ( | const int * | values, |
size_t | size | ||
) |
Write an array of signed ints (32 bit) to the stream.
|
inline |
Write an array of known size of signed ints (32 bit) to the stream.
void mitsuba::Stream::writeLine | ( | const std::string & | value | ) |
Write a string followed by a newline.
void mitsuba::Stream::writeLong | ( | int64_t | value | ) |
Write a signed int (64 bit) to the stream.
void mitsuba::Stream::writeLongArray | ( | const int64_t * | values, |
size_t | size | ||
) |
Write an array of signed ints (64 bit) to the stream.
|
inline |
Write an array of known size of signed ints (64 bit) to the stream.
void mitsuba::Stream::writeShort | ( | short | value | ) |
Write a signed short (16 bit) to the stream.
void mitsuba::Stream::writeShortArray | ( | const short * | values, |
size_t | size | ||
) |
Write an array of signed shorts (16 bit) to the stream.
|
inline |
Write an array of known size of signed shorts (16 bit) to the stream.
void mitsuba::Stream::writeSingle | ( | float | value | ) |
Write a single-precision floating point number (32 bit) to the stream.
void mitsuba::Stream::writeSingleArray | ( | const float * | data, |
size_t | size | ||
) |
Write a single-precision floating point array (32 bit) to the stream.
|
inline |
Write a known size single-precision floating point array (32 bit) to the stream.
|
inline |
Write a size value to the stream.
void mitsuba::Stream::writeString | ( | const std::string & | value | ) |
Write a null-terminated string to the stream.
void mitsuba::Stream::writeUChar | ( | unsigned char | value | ) |
Write an unsigned character (8 bit) to the stream.
void mitsuba::Stream::writeUInt | ( | unsigned int | value | ) |
Write an unsigned int (32 bit) to the stream.
void mitsuba::Stream::writeUIntArray | ( | const unsigned int * | values, |
size_t | size | ||
) |
Write an array of unsigned ints (32 bit) to the stream.
|
inline |
Write an array of known size of unsigned ints (32 bit) to the stream.
void mitsuba::Stream::writeULong | ( | uint64_t | value | ) |
Write an unsigned int (64 bit) to the stream.
void mitsuba::Stream::writeULongArray | ( | const uint64_t * | values, |
size_t | size | ||
) |
Write an array of unsigned ints (64 bit) to the stream.
|
inline |
Write an array of known size of unsigned ints (64 bit) to the stream.
void mitsuba::Stream::writeUShort | ( | unsigned short | value | ) |
Write an unsigned short (16 bit) to the stream.
void mitsuba::Stream::writeUShortArray | ( | const unsigned short * | values, |
size_t | size | ||
) |
Write an array of unsigned shorts (16 bit) to the stream.
|
inline |
Write an array of known size of unsigned shorts (16 bit) to the stream.
|
static |