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-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef __Serializer_H__ |
---|
30 | #define __Serializer_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | #include "OgreString.h" |
---|
34 | #include "OgreDataStream.h" |
---|
35 | #include "OgreHeaderPrefix.h" |
---|
36 | |
---|
37 | namespace Ogre { |
---|
38 | |
---|
39 | /** \addtogroup Core |
---|
40 | * @{ |
---|
41 | */ |
---|
42 | /** \addtogroup General |
---|
43 | * @{ |
---|
44 | */ |
---|
45 | /** Generic class for serialising data to / from binary stream-based files. |
---|
46 | @remarks |
---|
47 | This class provides a number of useful methods for exporting / importing data |
---|
48 | from stream-oriented binary files (e.g. .mesh and .skeleton). |
---|
49 | */ |
---|
50 | class _OgreExport Serializer : public SerializerAlloc |
---|
51 | { |
---|
52 | public: |
---|
53 | Serializer(); |
---|
54 | virtual ~Serializer(); |
---|
55 | |
---|
56 | /// The endianness of written files |
---|
57 | enum Endian |
---|
58 | { |
---|
59 | /// Use the platform native endian |
---|
60 | ENDIAN_NATIVE, |
---|
61 | /// Use big endian (0x1000 is serialised as 0x10 0x00) |
---|
62 | ENDIAN_BIG, |
---|
63 | /// Use little endian (0x1000 is serialised as 0x00 0x10) |
---|
64 | ENDIAN_LITTLE |
---|
65 | }; |
---|
66 | |
---|
67 | |
---|
68 | protected: |
---|
69 | |
---|
70 | uint32 mCurrentstreamLen; |
---|
71 | DataStreamPtr mStream; |
---|
72 | String mVersion; |
---|
73 | bool mFlipEndian; /// Default to native endian, derive from header |
---|
74 | |
---|
75 | // Internal methods |
---|
76 | virtual void writeFileHeader(void); |
---|
77 | virtual void writeChunkHeader(uint16 id, size_t size); |
---|
78 | |
---|
79 | void writeFloats(const float* const pfloat, size_t count); |
---|
80 | void writeFloats(const double* const pfloat, size_t count); |
---|
81 | void writeShorts(const uint16* const pShort, size_t count); |
---|
82 | void writeInts(const uint32* const pInt, size_t count); |
---|
83 | void writeBools(const bool* const pLong, size_t count); |
---|
84 | void writeObject(const Vector3& vec); |
---|
85 | void writeObject(const Quaternion& q); |
---|
86 | |
---|
87 | void writeString(const String& string); |
---|
88 | void writeData(const void* const buf, size_t size, size_t count); |
---|
89 | |
---|
90 | virtual void readFileHeader(DataStreamPtr& stream); |
---|
91 | virtual unsigned short readChunk(DataStreamPtr& stream); |
---|
92 | |
---|
93 | void readBools(DataStreamPtr& stream, bool* pDest, size_t count); |
---|
94 | void readFloats(DataStreamPtr& stream, float* pDest, size_t count); |
---|
95 | void readFloats(DataStreamPtr& stream, double* pDest, size_t count); |
---|
96 | void readShorts(DataStreamPtr& stream, uint16* pDest, size_t count); |
---|
97 | void readInts(DataStreamPtr& stream, uint32* pDest, size_t count); |
---|
98 | void readObject(DataStreamPtr& stream, Vector3& pDest); |
---|
99 | void readObject(DataStreamPtr& stream, Quaternion& pDest); |
---|
100 | |
---|
101 | String readString(DataStreamPtr& stream); |
---|
102 | String readString(DataStreamPtr& stream, size_t numChars); |
---|
103 | |
---|
104 | virtual void flipToLittleEndian(void* pData, size_t size, size_t count = 1); |
---|
105 | virtual void flipFromLittleEndian(void* pData, size_t size, size_t count = 1); |
---|
106 | |
---|
107 | virtual void flipEndian(void * pData, size_t size, size_t count); |
---|
108 | virtual void flipEndian(void * pData, size_t size); |
---|
109 | |
---|
110 | /// Determine the endianness of the incoming stream compared to native |
---|
111 | virtual void determineEndianness(DataStreamPtr& stream); |
---|
112 | /// Determine the endianness to write with based on option |
---|
113 | virtual void determineEndianness(Endian requestedEndian); |
---|
114 | }; |
---|
115 | /** @} */ |
---|
116 | /** @} */ |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | #include "OgreHeaderSuffix.h" |
---|
121 | |
---|
122 | #endif |
---|