aboutsummaryrefslogtreecommitdiff
path: root/src/old/serializerbinary.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
commitf4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch)
tree13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/old/serializerbinary.cpp
parent74d4c8cd27334fc7204d5a8773deb3d424565778 (diff)
downloadlibbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/old/serializerbinary.cpp')
-rw-r--r--src/old/serializerbinary.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/old/serializerbinary.cpp b/src/old/serializerbinary.cpp
new file mode 100644
index 0000000..ea7ed93
--- /dev/null
+++ b/src/old/serializerbinary.cpp
@@ -0,0 +1,63 @@
1#include "serializerbinary.h"
2#include "serializable.h"
3#include "exceptions.h"
4
5SerializerBinary::SerializerBinary(FILE *fhFile, bool bLoading):
6 Serializer(bLoading),
7 fhFile(fhFile),
8 bCloseFile(false)
9{
10}
11
12SerializerBinary::SerializerBinary(const char *sFileName, bool bLoading):
13 Serializer(bLoading),
14 bCloseFile(true)
15{
16 if (bLoading)
17 {
18 fhFile = fopen(sFileName, "rb");
19 if( fhFile == NULL )
20 throw FileException("Unable to open file: %s", sFileName );
21 }
22 else
23 {
24 fhFile = fopen(sFileName, "wb");
25 if( fhFile == NULL )
26 throw FileException("Unable to open file: %s", sFileName );
27 }
28}
29
30SerializerBinary::~SerializerBinary()
31{
32 close();
33}
34
35void SerializerBinary::close()
36{
37 if (fhFile != NULL && bCloseFile )
38 {
39 fclose(fhFile);
40 fhFile = NULL;
41 }
42}
43
44void SerializerBinary::write(const void * pData, int32_t nSize)
45{
46 if( nSize == 0 )
47 return;
48
49 fwrite(pData, nSize, 1, fhFile);
50}
51
52void SerializerBinary::read(void * pData, int32_t nSize)
53{
54 if( nSize == 0 )
55 return;
56
57 uint32_t nRead = fread(pData, nSize, 1, fhFile);
58 if( nRead < 1 )
59 {
60 throw FileException( excodeEOF, "End of file read");
61 }
62}
63