OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreSerializer.h
Go to the documentation of this file.
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 #ifndef OGRE_SERIALIZER_VALIDATE_CHUNKSIZE
36 #define OGRE_SERIALIZER_VALIDATE_CHUNKSIZE OGRE_DEBUG_MODE
37 #endif
38 
39 namespace Ogre {
40 
53  {
54  public:
55  Serializer();
56  virtual ~Serializer();
57 
59  enum Endian
60  {
66  ENDIAN_LITTLE
67  };
68 
69 
70  protected:
71 
75  bool mFlipEndian;
76 
77  // Internal methods
78  virtual void writeFileHeader(void);
79  virtual void writeChunkHeader(uint16 id, size_t size);
80  virtual size_t calcChunkHeaderSize();
81  size_t calcStringSize(const String& string);
82 
83  void writeFloats(const float* const pfloat, size_t count);
84  void writeFloats(const double* const pfloat, size_t count);
85  void writeShorts(const uint16* const pShort, size_t count);
86  void writeInts(const uint32* const pInt, size_t count);
87  void writeBools(const bool* const pLong, size_t count);
88  void writeObject(const Vector3& vec);
89  void writeObject(const Quaternion& q);
90 
91  void writeString(const String& string);
92  void writeData(const void* const buf, size_t size, size_t count);
93 
94  virtual void readFileHeader(DataStreamPtr& stream);
95  virtual unsigned short readChunk(DataStreamPtr& stream);
96 
97  void readBools(DataStreamPtr& stream, bool* pDest, size_t count);
98  void readFloats(DataStreamPtr& stream, float* pDest, size_t count);
99  void readFloats(DataStreamPtr& stream, double* pDest, size_t count);
100  void readShorts(DataStreamPtr& stream, uint16* pDest, size_t count);
101  void readInts(DataStreamPtr& stream, uint32* pDest, size_t count);
102  void readObject(DataStreamPtr& stream, Vector3& pDest);
103  void readObject(DataStreamPtr& stream, Quaternion& pDest);
104 
105  String readString(DataStreamPtr& stream);
106  String readString(DataStreamPtr& stream, size_t numChars);
107 
108  virtual void flipToLittleEndian(void* pData, size_t size, size_t count = 1);
109  virtual void flipFromLittleEndian(void* pData, size_t size, size_t count = 1);
110 
111  virtual void flipEndian(void * pData, size_t size, size_t count);
112  virtual void flipEndian(void * pData, size_t size);
113 
115  virtual void determineEndianness(DataStreamPtr& stream);
117  virtual void determineEndianness(Endian requestedEndian);
118 
119 #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE
120  typedef vector<size_t>::type ChunkSizeStack;
121  ChunkSizeStack mChunkSizeStack;
122  bool mReportChunkErrors;
123 #endif
124  virtual void pushInnerChunk(const DataStreamPtr& stream);
125  virtual void popInnerChunk(const DataStreamPtr& stream);
126  virtual void backpedalChunkHeader(DataStreamPtr& stream);
127  };
131 }
132 
133 #include "OgreHeaderSuffix.h"
134 
135 #endif
unsigned int uint32
Definition: OgrePlatform.h:420
#define _OgreExport
Definition: OgrePlatform.h:255
Generic class for serialising data to / from binary stream-based files.
Use the platform native endian.
Implementation of a Quaternion, i.e.
uint32 mCurrentstreamLen
Endian
The endianness of written files.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
Use big endian (0x1000 is serialised as 0x10 0x00)
_StringBase String
Definition: OgreCommon.h:53
DataStreamPtr mStream
unsigned short uint16
Definition: OgrePlatform.h:421