OGRE  1.8
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-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 
51  {
52  public:
53  Serializer();
54  virtual ~Serializer();
55 
57  enum Endian
58  {
64  ENDIAN_LITTLE
65  };
66 
67 
68  protected:
69 
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 
111  virtual void determineEndianness(DataStreamPtr& stream);
113  virtual void determineEndianness(Endian requestedEndian);
114  };
118 }
119 
120 #include "OgreHeaderSuffix.h"
121 
122 #endif
unsigned int uint32
Definition: OgrePlatform.h:270
#define _OgreExport
Definition: OgrePlatform.h:233
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:51
Use big endian (0x1000 is serialised as 0x10 0x00)
_StringBase String
DataStreamPtr mStream
unsigned short uint16
Definition: OgrePlatform.h:271