[5] | 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-2006 Torus Knot Software Ltd |
---|
| 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 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef __Serializer_H__ |
---|
| 31 | #define __Serializer_H__ |
---|
| 32 | |
---|
| 33 | #include "OgrePrerequisites.h" |
---|
| 34 | #include "OgreString.h" |
---|
| 35 | #include "OgreDataStream.h" |
---|
| 36 | |
---|
| 37 | namespace Ogre { |
---|
| 38 | |
---|
| 39 | /** Generic class for serialising data to / from binary stream-based files. |
---|
| 40 | @remarks |
---|
| 41 | This class provides a number of useful methods for exporting / importing data |
---|
| 42 | from stream-oriented binary files (e.g. .mesh and .skeleton). |
---|
| 43 | */ |
---|
| 44 | class _OgreExport Serializer |
---|
| 45 | { |
---|
| 46 | public: |
---|
| 47 | Serializer(); |
---|
| 48 | virtual ~Serializer(); |
---|
| 49 | |
---|
| 50 | /// The endianness of written files |
---|
| 51 | enum Endian |
---|
| 52 | { |
---|
| 53 | /// Use the platform native endian |
---|
| 54 | ENDIAN_NATIVE, |
---|
| 55 | /// Use big endian (0x1000 is serialised as 0x10 0x00) |
---|
| 56 | ENDIAN_BIG, |
---|
| 57 | /// Use little endian (0x1000 is serialised as 0x00 0x10) |
---|
| 58 | ENDIAN_LITTLE |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | protected: |
---|
| 63 | |
---|
| 64 | uint32 mCurrentstreamLen; |
---|
| 65 | FILE* mpfFile; |
---|
| 66 | String mVersion; |
---|
| 67 | bool mFlipEndian; // default to native endian, derive from header |
---|
| 68 | |
---|
| 69 | // Internal methods |
---|
| 70 | virtual void writeFileHeader(void); |
---|
| 71 | virtual void writeChunkHeader(uint16 id, size_t size); |
---|
| 72 | |
---|
| 73 | void writeFloats(const float* const pfloat, size_t count); |
---|
| 74 | void writeFloats(const double* const pfloat, size_t count); |
---|
| 75 | void writeShorts(const uint16* const pShort, size_t count); |
---|
| 76 | void writeInts(const uint32* const pInt, size_t count); |
---|
| 77 | void writeBools(const bool* const pLong, size_t count); |
---|
| 78 | void writeObject(const Vector3& vec); |
---|
| 79 | void writeObject(const Quaternion& q); |
---|
| 80 | |
---|
| 81 | void writeString(const String& string); |
---|
| 82 | void writeData(const void* const buf, size_t size, size_t count); |
---|
| 83 | |
---|
| 84 | virtual void readFileHeader(DataStreamPtr& stream); |
---|
| 85 | virtual unsigned short readChunk(DataStreamPtr& stream); |
---|
| 86 | |
---|
| 87 | void readBools(DataStreamPtr& stream, bool* pDest, size_t count); |
---|
| 88 | void readFloats(DataStreamPtr& stream, float* pDest, size_t count); |
---|
| 89 | void readFloats(DataStreamPtr& stream, double* pDest, size_t count); |
---|
| 90 | void readShorts(DataStreamPtr& stream, uint16* pDest, size_t count); |
---|
| 91 | void readInts(DataStreamPtr& stream, uint32* pDest, size_t count); |
---|
| 92 | void readObject(DataStreamPtr& stream, Vector3& pDest); |
---|
| 93 | void readObject(DataStreamPtr& stream, Quaternion& pDest); |
---|
| 94 | |
---|
| 95 | String readString(DataStreamPtr& stream); |
---|
| 96 | String readString(DataStreamPtr& stream, size_t numChars); |
---|
| 97 | |
---|
| 98 | virtual void flipToLittleEndian(void* pData, size_t size, size_t count = 1); |
---|
| 99 | virtual void flipFromLittleEndian(void* pData, size_t size, size_t count = 1); |
---|
| 100 | |
---|
| 101 | virtual void flipEndian(void * pData, size_t size, size_t count); |
---|
| 102 | virtual void flipEndian(void * pData, size_t size); |
---|
| 103 | |
---|
| 104 | /// Determine the endianness of the incoming stream compared to native |
---|
| 105 | virtual void determineEndianness(DataStreamPtr& stream); |
---|
| 106 | /// Determine the endianness to write with based on option |
---|
| 107 | virtual void determineEndianness(Endian requestedEndian); |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | #endif |
---|