aboutsummaryrefslogtreecommitdiff
path: root/src/serializertext.cpp
diff options
context:
space:
mode:
authorDavid <david@xagasoft.com>2006-05-13 01:52:31 +0000
committerDavid <david@xagasoft.com>2006-05-13 01:52:31 +0000
commit3df557a87b39fc4c2ff14006506e6992d1620ab0 (patch)
treeeb9a3fe0be541fed4acd07794b7d64157ea429d3 /src/serializertext.cpp
parent632e1d1dbe6ac35eba93523dd144129af1122ca2 (diff)
downloadlibbu++-3df557a87b39fc4c2ff14006506e6992d1620ab0.tar.gz
libbu++-3df557a87b39fc4c2ff14006506e6992d1620ab0.tar.bz2
libbu++-3df557a87b39fc4c2ff14006506e6992d1620ab0.tar.xz
libbu++-3df557a87b39fc4c2ff14006506e6992d1620ab0.zip
david - initial NOT WORKING commit of SerializerText stuff...
Diffstat (limited to '')
-rw-r--r--src/serializertext.cpp170
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
3SerializerText::SerializerText(FILE *fhFile, bool bLoading):
4 Serializer(bLoading),
5 fhFile(fhFile),
6 bCloseFile(false)
7{
8}
9
10SerializerText::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
24SerializerText::~SerializerText()
25{
26 close();
27}
28
29void SerializerText::close()
30{
31 if (fhFile != NULL)
32 {
33 fclose(fhFile);
34 fhFile = NULL;
35 }
36}
37
38void SerializerText::write(void * pData, int32_t nSize)
39{
40 fwrite(pData, nSize, 1, fhFile);
41 fprintf(fhFile, "\n");
42}
43
44void SerializerText::read(void * pData, int32_t nSize)
45{
46 fread(pData, nSize, 1, fhFile);
47 fgetc(fhFile);
48}
49
50Serializer &SerializerText::operator<<(bool p)
51{
52 fprintf(fhFile, "%hhd\n", p);
53 return *this;
54}
55Serializer &SerializerText::operator<<(int8_t p)
56{
57 fprintf(fhFile, "%hhd\n", p);
58 return *this;
59}
60Serializer &SerializerText::operator<<(int16_t p)
61{
62 fprintf(fhFile, "%hd\n", p);
63 return *this;
64}
65Serializer &SerializerText::operator<<(int32_t p)
66{
67 fprintf(fhFile, "%ld\n", p);
68 return *this;
69}
70Serializer &SerializerText::operator<<(int64_t p)
71{
72 fprintf(fhFile, "%lld\n", p);
73 return *this;
74}
75Serializer &SerializerText::operator<<(uint8_t p)
76{
77 fprintf(fhFile, "%hhu\n", p);
78 return *this;
79}
80Serializer &SerializerText::operator<<(uint16_t p)
81{
82 fprintf(fhFile, "%hu\n", p);
83 return *this;
84}
85Serializer &SerializerText::operator<<(uint32_t p)
86{
87 fprintf(fhFile, "%lu\n", p);
88 return *this;
89}
90Serializer &SerializerText::operator<<(uint64_t p)
91{
92 fprintf(fhFile, "%llu\n", p);
93 return *this;
94}
95Serializer &SerializerText::operator<<(float p)
96{
97 fprintf(fhFile, "%f\n", p);
98 return *this;
99}
100Serializer &SerializerText::operator<<(double p)
101{
102 fprintf(fhFile, "%f\n", p);
103 return *this;
104}
105Serializer &SerializerText::operator<<(long double p)
106{
107 fprintf(fhFile, "%Lf\n", p);
108 return *this;
109}
110
111Serializer &SerializerText::operator>>(bool &p)
112{
113 fscanf(fhFile, "%hhd\n", &p);
114 return *this;
115}
116Serializer &SerializerText::operator>>(int8_t &p)
117{
118 fscanf(fhFile, "%hhd\n", &p);
119 return *this;
120}
121Serializer &SerializerText::operator>>(int16_t &p)
122{
123 fscanf(fhFile, "%hd\n", &p);
124 return *this;
125}
126Serializer &SerializerText::operator>>(int32_t &p)
127{
128 fscanf(fhFile, "%ld\n", &p);
129 return *this;
130}
131Serializer &SerializerText::operator>>(int64_t &p)
132{
133 fscanf(fhFile, "%lld\n", &p);
134 return *this;
135}
136Serializer &SerializerText::operator>>(uint8_t &p)
137{
138 fscanf(fhFile, "%hhu\n", &p);
139 return *this;
140}
141Serializer &SerializerText::operator>>(uint16_t &p)
142{
143 fscanf(fhFile, "%hu\n", &p);
144 return *this;
145}
146Serializer &SerializerText::operator>>(uint32_t &p)
147{
148 fscanf(fhFile, "%lu\n", &p);
149 return *this;
150}
151Serializer &SerializerText::operator>>(uint64_t &p)
152{
153 fscanf(fhFile, "%llu\n", &p);
154 return *this;
155}
156Serializer &SerializerText::operator>>(float &p)
157{
158 fscanf(fhFile, "%f\n", &p);
159 return *this;
160}
161Serializer &SerializerText::operator>>(double &p)
162{
163 fscanf(fhFile, "%f\n", &p);
164 return *this;
165}
166Serializer &SerializerText::operator>>(long double &p)
167{
168 fscanf(fhFile, "%Lf\n", &p);
169 return *this;
170}