![]() |
OGRE-Next 4.0.0unstable
Object-Oriented Graphics Rendering Engine
|
Utility class providing helper methods for reading / writing structured data held in a DataStream. More...
#include <OgreStreamSerialiser.h>
Classes | |
struct | Chunk |
Definition of a chunk of data in a file. More... | |
Public Types | |
enum | Endian { ENDIAN_AUTO , ENDIAN_BIG , ENDIAN_LITTLE } |
The endianness of files. More... | |
enum | RealStorageFormat { REAL_FLOAT , REAL_DOUBLE } |
The storage format of Real values. More... | |
Public Member Functions | |
StreamSerialiser (const DataStreamPtr &stream, Endian endianMode=ENDIAN_AUTO, bool autoHeader=true, RealStorageFormat realFormat=REAL_FLOAT) | |
Constructor. | |
virtual | ~StreamSerialiser () |
virtual bool | eof () const |
Reports whether the stream is at the end of file. | |
virtual const Chunk * | getCurrentChunk () const |
Get the definition of the current chunk being read (if any). | |
size_t | getCurrentChunkDepth () const |
Report the current depth of the chunk nesting, whether reading or writing. | |
uint32 | getCurrentChunkID () const |
Get the ID of the chunk that's currently being read/written, if any. | |
virtual Endian | getEndian () const |
Get the endian mode. | |
size_t | getOffsetFromChunkStart () const |
Get the current byte position relative to the start of the data section of the last chunk that was read or written. | |
virtual bool | isEndOfChunk (uint32 id) |
Return whether the current data pointer is at the end of the current chunk. | |
virtual uint32 | peekNextChunkID () |
Call this to 'peek' at the next chunk ID without permanently moving the stream pointer. | |
virtual void | read (AxisAlignedBox *aabb, size_t count=1) |
virtual void | read (bool *val, size_t count=1) |
virtual void | read (Matrix3 *m, size_t count=1) |
virtual void | read (Matrix4 *m, size_t count=1) |
virtual void | read (Node *node, size_t count=1) |
virtual void | read (Plane *plane, size_t count=1) |
virtual void | read (Quaternion *q, size_t count=1) |
virtual void | read (Radian *angle, size_t count=1) |
virtual void | read (Ray *ray, size_t count=1) |
virtual void | read (Real *val, size_t count=1) |
virtual void | read (Sphere *sphere, size_t count=1) |
virtual void | read (String *string) |
template<typename T > | |
void | read (T *pT, size_t count=1) |
Catch-all method to read primitive types. | |
virtual void | read (Vector2 *vec, size_t count=1) |
read a Vector3 | |
virtual void | read (Vector3 *vec, size_t count=1) |
virtual void | read (Vector4 *vec, size_t count=1) |
virtual const Chunk * | readChunkBegin () |
Reads the start of the next chunk in the file. | |
virtual const Chunk * | readChunkBegin (uint32 id, uint16 maxVersion, const String &msg=BLANKSTRING) |
Reads the start of the next chunk so long as it's of a given ID and version. | |
virtual void | readChunkEnd (uint32 id) |
Finish the reading of a chunk. | |
virtual void | readData (void *buf, size_t size, size_t count) |
Read arbitrary data from a stream. | |
virtual void | startDeflate (size_t avail_in=0) |
Start (un)compressing data. | |
virtual void | stopDeflate () |
Stop (un)compressing data. | |
virtual void | undoReadChunk (uint32 id) |
Call this to 'rewind' the stream to just before the start of the current chunk. | |
virtual void | write (const AxisAlignedBox *aabb, size_t count=1) |
virtual void | write (const bool *boolean, size_t count=1) |
virtual void | write (const Matrix3 *m, size_t count=1) |
virtual void | write (const Matrix4 *m, size_t count=1) |
virtual void | write (const Node *node, size_t count=1) |
virtual void | write (const Plane *plane, size_t count=1) |
virtual void | write (const Quaternion *q, size_t count=1) |
virtual void | write (const Radian *angle, size_t count=1) |
virtual void | write (const Ray *ray, size_t count=1) |
virtual void | write (const Real *val, size_t count=1) |
virtual void | write (const Sphere *sphere, size_t count=1) |
virtual void | write (const String *string) |
template<typename T > | |
void | write (const T *pT, size_t count=1) |
Catch-all method to write primitive types. | |
virtual void | write (const Vector2 *vec, size_t count=1) |
virtual void | write (const Vector3 *vec, size_t count=1) |
virtual void | write (const Vector4 *vec, size_t count=1) |
virtual void | writeChunkBegin (uint32 id, uint16 version=1) |
Begin writing a new chunk. | |
virtual void | writeChunkEnd (uint32 id) |
End writing a chunk. | |
virtual void | writeData (const void *buf, size_t size, size_t count) |
Write arbitrary data to a stream. | |
Static Public Member Functions | |
static uint32 | makeIdentifier (const String &code) |
Pack a 4-character code into a 32-bit identifier. | |
Utility class providing helper methods for reading / writing structured data held in a DataStream.
Ogre::StreamSerialiser::StreamSerialiser | ( | const DataStreamPtr & | stream, |
Endian | endianMode = ENDIAN_AUTO , |
||
bool | autoHeader = true , |
||
RealStorageFormat | realFormat = REAL_FLOAT |
||
) |
Constructor.
stream | The stream on which you will read / write data. |
endianMode | The endian mode in which to read / writedata. If left at the default, when writing the endian mode will be the native platform mode, and when reading it's expected that the first chunk encountered will be the header chunk, which will determine the endian mode. |
autoHeader | If true, the first write or read to this stream will automatically read / write the header too. This is required if you set endianMode to ENDIAN_AUTO, but if you manually set the endian mode, then you can skip writing / reading the header if you wish, if for example this stream is midway through a file which has already included header information. |
realFormat | Set the format you want to write reals in. Only useful for files that you're writing (since when reading this is picked up from the file), and can only be changed if autoHeader is true, since real format is stored in the header. Defaults to float unless you're using OGRE_DOUBLE_PRECISION. |
|
virtual |
|
virtual |
Reports whether the stream is at the end of file.
|
virtual |
Get the definition of the current chunk being read (if any).
|
inline |
Report the current depth of the chunk nesting, whether reading or writing.
uint32 Ogre::StreamSerialiser::getCurrentChunkID | ( | ) | const |
Get the ID of the chunk that's currently being read/written, if any.
|
inlinevirtual |
Get the endian mode.
size_t Ogre::StreamSerialiser::getOffsetFromChunkStart | ( | ) | const |
Get the current byte position relative to the start of the data section of the last chunk that was read or written.
|
virtual |
Return whether the current data pointer is at the end of the current chunk.
id | The id of the chunk that you were reading (for validation purposes) |
Pack a 4-character code into a 32-bit identifier.
code | String to pack - must be 4 characters. |
|
virtual |
Call this to 'peek' at the next chunk ID without permanently moving the stream pointer.
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
inline |
Catch-all method to read primitive types.
|
virtual |
read a Vector3
|
virtual |
|
virtual |
|
virtual |
Reads the start of the next chunk in the file.
|
virtual |
Reads the start of the next chunk so long as it's of a given ID and version.
id | The ID you're expecting. If the next chunk isn't of this ID, then the chunk read is undone and the method returns null. |
maxVersion | The maximum version you're able to process. If the ID is correct but the version exceeds what is passed in here, the chunk is skipped over, the problem logged and null is returned. |
msg | Descriptive text added to the log if versions are not compatible |
|
virtual |
Finish the reading of a chunk.
id | The id of the chunk that you were reading (for validation purposes) |
|
virtual |
Read arbitrary data from a stream.
buf | Pointer to bytes |
size | The size of each element to read; each will be endian-flipped if necessary |
count | The number of elements to read |
|
virtual |
Start (un)compressing data.
avail_in | Available bytes for uncompressing |
|
virtual |
Stop (un)compressing data.
|
virtual |
Call this to 'rewind' the stream to just before the start of the current chunk.
id | The id of the chunk that you were reading (for validation purposes) |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
inline |
Catch-all method to write primitive types.
|
virtual |
|
virtual |
|
virtual |
Begin writing a new chunk.
id | The identifier of the new chunk. Any value that's unique in the file context is valid, except for the numbers 0x0001 and 0x1000 which are reserved for internal header identification use. |
version | The version of the chunk you're writing |
|
virtual |
End writing a chunk.
id | The identifier of the chunk - this is really just a safety check, since you can only end the chunk you most recently started. |
|
virtual |
Write arbitrary data to a stream.
buf | Pointer to bytes |
size | The size of each element to write; each will be endian-flipped if necessary |
count | The number of elements to write |