aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-11-25 23:38:14 +0000
committerMike Buland <eichlan@xagasoft.com>2006-11-25 23:38:14 +0000
commit27e0164234c916adaf0ce78e29dffe565302ef53 (patch)
tree9153d33a0fcd67c38daba80a4f6c406a8701cec4 /src
parent2828a0bb77e2cf1bc6fbd38c3bca5cfaddb23b80 (diff)
downloadlibbu++-27e0164234c916adaf0ce78e29dffe565302ef53.tar.gz
libbu++-27e0164234c916adaf0ce78e29dffe565302ef53.tar.bz2
libbu++-27e0164234c916adaf0ce78e29dffe565302ef53.tar.xz
libbu++-27e0164234c916adaf0ce78e29dffe565302ef53.zip
I think this is a better serializer model.
Diffstat (limited to '')
-rw-r--r--src/exceptions.h5
-rw-r--r--src/serializer.cpp121
-rw-r--r--src/serializer.h48
-rw-r--r--src/serializerbinary.cpp126
-rw-r--r--src/serializerbinary.h26
-rw-r--r--src/serializerbzip2.cpp122
-rw-r--r--src/serializerbzip2.h26
7 files changed, 154 insertions, 320 deletions
diff --git a/src/exceptions.h b/src/exceptions.h
index b4126b7..cf9d47a 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -8,6 +8,11 @@ subExceptionDecl( XmlException )
8subExceptionDecl( FileException ) 8subExceptionDecl( FileException )
9subExceptionDecl( ConnectionException ) 9subExceptionDecl( ConnectionException )
10 10
11enum eFileException
12{
13 excodeEOF
14};
15
11enum eConnectionException 16enum eConnectionException
12{ 17{
13 excodeReadError, 18 excodeReadError,
diff --git a/src/serializer.cpp b/src/serializer.cpp
index 0afaf4b..587f613 100644
--- a/src/serializer.cpp
+++ b/src/serializer.cpp
@@ -14,6 +14,127 @@ bool Serializer::isLoading()
14{ 14{
15 return bLoading; 15 return bLoading;
16} 16}
17Serializer &Serializer::operator<<(bool p)
18{
19 write( &p, sizeof(p) );
20 return *this;
21}
22Serializer &Serializer::operator<<(int8_t p)
23{
24 write( &p, sizeof(p) );
25 return *this;
26}
27Serializer &Serializer::operator<<(int16_t p)
28{
29 write( &p, sizeof(p) );
30 return *this;
31}
32Serializer &Serializer::operator<<(int32_t p)
33{
34 write( &p, sizeof(p) );
35 return *this;
36}
37Serializer &Serializer::operator<<(int64_t p)
38{
39 write( &p, sizeof(p) );
40 return *this;
41}
42Serializer &Serializer::operator<<(uint8_t p)
43{
44 write( &p, sizeof(p) );
45 return *this;
46}
47Serializer &Serializer::operator<<(uint16_t p)
48{
49 write( &p, sizeof(p) );
50 return *this;
51}
52Serializer &Serializer::operator<<(uint32_t p)
53{
54 write( &p, sizeof(p) );
55 return *this;
56}
57Serializer &Serializer::operator<<(uint64_t p)
58{
59 write( &p, sizeof(p) );
60 return *this;
61}
62Serializer &Serializer::operator<<(float p)
63{
64 write( &p, sizeof(p) );
65 return *this;
66}
67Serializer &Serializer::operator<<(double p)
68{
69 write( &p, sizeof(p) );
70 return *this;
71}
72Serializer &Serializer::operator<<(long double p)
73{
74 write( &p, sizeof(p) );
75 return *this;
76}
77
78Serializer &Serializer::operator>>(bool &p)
79{
80 read( &p, sizeof(p) );
81 return *this;
82}
83Serializer &Serializer::operator>>(int8_t &p)
84{
85 read( &p, sizeof(p) );
86 return *this;
87}
88Serializer &Serializer::operator>>(int16_t &p)
89{
90 read( &p, sizeof(p) );
91 return *this;
92}
93Serializer &Serializer::operator>>(int32_t &p)
94{
95 read( &p, sizeof(p) );
96 return *this;
97}
98Serializer &Serializer::operator>>(int64_t &p)
99{
100 read( &p, sizeof(p) );
101 return *this;
102}
103Serializer &Serializer::operator>>(uint8_t &p)
104{
105 read( &p, sizeof(p) );
106 return *this;
107}
108Serializer &Serializer::operator>>(uint16_t &p)
109{
110 read( &p, sizeof(p) );
111 return *this;
112}
113Serializer &Serializer::operator>>(uint32_t &p)
114{
115 read( &p, sizeof(p) );
116 return *this;
117}
118Serializer &Serializer::operator>>(uint64_t &p)
119{
120 read( &p, sizeof(p) );
121 return *this;
122}
123Serializer &Serializer::operator>>(float &p)
124{
125 read( &p, sizeof(p) );
126 return *this;
127}
128Serializer &Serializer::operator>>(double &p)
129{
130 read( &p, sizeof(p) );
131 return *this;
132}
133Serializer &Serializer::operator>>(long double &p)
134{
135 read( &p, sizeof(p) );
136 return *this;
137}
17 138
18/*Serializer::Serializer &operator&(bool &p) 139/*Serializer::Serializer &operator&(bool &p)
19{ 140{
diff --git a/src/serializer.h b/src/serializer.h
index 334c3c7..e79c810 100644
--- a/src/serializer.h
+++ b/src/serializer.h
@@ -26,31 +26,31 @@ public:
26 virtual void write(const void *, int32_t)=0; 26 virtual void write(const void *, int32_t)=0;
27 virtual void read(void *, int32_t)=0; 27 virtual void read(void *, int32_t)=0;
28 28
29 virtual Serializer &operator<<(bool)=0; 29 virtual Serializer &operator<<(bool);
30 virtual Serializer &operator<<(int8_t)=0; 30 virtual Serializer &operator<<(int8_t);
31 virtual Serializer &operator<<(int16_t)=0; 31 virtual Serializer &operator<<(int16_t);
32 virtual Serializer &operator<<(int32_t)=0; 32 virtual Serializer &operator<<(int32_t);
33 virtual Serializer &operator<<(int64_t)=0; 33 virtual Serializer &operator<<(int64_t);
34 virtual Serializer &operator<<(uint8_t)=0; 34 virtual Serializer &operator<<(uint8_t);
35 virtual Serializer &operator<<(uint16_t)=0; 35 virtual Serializer &operator<<(uint16_t);
36 virtual Serializer &operator<<(uint32_t)=0; 36 virtual Serializer &operator<<(uint32_t);
37 virtual Serializer &operator<<(uint64_t)=0; 37 virtual Serializer &operator<<(uint64_t);
38 virtual Serializer &operator<<(float)=0; 38 virtual Serializer &operator<<(float);
39 virtual Serializer &operator<<(double)=0; 39 virtual Serializer &operator<<(double);
40 virtual Serializer &operator<<(long double)=0; 40 virtual Serializer &operator<<(long double);
41 41
42 virtual Serializer &operator>>(bool &)=0; 42 virtual Serializer &operator>>(bool &);
43 virtual Serializer &operator>>(int8_t &)=0; 43 virtual Serializer &operator>>(int8_t &);
44 virtual Serializer &operator>>(int16_t &)=0; 44 virtual Serializer &operator>>(int16_t &);
45 virtual Serializer &operator>>(int32_t &)=0; 45 virtual Serializer &operator>>(int32_t &);
46 virtual Serializer &operator>>(int64_t &)=0; 46 virtual Serializer &operator>>(int64_t &);
47 virtual Serializer &operator>>(uint8_t &)=0; 47 virtual Serializer &operator>>(uint8_t &);
48 virtual Serializer &operator>>(uint16_t &)=0; 48 virtual Serializer &operator>>(uint16_t &);
49 virtual Serializer &operator>>(uint32_t &)=0; 49 virtual Serializer &operator>>(uint32_t &);
50 virtual Serializer &operator>>(uint64_t &)=0; 50 virtual Serializer &operator>>(uint64_t &);
51 virtual Serializer &operator>>(float &)=0; 51 virtual Serializer &operator>>(float &);
52 virtual Serializer &operator>>(double &)=0; 52 virtual Serializer &operator>>(double &);
53 virtual Serializer &operator>>(long double &)=0; 53 virtual Serializer &operator>>(long double &);
54 54
55 /* 55 /*
56 virtual Serializer &operator&(bool &); 56 virtual Serializer &operator&(bool &);
diff --git a/src/serializerbinary.cpp b/src/serializerbinary.cpp
index 23fb2b1..bfe3cc9 100644
--- a/src/serializerbinary.cpp
+++ b/src/serializerbinary.cpp
@@ -48,127 +48,9 @@ void SerializerBinary::write(const void * pData, int32_t nSize)
48 48
49void SerializerBinary::read(void * pData, int32_t nSize) 49void SerializerBinary::read(void * pData, int32_t nSize)
50{ 50{
51 fread(pData, nSize, 1, fhFile); 51 if( fread(pData, nSize, 1, fhFile) < 1 )
52} 52 {
53 53 throw FileException( excodeEOF, "End of file read");
54Serializer &SerializerBinary::operator<<(bool p) 54 }
55{
56 fwrite(&p, sizeof(p), 1, fhFile);
57 return *this;
58}
59Serializer &SerializerBinary::operator<<(int8_t p)
60{
61 fwrite(&p, sizeof(p), 1, fhFile);
62 return *this;
63}
64Serializer &SerializerBinary::operator<<(int16_t p)
65{
66 fwrite(&p, sizeof(p), 1, fhFile);
67 return *this;
68}
69Serializer &SerializerBinary::operator<<(int32_t p)
70{
71 fwrite(&p, sizeof(p), 1, fhFile);
72 return *this;
73}
74Serializer &SerializerBinary::operator<<(int64_t p)
75{
76 fwrite(&p, sizeof(p), 1, fhFile);
77 return *this;
78}
79Serializer &SerializerBinary::operator<<(uint8_t p)
80{
81 fwrite(&p, sizeof(p), 1, fhFile);
82 return *this;
83}
84Serializer &SerializerBinary::operator<<(uint16_t p)
85{
86 fwrite(&p, sizeof(p), 1, fhFile);
87 return *this;
88}
89Serializer &SerializerBinary::operator<<(uint32_t p)
90{
91 fwrite(&p, sizeof(p), 1, fhFile);
92 return *this;
93}
94Serializer &SerializerBinary::operator<<(uint64_t p)
95{
96 fwrite(&p, sizeof(p), 1, fhFile);
97 return *this;
98}
99Serializer &SerializerBinary::operator<<(float p)
100{
101 fwrite(&p, sizeof(p), 1, fhFile);
102 return *this;
103}
104Serializer &SerializerBinary::operator<<(double p)
105{
106 fwrite(&p, sizeof(p), 1, fhFile);
107 return *this;
108}
109Serializer &SerializerBinary::operator<<(long double p)
110{
111 fwrite(&p, sizeof(p), 1, fhFile);
112 return *this;
113} 55}
114 56
115Serializer &SerializerBinary::operator>>(bool &p)
116{
117 fread(&p, sizeof(p), 1, fhFile);
118 return *this;
119}
120Serializer &SerializerBinary::operator>>(int8_t &p)
121{
122 fread(&p, sizeof(p), 1, fhFile);
123 return *this;
124}
125Serializer &SerializerBinary::operator>>(int16_t &p)
126{
127 fread(&p, sizeof(p), 1, fhFile);
128 return *this;
129}
130Serializer &SerializerBinary::operator>>(int32_t &p)
131{
132 fread(&p, sizeof(p), 1, fhFile);
133 return *this;
134}
135Serializer &SerializerBinary::operator>>(int64_t &p)
136{
137 fread(&p, sizeof(p), 1, fhFile);
138 return *this;
139}
140Serializer &SerializerBinary::operator>>(uint8_t &p)
141{
142 fread(&p, sizeof(p), 1, fhFile);
143 return *this;
144}
145Serializer &SerializerBinary::operator>>(uint16_t &p)
146{
147 fread(&p, sizeof(p), 1, fhFile);
148 return *this;
149}
150Serializer &SerializerBinary::operator>>(uint32_t &p)
151{
152 fread(&p, sizeof(p), 1, fhFile);
153 return *this;
154}
155Serializer &SerializerBinary::operator>>(uint64_t &p)
156{
157 fread(&p, sizeof(p), 1, fhFile);
158 return *this;
159}
160Serializer &SerializerBinary::operator>>(float &p)
161{
162 fread(&p, sizeof(p), 1, fhFile);
163 return *this;
164}
165Serializer &SerializerBinary::operator>>(double &p)
166{
167 fread(&p, sizeof(p), 1, fhFile);
168 return *this;
169}
170Serializer &SerializerBinary::operator>>(long double &p)
171{
172 fread(&p, sizeof(p), 1, fhFile);
173 return *this;
174}
diff --git a/src/serializerbinary.h b/src/serializerbinary.h
index 2930077..8510fcd 100644
--- a/src/serializerbinary.h
+++ b/src/serializerbinary.h
@@ -16,32 +16,6 @@ public:
16 virtual void write(const void *, int32_t); 16 virtual void write(const void *, int32_t);
17 virtual void read(void *, int32_t); 17 virtual void read(void *, int32_t);
18 18
19 virtual Serializer &operator<<(bool);
20 virtual Serializer &operator<<(int8_t);
21 virtual Serializer &operator<<(int16_t);
22 virtual Serializer &operator<<(int32_t);
23 virtual Serializer &operator<<(int64_t);
24 virtual Serializer &operator<<(uint8_t);
25 virtual Serializer &operator<<(uint16_t);
26 virtual Serializer &operator<<(uint32_t);
27 virtual Serializer &operator<<(uint64_t);
28 virtual Serializer &operator<<(float);
29 virtual Serializer &operator<<(double);
30 virtual Serializer &operator<<(long double);
31
32 virtual Serializer &operator>>(bool &);
33 virtual Serializer &operator>>(int8_t &);
34 virtual Serializer &operator>>(int16_t &);
35 virtual Serializer &operator>>(int32_t &);
36 virtual Serializer &operator>>(int64_t &);
37 virtual Serializer &operator>>(uint8_t &);
38 virtual Serializer &operator>>(uint16_t &);
39 virtual Serializer &operator>>(uint32_t &);
40 virtual Serializer &operator>>(uint64_t &);
41 virtual Serializer &operator>>(float &);
42 virtual Serializer &operator>>(double &);
43 virtual Serializer &operator>>(long double &);
44
45private: 19private:
46 FILE *fhFile; 20 FILE *fhFile;
47 bool bCloseFile; 21 bool bCloseFile;
diff --git a/src/serializerbzip2.cpp b/src/serializerbzip2.cpp
index 9d4dafa..bafabc8 100644
--- a/src/serializerbzip2.cpp
+++ b/src/serializerbzip2.cpp
@@ -86,125 +86,3 @@ void SerializerBZip2::read(void * pData, int32_t nSize)
86 checkBZError(); 86 checkBZError();
87} 87}
88 88
89Serializer &SerializerBZip2::operator<<(bool p)
90{
91 write( &p, sizeof(p) );
92 return *this;
93}
94Serializer &SerializerBZip2::operator<<(int8_t p)
95{
96 write( &p, sizeof(p) );
97 return *this;
98}
99Serializer &SerializerBZip2::operator<<(int16_t p)
100{
101 write (&p, sizeof(p) );
102 return *this;
103}
104Serializer &SerializerBZip2::operator<<(int32_t p)
105{
106 write( &p, sizeof(p) );
107 return *this;
108}
109Serializer &SerializerBZip2::operator<<(int64_t p)
110{
111 write( &p, sizeof(p) );
112 return *this;
113}
114Serializer &SerializerBZip2::operator<<(uint8_t p)
115{
116 write( &p, sizeof(p) );
117 return *this;
118}
119Serializer &SerializerBZip2::operator<<(uint16_t p)
120{
121 write( &p, sizeof(p) );
122 return *this;
123}
124Serializer &SerializerBZip2::operator<<(uint32_t p)
125{
126 write( &p, sizeof(p) );
127 return *this;
128}
129Serializer &SerializerBZip2::operator<<(uint64_t p)
130{
131 write( &p, sizeof(p) );
132 return *this;
133}
134Serializer &SerializerBZip2::operator<<(float p)
135{
136 write( &p, sizeof(p) );
137 return *this;
138}
139Serializer &SerializerBZip2::operator<<(double p)
140{
141 write( &p, sizeof(p) );
142 return *this;
143}
144Serializer &SerializerBZip2::operator<<(long double p)
145{
146 write( &p, sizeof(p) );
147 return *this;
148}
149
150Serializer &SerializerBZip2::operator>>(bool &p)
151{
152 read( &p, sizeof(p) );
153 return *this;
154}
155Serializer &SerializerBZip2::operator>>(int8_t &p)
156{
157 read( &p, sizeof(p) );
158 return *this;
159}
160Serializer &SerializerBZip2::operator>>(int16_t &p)
161{
162 read( &p, sizeof(p) );
163 return *this;
164}
165Serializer &SerializerBZip2::operator>>(int32_t &p)
166{
167 read( &p, sizeof(p) );
168 return *this;
169}
170Serializer &SerializerBZip2::operator>>(int64_t &p)
171{
172 read( &p, sizeof(p) );
173 return *this;
174}
175Serializer &SerializerBZip2::operator>>(uint8_t &p)
176{
177 read( &p, sizeof(p) );
178 return *this;
179}
180Serializer &SerializerBZip2::operator>>(uint16_t &p)
181{
182 read( &p, sizeof(p) );
183 return *this;
184}
185Serializer &SerializerBZip2::operator>>(uint32_t &p)
186{
187 read( &p, sizeof(p) );
188 return *this;
189}
190Serializer &SerializerBZip2::operator>>(uint64_t &p)
191{
192 read( &p, sizeof(p) );
193 return *this;
194}
195Serializer &SerializerBZip2::operator>>(float &p)
196{
197 read( &p, sizeof(p) );
198 return *this;
199}
200Serializer &SerializerBZip2::operator>>(double &p)
201{
202 read( &p, sizeof(p) );
203 return *this;
204}
205Serializer &SerializerBZip2::operator>>(long double &p)
206{
207 read( &p, sizeof(p) );
208 return *this;
209}
210
diff --git a/src/serializerbzip2.h b/src/serializerbzip2.h
index 098c66e..4aeb22e 100644
--- a/src/serializerbzip2.h
+++ b/src/serializerbzip2.h
@@ -16,32 +16,6 @@ public:
16 virtual void write(const void *, int32_t); 16 virtual void write(const void *, int32_t);
17 virtual void read(void *, int32_t); 17 virtual void read(void *, int32_t);
18 18
19 virtual Serializer &operator<<(bool);
20 virtual Serializer &operator<<(int8_t);
21 virtual Serializer &operator<<(int16_t);
22 virtual Serializer &operator<<(int32_t);
23 virtual Serializer &operator<<(int64_t);
24 virtual Serializer &operator<<(uint8_t);
25 virtual Serializer &operator<<(uint16_t);
26 virtual Serializer &operator<<(uint32_t);
27 virtual Serializer &operator<<(uint64_t);
28 virtual Serializer &operator<<(float);
29 virtual Serializer &operator<<(double);
30 virtual Serializer &operator<<(long double);
31
32 virtual Serializer &operator>>(bool &);
33 virtual Serializer &operator>>(int8_t &);
34 virtual Serializer &operator>>(int16_t &);
35 virtual Serializer &operator>>(int32_t &);
36 virtual Serializer &operator>>(int64_t &);
37 virtual Serializer &operator>>(uint8_t &);
38 virtual Serializer &operator>>(uint16_t &);
39 virtual Serializer &operator>>(uint32_t &);
40 virtual Serializer &operator>>(uint64_t &);
41 virtual Serializer &operator>>(float &);
42 virtual Serializer &operator>>(double &);
43 virtual Serializer &operator>>(long double &);
44
45private: 19private:
46 void checkBZError(); 20 void checkBZError();
47 FILE *fhFile; 21 FILE *fhFile;