aboutsummaryrefslogtreecommitdiff
path: root/src/serializerbinary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/serializerbinary.cpp')
-rw-r--r--src/serializerbinary.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/src/serializerbinary.cpp b/src/serializerbinary.cpp
new file mode 100644
index 0000000..1ea9f36
--- /dev/null
+++ b/src/serializerbinary.cpp
@@ -0,0 +1,163 @@
1#include "serializerbinary.h"
2
3SerializerBinary::SerializerBinary(FILE *fhFile, bool bLoading):
4 Serializer(bLoading),
5 fhFile(fhFile),
6 bCloseFile(false)
7{
8}
9
10SerializerBinary::SerializerBinary(char *sFileName, bool bLoading):
11 Serializer(bLoading),
12 bCloseFile(true)
13{
14 if (bLoading)
15 {
16 fhFile = fopen(sFileName, "rb");
17 }
18 else
19 {
20 fhFile = fopen(sFileName, "wb");
21 }
22}
23
24SerializerBinary::~SerializerBinary()
25{
26 close();
27}
28
29void SerializerBinary::close()
30{
31 if (fhFile != NULL)
32 {
33 fclose(fhFile);
34 fhFile = NULL;
35 }
36}
37
38Serializer &SerializerBinary::operator<<(bool p)
39{
40 fwrite(&p, sizeof(p), 1, fhFile);
41 return *this;
42}
43Serializer &SerializerBinary::operator<<(int8_t p)
44{
45 fwrite(&p, sizeof(p), 1, fhFile);
46 return *this;
47}
48Serializer &SerializerBinary::operator<<(int16_t p)
49{
50 fwrite(&p, sizeof(p), 1, fhFile);
51 return *this;
52}
53Serializer &SerializerBinary::operator<<(int32_t p)
54{
55 printf("int: %d, size: %d\n", p, sizeof(p));
56 fwrite(&p, sizeof(p), 1, fhFile);
57 return *this;
58}
59Serializer &SerializerBinary::operator<<(int64_t p)
60{
61 fwrite(&p, sizeof(p), 1, fhFile);
62 return *this;
63}
64Serializer &SerializerBinary::operator<<(uint8_t p)
65{
66 fwrite(&p, sizeof(p), 1, fhFile);
67 return *this;
68}
69Serializer &SerializerBinary::operator<<(uint16_t p)
70{
71 fwrite(&p, sizeof(p), 1, fhFile);
72 return *this;
73}
74Serializer &SerializerBinary::operator<<(uint32_t p)
75{
76 fwrite(&p, sizeof(p), 1, fhFile);
77 return *this;
78}
79Serializer &SerializerBinary::operator<<(uint64_t p)
80{
81 fwrite(&p, sizeof(p), 1, fhFile);
82 return *this;
83}
84Serializer &SerializerBinary::operator<<(float p)
85{
86 fwrite(&p, sizeof(p), 1, fhFile);
87 return *this;
88}
89Serializer &SerializerBinary::operator<<(double p)
90{
91 fwrite(&p, sizeof(p), 1, fhFile);
92 return *this;
93}
94Serializer &SerializerBinary::operator<<(long double p)
95{
96 fwrite(&p, sizeof(p), 1, fhFile);
97 return *this;
98}
99
100Serializer &SerializerBinary::operator>>(bool &p)
101{
102 bool bTmp;
103 fread(&bTmp, sizeof(p), 1, fhFile);
104 p = bTmp;
105 return *this;
106}
107Serializer &SerializerBinary::operator>>(int8_t &p)
108{
109 fread(&p, sizeof(p), 1, fhFile);
110 return *this;
111}
112Serializer &SerializerBinary::operator>>(int16_t &p)
113{
114 fread(&p, sizeof(p), 1, fhFile);
115 return *this;
116}
117Serializer &SerializerBinary::operator>>(int32_t &p)
118{
119 printf("reding before: %d", p);
120 fread(&p, sizeof(p), 1, fhFile);
121 printf(" after: %d\n", p);
122 return *this;
123}
124Serializer &SerializerBinary::operator>>(int64_t &p)
125{
126 fread(&p, sizeof(p), 1, fhFile);
127 return *this;
128}
129Serializer &SerializerBinary::operator>>(uint8_t &p)
130{
131 fread(&p, sizeof(p), 1, fhFile);
132 return *this;
133}
134Serializer &SerializerBinary::operator>>(uint16_t &p)
135{
136 fread(&p, sizeof(p), 1, fhFile);
137 return *this;
138}
139Serializer &SerializerBinary::operator>>(uint32_t &p)
140{
141 fread(&p, sizeof(p), 1, fhFile);
142 return *this;
143}
144Serializer &SerializerBinary::operator>>(uint64_t &p)
145{
146 fread(&p, sizeof(p), 1, fhFile);
147 return *this;
148}
149Serializer &SerializerBinary::operator>>(float &p)
150{
151 fread(&p, sizeof(p), 1, fhFile);
152 return *this;
153}
154Serializer &SerializerBinary::operator>>(double &p)
155{
156 fread(&p, sizeof(p), 1, fhFile);
157 return *this;
158}
159Serializer &SerializerBinary::operator>>(long double &p)
160{
161 fread(&p, sizeof(p), 1, fhFile);
162 return *this;
163}