TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
serialize.h
Go to the documentation of this file.
1 #ifndef G3D_serialize_h
2 #define G3D_serialize_h
3 
4 #include "G3D/BinaryInput.h"
5 #include "G3D/BinaryOutput.h"
6 #include "G3D/Array.h"
7 #include <string>
8 
9 namespace G3D {
10 
11 
12 inline void serialize(const std::string& s, BinaryOutput& b) {
13  b.writeString32(s);
14 }
15 
16 inline void deserialize(std::string& s, BinaryInput& b) {
17  s = b.readString32();
18 }
19 
20 inline void serialize(const int32& i, BinaryOutput& b) {
21  b.writeInt32(i);
22 }
23 
24 inline void deserialize(int32& i, BinaryInput& b) {
25  i = b.readInt32();
26 }
27 
28 inline void serialize(const uint32& i, BinaryOutput& b) {
29  b.writeUInt32(i);
30 }
31 
32 inline void deserialize(uint32& i, BinaryInput& b) {
33  i = b.readUInt32();
34 }
35 
36 inline void serialize(const bool& i, BinaryOutput& b) {
37  b.writeBool8(i);
38 }
39 
40 inline void deserialize(bool& i, BinaryInput& b) {
41  i = b.readBool8();
42 }
43 
44 inline void serialize(const float32& f, BinaryOutput& b) {
45  b.writeFloat32(f);
46 }
47 
48 inline void deserialize(float32& f, BinaryInput& b) {
49  f = b.readFloat32();
50 }
51 
52 inline void serialize(const float64& f, BinaryOutput& b) {
53  b.writeFloat64(f);
54 }
55 
56 inline void deserialize(float64& f, BinaryInput& b) {
57  f = b.readFloat64();
58 }
59 
61 template<typename T>
62 void serialize(const Array<T>& array, BinaryOutput& b) {
63  b.writeInt32(array.size());
64  for (int i = 0; i < array.size(); ++i) {
65  serialize(array[i], b);
66  }
67 }
68 
69 template<typename T>
70 void deserialize(Array<T>& array, BinaryInput& b) {
71  int N = b.readInt32();
72  array.resize(N);
73  for (int i = 0; i < array.size(); ++i) {
74  deserialize(array[i], b);
75  }
76 }
77 
78 } // G3D
79 
80 #endif //G3D_serialize_h
void writeInt32(int32 i)
Definition: BinaryOutput.h:301
float64 readFloat64()
Definition: BinaryInput.h:361
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
Definition: BinaryInput.h:69
void writeString32(const char *s)
Definition: BinaryOutput.cpp:463
bool readBool8()
Definition: BinaryInput.h:274
double float64
Definition: g3dmath.h:173
int32 readInt32()
Definition: BinaryInput.h:340
Definition: AABox.h:25
void deserialize(std::string &s, BinaryInput &b)
Definition: serialize.h:16
float32 readFloat32()
Definition: BinaryInput.h:352
void writeFloat64(float64 f)
Definition: BinaryOutput.h:322
void serialize(const std::string &s, BinaryOutput &b)
Definition: serialize.h:12
uint32 readUInt32()
Definition: BinaryInput.h:314
float float32
Definition: g3dmath.h:172
int size() const
Definition: Array.h:430
std::string readString32()
Definition: BinaryInput.cpp:473
Definition: BinaryOutput.h:52
int32_t int32
Definition: g3dmath.h:167
void writeFloat32(float32 f)
Definition: BinaryOutput.h:312
void writeUInt32(uint32 u)
Definition: BinaryOutput.cpp:395
uint32_t uint32
Definition: g3dmath.h:168
void writeBool8(bool b)
Definition: BinaryOutput.h:279