Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::MemoryStream Class Reference

Simple memory buffer-based stream with automatic memory management. More...

#include <mitsuba/core/mstream.h>

+ Inheritance diagram for mitsuba::MemoryStream:

Public Member Functions

std::string toString () const
 Return a string representation. More...
 
virtual const ClassgetClass () const
 Retrieve this object's class. More...
 
Constructors
 MemoryStream (size_t initialSize=512)
 Create a new memory stream. More...
 
 MemoryStream (void *ptr, size_t size)
 Create a memory stream, which operates on a pre-allocated buffer. More...
 
Memory stream-specific features
uint8_tgetData ()
 Return the underlying data. More...
 
const uint8_tgetData () const
 Return the underlying data (const version) More...
 
uint8_tgetCurrentData ()
 Return the underlying data at the current position. More...
 
const uint8_tgetCurrentData () const
 Return the underlying data at the current position (const version) More...
 
void reset ()
 Set size and position to zero without changing the underlying buffer. More...
 
Implementation of the Stream interface
void read (void *ptr, size_t size)
 Read a specified amount of data from the stream. More...
 
void write (const void *ptr, size_t size)
 Write a specified amount of data into the stream. More...
 
void seek (size_t pos)
 Seek to a position inside the stream. More...
 
size_t getPos () const
 Get the current position inside the stream. More...
 
size_t getSize () const
 Return the size of the stream. More...
 
void truncate (size_t size)
 Truncate the stream to a given size. More...
 
void flush ()
 Flush the stream's buffers. More...
 
bool canWrite () const
 Can we write to the stream? More...
 
bool canRead () const
 Can we read from the stream? More...
 
- Public Member Functions inherited from mitsuba::Stream
 Stream ()
 Create a new stream. More...
 
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 >
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...
 
void setByteOrder (EByteOrder byteOrder)
 Set the stream byte order. More...
 
EByteOrder getByteOrder () const
 Return the byte order of this stream. 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 Classm_theClass
 
- Static Public Attributes inherited from mitsuba::Stream
static Classm_theClass
 
- Static Public Attributes inherited from Object
static Classm_theClass
 Pointer to the object's class descriptor. More...
 

Protected Member Functions

void resize (size_t newSize)
 
virtual ~MemoryStream ()
 
- Protected Member Functions inherited from mitsuba::Stream
virtual ~Stream ()
 Virtual destructor. More...
 
- Protected Member Functions inherited from Object
virtual ~Object ()
 Virtual private deconstructor. (Will only be called by ref) More...
 

Protected Attributes

size_t m_capacity
 
size_t m_size
 
size_t m_pos
 
bool m_ownsBuffer
 
uint8_tm_data
 

Additional Inherited Members

- Public Types inherited from mitsuba::Stream
enum  EByteOrder { EBigEndian = 0, ELittleEndian = 1, ENetworkByteOrder = EBigEndian }
 Defines the byte order to use in this Stream. More...
 
- Static Public Member Functions inherited from mitsuba::Stream
static EByteOrder getHostByteOrder ()
 Return the byte order of the underlying machine. More...
 
- 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...
 

Detailed Description

Simple memory buffer-based stream with automatic memory management.

The underlying memory storage of this implementation dynamically expands as data is written to the stream.

Constructor & Destructor Documentation

mitsuba::MemoryStream::MemoryStream ( size_t  initialSize = 512)

Create a new memory stream.

mitsuba::MemoryStream::MemoryStream ( void *  ptr,
size_t  size 
)

Create a memory stream, which operates on a pre-allocated buffer.

A memory stream created in this way will never resize the underlying buffer. An exception is thrown e.g. when attempting to extend its size

Remarks
This constructor is not available in the python bindings
virtual mitsuba::MemoryStream::~MemoryStream ( )
protectedvirtual

Member Function Documentation

bool mitsuba::MemoryStream::canRead ( ) const
virtual

Can we read from the stream?

Implements mitsuba::Stream.

bool mitsuba::MemoryStream::canWrite ( ) const
virtual

Can we write to the stream?

Implements mitsuba::Stream.

void mitsuba::MemoryStream::flush ( )
virtual

Flush the stream's buffers.

Implements mitsuba::Stream.

virtual const Class* mitsuba::MemoryStream::getClass ( ) const
virtual

Retrieve this object's class.

Reimplemented from mitsuba::Stream.

uint8_t* mitsuba::MemoryStream::getCurrentData ( )
inline

Return the underlying data at the current position.

const uint8_t* mitsuba::MemoryStream::getCurrentData ( ) const
inline

Return the underlying data at the current position (const version)

uint8_t* mitsuba::MemoryStream::getData ( )
inline

Return the underlying data.

const uint8_t* mitsuba::MemoryStream::getData ( ) const
inline

Return the underlying data (const version)

size_t mitsuba::MemoryStream::getPos ( ) const
virtual

Get the current position inside the stream.

Implements mitsuba::Stream.

size_t mitsuba::MemoryStream::getSize ( ) const
virtual

Return the size of the stream.

Implements mitsuba::Stream.

void mitsuba::MemoryStream::read ( void *  ptr,
size_t  size 
)
virtual

Read a specified amount of data from the stream.

Throws an exception when the stream ended prematurely

Implements mitsuba::Stream.

void mitsuba::MemoryStream::reset ( )

Set size and position to zero without changing the underlying buffer.

void mitsuba::MemoryStream::resize ( size_t  newSize)
protected
void mitsuba::MemoryStream::seek ( size_t  pos)
virtual

Seek to a position inside the stream.

Implements mitsuba::Stream.

std::string mitsuba::MemoryStream::toString ( ) const
virtual

Return a string representation.

Reimplemented from mitsuba::Stream.

void mitsuba::MemoryStream::truncate ( size_t  size)
virtual

Truncate the stream to a given size.

Implements mitsuba::Stream.

void mitsuba::MemoryStream::write ( const void *  ptr,
size_t  size 
)
virtual

Write a specified amount of data into the stream.

Throws an exception when not all data could be written

Implements mitsuba::Stream.

Member Data Documentation

size_t mitsuba::MemoryStream::m_capacity
protected
uint8_t* mitsuba::MemoryStream::m_data
protected
bool mitsuba::MemoryStream::m_ownsBuffer
protected
size_t mitsuba::MemoryStream::m_pos
protected
size_t mitsuba::MemoryStream::m_size
protected
Class* mitsuba::MemoryStream::m_theClass
static

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