28#ifndef __StreamSerialiser_H__
29#define __StreamSerialiser_H__
102 Chunk() : id(0), version(1), length(0), offset(0) {}
123 bool autoHeader =
true,
259 virtual void writeData(
const void* buf,
size_t size,
size_t count);
262 template <
typename T>
263 void write(
const T* pT,
size_t count = 1)
265 writeData(pT,
sizeof(T), count);
281 virtual void write(
const Ray* ray,
size_t count = 1);
284 virtual void write(
const bool*
boolean,
size_t count = 1);
293 virtual void readData(
void* buf,
size_t size,
size_t count);
296 template <
typename T>
297 void read(T* pT,
size_t count = 1)
299 readData(pT,
sizeof(T), count);
316 virtual void read(
Ray* ray,
size_t count = 1);
319 virtual void read(
bool* val,
size_t count = 1);
349 bool validateReadable =
false,
bool validateWriteable =
false)
const;
351 virtual void flipEndian(
void * pData,
size_t size,
size_t count);
360 template <
typename T,
typename U>
366 for (
size_t i = 0; i < count; ++i)
367 *pDst++ =
static_cast<U
>(*pSrc++);
369 writeData(tmp,
sizeof(U), count);
373 template <
typename T,
typename U>
377 readData(tmp,
sizeof(U), count);
381 for (
size_t i = 0; i < count; ++i)
382 *pDst++ =
static_cast<T
>(*pSrc++);
#define OGRE_DOUBLE_PRECISION
If set to 1, Real is typedef'ed to double.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
A 3D box aligned with the x/y/z axes.
A 3x3 matrix which can represent rotations around axes.
Class encapsulating a standard 4x4 homogeneous matrix.
Class representing a general-purpose node an articulated scene graph.
Defines a plane in 3D space.
Implementation of a Quaternion, i.e.
Wrapper class which indicates a given angle value is in Radians.
Representation of a ray in space, i.e.
A sphere primitive, mostly used for bounds checking.
Utility class providing helper methods for reading / writing structured data held in a DataStream.
Endian
The endianness of files.
@ ENDIAN_AUTO
Automatically determine endianness.
@ ENDIAN_BIG
Use big endian (0x1000 is serialised as 0x10 0x00)
virtual void write(const Plane *plane, size_t count=1)
virtual void write(const Matrix4 *m, size_t count=1)
virtual void writeData(const void *buf, size_t size, size_t count)
Write arbitrary data to a stream.
ChunkStack mChunkStack
Current list of open chunks.
RealStorageFormat mRealFormat
static uint32 CHUNK_HEADER_SIZE
virtual void read(Sphere *sphere, size_t count=1)
virtual uint32 calculateChecksum(Chunk *c)
virtual void read(Vector2 *vec, size_t count=1)
read a Vector3
virtual void read(Matrix4 *m, size_t count=1)
void write(const T *pT, size_t count=1)
Catch-all method to write primitive types.
virtual void readData(void *buf, size_t size, size_t count)
Read arbitrary data from a stream.
virtual void read(Quaternion *q, size_t count=1)
virtual void read(AxisAlignedBox *aabb, size_t count=1)
virtual void write(const bool *boolean, size_t count=1)
virtual void write(const Node *node, size_t count=1)
virtual void read(Real *val, size_t count=1)
deque< Chunk * >::type ChunkStack
virtual void writeChunkBegin(uint32 id, uint16 version=1)
Begin writing a new chunk.
uint32 getCurrentChunkID() const
Get the ID of the chunk that's currently being read/written, if any.
virtual void readHeader()
virtual void write(const Quaternion *q, size_t count=1)
virtual void write(const Sphere *sphere, size_t count=1)
virtual void write(const Real *val, size_t count=1)
virtual void read(Node *node, size_t count=1)
virtual void read(Vector3 *vec, size_t count=1)
virtual void write(const Vector2 *vec, size_t count=1)
virtual void write(const Matrix3 *m, size_t count=1)
virtual ~StreamSerialiser()
virtual Chunk * readChunkImpl()
virtual void write(const AxisAlignedBox *aabb, size_t count=1)
virtual void flipEndian(void *pData, size_t size)
RealStorageFormat
The storage format of Real values.
@ REAL_FLOAT
Real is stored as float, reducing precision if you're using OGRE_DOUBLE_PRECISION.
virtual void determineEndianness()
StreamSerialiser(const DataStreamPtr &stream, Endian endianMode=ENDIAN_AUTO, bool autoHeader=true, RealStorageFormat realFormat=REAL_FLOAT)
Constructor.
virtual void writeChunkImpl(uint32 id, uint16 version)
static uint32 REVERSE_HEADER_ID
virtual void checkStream(bool failOnEof=false, bool validateReadable=false, bool validateWriteable=false) const
void read(T *pT, size_t count=1)
Catch-all method to read primitive types.
virtual Endian getEndian() const
Get the endian mode.
virtual void writeHeader()
virtual void write(const Radian *angle, size_t count=1)
void writeConverted(const T *src, U typeToWrite, size_t count)
virtual void readFloatsAsDoubles(double *val, size_t count)
DataStreamPtr mOriginalStream
virtual void write(const String *string)
virtual void read(Ray *ray, size_t count=1)
virtual const Chunk * readChunkBegin(uint32 id, uint16 maxVersion, const String &msg=StringUtil::BLANK)
Reads the start of the next chunk so long as it's of a given ID and version.
virtual void read(Plane *plane, size_t count=1)
virtual const Chunk * getCurrentChunk() const
Get the definition of the current chunk being read (if any).
virtual void read(Radian *angle, size_t count=1)
virtual void writeDoublesAsFloats(const double *val, size_t count)
virtual void writeFloatsAsDoubles(const float *val, size_t count)
virtual void readChunkEnd(uint32 id)
Finish the reading of a chunk.
virtual void write(const Vector4 *vec, size_t count=1)
virtual void read(Matrix3 *m, size_t count=1)
virtual bool eof() const
Reports whether the stream is at the end of file.
virtual uint32 peekNextChunkID()
Call this to 'peek' at the next chunk ID without permanently moving the stream pointer.
size_t getOffsetFromChunkStart() const
Get the current byte position relative to the start of the data section of the last chunk that was re...
virtual void read(String *string)
virtual void startDeflate(size_t avail_in=0)
Start (un)compressing data.
virtual void undoReadChunk(uint32 id)
Call this to 'rewind' the stream to just before the start of the current chunk.
void readConverted(T *dst, U typeToRead, size_t count)
virtual void flipEndian(void *pData, size_t size, size_t count)
virtual void stopDeflate()
Stop (un)compressing data.
virtual Chunk * popChunk(uint id)
virtual void write(const Ray *ray, size_t count=1)
virtual void writeChunkEnd(uint32 id)
End writing a chunk.
virtual bool isEndOfChunk(uint32 id)
Return whether the current data pointer is at the end of the current chunk.
static uint32 makeIdentifier(const String &code)
Pack a 4-character code into a 32-bit identifier.
virtual void write(const Vector3 *vec, size_t count=1)
size_t getCurrentChunkDepth() const
Report the current depth of the chunk nesting, whether reading or writing.
virtual void readDoublesAsFloats(float *val, size_t count)
virtual const Chunk * readChunkBegin()
Reads the start of the next chunk in the file.
virtual void read(Vector4 *vec, size_t count=1)
virtual void read(bool *val, size_t count=1)
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Standard 2-dimensional vector.
Standard 3-dimensional vector.
4-dimensional homogeneous vector.
#define OGRE_ALLOC_T(T, count, category)
Allocate a block of memory for a primitive type, and indicate the category of usage.
#define OGRE_FREE(ptr, category)
Free the memory allocated with OGRE_MALLOC or OGRE_ALLOC_T. Category is required to be restated to en...
@ MEMCATEGORY_GENERAL
General purpose.
float Real
Software floating point type.
Definition of a chunk of data in a file.
uint32 offset
Location of the chunk (header) in bytes from the start of a stream (derived)
uint16 version
Version of the chunk (stored)
uint32 id
Identifier of the chunk (for example from makeIdentifier) (stored)
uint32 length
Length of the chunk data in bytes, excluding the header of this chunk (stored)