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