diff options
author | David <david@xagasoft.com> | 2006-05-13 00:08:20 +0000 |
---|---|---|
committer | David <david@xagasoft.com> | 2006-05-13 00:08:20 +0000 |
commit | de1aa6d66e11232edf2d7bbc729425003f6c3db5 (patch) | |
tree | 443216dc0fb9ac2bc66539332286b7b3167940b2 /src/serializerbinary.cpp | |
parent | 59cea3a2c49618ec7351028334d468a9204f4027 (diff) | |
download | libbu++-de1aa6d66e11232edf2d7bbc729425003f6c3db5.tar.gz libbu++-de1aa6d66e11232edf2d7bbc729425003f6c3db5.tar.bz2 libbu++-de1aa6d66e11232edf2d7bbc729425003f6c3db5.tar.xz libbu++-de1aa6d66e11232edf2d7bbc729425003f6c3db5.zip |
david - initial commit of serialize code ;p
Diffstat (limited to 'src/serializerbinary.cpp')
-rw-r--r-- | src/serializerbinary.cpp | 163 |
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 | |||
3 | SerializerBinary::SerializerBinary(FILE *fhFile, bool bLoading): | ||
4 | Serializer(bLoading), | ||
5 | fhFile(fhFile), | ||
6 | bCloseFile(false) | ||
7 | { | ||
8 | } | ||
9 | |||
10 | SerializerBinary::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 | |||
24 | SerializerBinary::~SerializerBinary() | ||
25 | { | ||
26 | close(); | ||
27 | } | ||
28 | |||
29 | void SerializerBinary::close() | ||
30 | { | ||
31 | if (fhFile != NULL) | ||
32 | { | ||
33 | fclose(fhFile); | ||
34 | fhFile = NULL; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | Serializer &SerializerBinary::operator<<(bool p) | ||
39 | { | ||
40 | fwrite(&p, sizeof(p), 1, fhFile); | ||
41 | return *this; | ||
42 | } | ||
43 | Serializer &SerializerBinary::operator<<(int8_t p) | ||
44 | { | ||
45 | fwrite(&p, sizeof(p), 1, fhFile); | ||
46 | return *this; | ||
47 | } | ||
48 | Serializer &SerializerBinary::operator<<(int16_t p) | ||
49 | { | ||
50 | fwrite(&p, sizeof(p), 1, fhFile); | ||
51 | return *this; | ||
52 | } | ||
53 | Serializer &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 | } | ||
59 | Serializer &SerializerBinary::operator<<(int64_t p) | ||
60 | { | ||
61 | fwrite(&p, sizeof(p), 1, fhFile); | ||
62 | return *this; | ||
63 | } | ||
64 | Serializer &SerializerBinary::operator<<(uint8_t p) | ||
65 | { | ||
66 | fwrite(&p, sizeof(p), 1, fhFile); | ||
67 | return *this; | ||
68 | } | ||
69 | Serializer &SerializerBinary::operator<<(uint16_t p) | ||
70 | { | ||
71 | fwrite(&p, sizeof(p), 1, fhFile); | ||
72 | return *this; | ||
73 | } | ||
74 | Serializer &SerializerBinary::operator<<(uint32_t p) | ||
75 | { | ||
76 | fwrite(&p, sizeof(p), 1, fhFile); | ||
77 | return *this; | ||
78 | } | ||
79 | Serializer &SerializerBinary::operator<<(uint64_t p) | ||
80 | { | ||
81 | fwrite(&p, sizeof(p), 1, fhFile); | ||
82 | return *this; | ||
83 | } | ||
84 | Serializer &SerializerBinary::operator<<(float p) | ||
85 | { | ||
86 | fwrite(&p, sizeof(p), 1, fhFile); | ||
87 | return *this; | ||
88 | } | ||
89 | Serializer &SerializerBinary::operator<<(double p) | ||
90 | { | ||
91 | fwrite(&p, sizeof(p), 1, fhFile); | ||
92 | return *this; | ||
93 | } | ||
94 | Serializer &SerializerBinary::operator<<(long double p) | ||
95 | { | ||
96 | fwrite(&p, sizeof(p), 1, fhFile); | ||
97 | return *this; | ||
98 | } | ||
99 | |||
100 | Serializer &SerializerBinary::operator>>(bool &p) | ||
101 | { | ||
102 | bool bTmp; | ||
103 | fread(&bTmp, sizeof(p), 1, fhFile); | ||
104 | p = bTmp; | ||
105 | return *this; | ||
106 | } | ||
107 | Serializer &SerializerBinary::operator>>(int8_t &p) | ||
108 | { | ||
109 | fread(&p, sizeof(p), 1, fhFile); | ||
110 | return *this; | ||
111 | } | ||
112 | Serializer &SerializerBinary::operator>>(int16_t &p) | ||
113 | { | ||
114 | fread(&p, sizeof(p), 1, fhFile); | ||
115 | return *this; | ||
116 | } | ||
117 | Serializer &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 | } | ||
124 | Serializer &SerializerBinary::operator>>(int64_t &p) | ||
125 | { | ||
126 | fread(&p, sizeof(p), 1, fhFile); | ||
127 | return *this; | ||
128 | } | ||
129 | Serializer &SerializerBinary::operator>>(uint8_t &p) | ||
130 | { | ||
131 | fread(&p, sizeof(p), 1, fhFile); | ||
132 | return *this; | ||
133 | } | ||
134 | Serializer &SerializerBinary::operator>>(uint16_t &p) | ||
135 | { | ||
136 | fread(&p, sizeof(p), 1, fhFile); | ||
137 | return *this; | ||
138 | } | ||
139 | Serializer &SerializerBinary::operator>>(uint32_t &p) | ||
140 | { | ||
141 | fread(&p, sizeof(p), 1, fhFile); | ||
142 | return *this; | ||
143 | } | ||
144 | Serializer &SerializerBinary::operator>>(uint64_t &p) | ||
145 | { | ||
146 | fread(&p, sizeof(p), 1, fhFile); | ||
147 | return *this; | ||
148 | } | ||
149 | Serializer &SerializerBinary::operator>>(float &p) | ||
150 | { | ||
151 | fread(&p, sizeof(p), 1, fhFile); | ||
152 | return *this; | ||
153 | } | ||
154 | Serializer &SerializerBinary::operator>>(double &p) | ||
155 | { | ||
156 | fread(&p, sizeof(p), 1, fhFile); | ||
157 | return *this; | ||
158 | } | ||
159 | Serializer &SerializerBinary::operator>>(long double &p) | ||
160 | { | ||
161 | fread(&p, sizeof(p), 1, fhFile); | ||
162 | return *this; | ||
163 | } | ||