/src/ogre/OgreMain/include/OgreSerializer.h
Line | Count | Source (jump to first uncovered line) |
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-2014 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 "OgreHeaderPrefix.h" |
34 | | |
35 | | namespace Ogre { |
36 | | |
37 | | /** \addtogroup Core |
38 | | * @{ |
39 | | */ |
40 | | /** \addtogroup General |
41 | | * @{ |
42 | | */ |
43 | | /** Generic class for serialising data to / from binary stream-based files. |
44 | | |
45 | | This class provides a number of useful methods for exporting / importing data |
46 | | from stream-oriented binary files (e.g. .mesh and .skeleton). |
47 | | */ |
48 | | class _OgreExport Serializer : public SerializerAlloc |
49 | | { |
50 | | public: |
51 | | Serializer(); |
52 | | ~Serializer(); |
53 | | |
54 | | /// The endianness of written files |
55 | | enum Endian |
56 | | { |
57 | | /// Use the platform native endian |
58 | | ENDIAN_NATIVE, |
59 | | /// Use big endian (0x1000 is serialised as 0x10 0x00) |
60 | | ENDIAN_BIG, |
61 | | /// Use little endian (0x1000 is serialised as 0x00 0x10) |
62 | | ENDIAN_LITTLE |
63 | | }; |
64 | | |
65 | | |
66 | | protected: |
67 | | |
68 | | uint32 mCurrentstreamLen; |
69 | | DataStreamPtr mStream; |
70 | | String mVersion; |
71 | | bool mFlipEndian; /// Default to native endian, derive from header |
72 | | |
73 | | // Internal methods |
74 | | void writeFileHeader(void); |
75 | | void writeChunkHeader(uint16 id, size_t size); |
76 | 0 | static size_t calcChunkHeaderSize() { return sizeof(uint16) + sizeof(uint32); } |
77 | | /// string + terminating \n character |
78 | 0 | static size_t calcStringSize(const String& string) { return string.length() + 1; } |
79 | | |
80 | | void writeFloats(const float* const pfloat, size_t count); |
81 | | void writeFloats(const double* const pfloat, size_t count); |
82 | | void writeShorts(const uint16* const pShort, size_t count); |
83 | | void writeInts(const uint32* const pInt, size_t count); |
84 | | void writeBools(const bool* const pLong, size_t count); |
85 | | void writeObject(const Vector3& vec); |
86 | | void writeObject(const Quaternion& q); |
87 | | |
88 | | void writeString(const String& string); |
89 | | void writeData(const void* const buf, size_t size, size_t count); |
90 | | |
91 | | void readFileHeader(const DataStreamPtr& stream); |
92 | | unsigned short readChunk(const DataStreamPtr& stream); |
93 | | |
94 | | void readBools(const DataStreamPtr& stream, bool* pDest, size_t count); |
95 | | void readFloats(const DataStreamPtr& stream, float* pDest, size_t count); |
96 | | void readFloats(const DataStreamPtr& stream, double* pDest, size_t count); |
97 | | void readShorts(const DataStreamPtr& stream, uint16* pDest, size_t count); |
98 | | void readInts(const DataStreamPtr& stream, uint32* pDest, size_t count); |
99 | | void readObject(const DataStreamPtr& stream, Vector3& pDest); |
100 | | void readObject(const DataStreamPtr& stream, Quaternion& pDest); |
101 | | |
102 | | static String readString(const DataStreamPtr& stream); |
103 | | |
104 | | void flipToLittleEndian(void* pData, size_t size, size_t count = 1); |
105 | | void flipFromLittleEndian(void* pData, size_t size, size_t count = 1); |
106 | | |
107 | | /// Determine the endianness of the incoming stream compared to native |
108 | | void determineEndianness(const DataStreamPtr& stream); |
109 | | /// Determine the endianness to write with based on option |
110 | | void determineEndianness(Endian requestedEndian); |
111 | | |
112 | | // OGRE_SERIALIZER_VALIDATE_CHUNKSIZE |
113 | | typedef std::vector<size_t> ChunkSizeStack; |
114 | | ChunkSizeStack mChunkSizeStack; |
115 | | bool mReportChunkErrors; |
116 | | |
117 | | void pushInnerChunk(const DataStreamPtr& stream); |
118 | | void popInnerChunk(const DataStreamPtr& stream); |
119 | | void backpedalChunkHeader(const DataStreamPtr& stream); |
120 | | }; |
121 | | /** @} */ |
122 | | /** @} */ |
123 | | |
124 | | } |
125 | | |
126 | | #include "OgreHeaderSuffix.h" |
127 | | |
128 | | #endif |