[1809] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #ifndef __Serializer_H__
|
---|
| 27 | #define __Serializer_H__
|
---|
| 28 |
|
---|
| 29 | #include "OgrePrerequisites.h"
|
---|
| 30 | #include "OgreString.h"
|
---|
| 31 | #include "OgreDataStream.h"
|
---|
| 32 |
|
---|
| 33 | namespace Ogre {
|
---|
| 34 |
|
---|
| 35 | /** Generic class for serialising data to / from binary stream-based files.
|
---|
| 36 | @remarks
|
---|
| 37 | This class provides a number of useful methods for exporting / importing data
|
---|
| 38 | from stream-oriented binary files (e.g. .mesh and .skeleton).
|
---|
| 39 | */
|
---|
| 40 | class _OgreExport Serializer
|
---|
| 41 | {
|
---|
| 42 | public:
|
---|
| 43 | Serializer();
|
---|
| 44 | virtual ~Serializer();
|
---|
| 45 |
|
---|
| 46 | /// The endianness of written files
|
---|
| 47 | enum Endian
|
---|
| 48 | {
|
---|
| 49 | /// Use the platform native endian
|
---|
| 50 | ENDIAN_NATIVE,
|
---|
| 51 | /// Use big endian (0x1000 is serialised as 0x10 0x00)
|
---|
| 52 | ENDIAN_BIG,
|
---|
| 53 | /// Use little endian (0x1000 is serialised as 0x00 0x10)
|
---|
| 54 | ENDIAN_LITTLE
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | protected:
|
---|
| 59 |
|
---|
| 60 | uint32 mCurrentstreamLen;
|
---|
| 61 | FILE* mpfFile;
|
---|
| 62 | String mVersion;
|
---|
| 63 | bool mFlipEndian; // default to native endian, derive from header
|
---|
| 64 |
|
---|
| 65 | // Internal methods
|
---|
| 66 | virtual void writeFileHeader(void);
|
---|
| 67 | virtual void writeChunkHeader(uint16 id, uint32 size);
|
---|
| 68 |
|
---|
| 69 | void writeFloats(const float* const pfloat, size_t count);
|
---|
| 70 | void writeFloats(const double* const pfloat, size_t count);
|
---|
| 71 | void writeShorts(const uint16* const pShort, size_t count);
|
---|
| 72 | void writeInts(const uint32* const pInt, size_t count);
|
---|
| 73 | void writeBools(const bool* const pLong, size_t count);
|
---|
| 74 | void writeObject(const Vector3& vec);
|
---|
| 75 | void writeObject(const Quaternion& q);
|
---|
| 76 |
|
---|
| 77 | void writeString(const String& string);
|
---|
| 78 | void writeData(const void* const buf, size_t size, size_t count);
|
---|
| 79 |
|
---|
| 80 | virtual void readFileHeader(DataStreamPtr& stream);
|
---|
| 81 | virtual unsigned short readChunk(DataStreamPtr& stream);
|
---|
| 82 |
|
---|
| 83 | void readBools(DataStreamPtr& stream, bool* pDest, size_t count);
|
---|
| 84 | void readFloats(DataStreamPtr& stream, float* pDest, size_t count);
|
---|
| 85 | void readFloats(DataStreamPtr& stream, double* pDest, size_t count);
|
---|
| 86 | void readShorts(DataStreamPtr& stream, uint16* pDest, size_t count);
|
---|
| 87 | void readInts(DataStreamPtr& stream, uint32* pDest, size_t count);
|
---|
| 88 | void readObject(DataStreamPtr& stream, Vector3& pDest);
|
---|
| 89 | void readObject(DataStreamPtr& stream, Quaternion& pDest);
|
---|
| 90 |
|
---|
| 91 | String readString(DataStreamPtr& stream);
|
---|
| 92 | String readString(DataStreamPtr& stream, size_t numChars);
|
---|
| 93 |
|
---|
| 94 | virtual void flipToLittleEndian(void* pData, size_t size, size_t count = 1);
|
---|
| 95 | virtual void flipFromLittleEndian(void* pData, size_t size, size_t count = 1);
|
---|
| 96 |
|
---|
| 97 | virtual void flipEndian(void * pData, size_t size, size_t count);
|
---|
| 98 | virtual void flipEndian(void * pData, size_t size);
|
---|
| 99 |
|
---|
| 100 | /// Determine the endianness of the incoming stream compared to native
|
---|
| 101 | virtual void determineEndianness(DataStreamPtr& stream);
|
---|
| 102 | /// Determine the endianness to write with based on option
|
---|
| 103 | virtual void determineEndianness(Endian requestedEndian);
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | #endif
|
---|