aboutsummaryrefslogtreecommitdiff
path: root/src/old/serializerbinary.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/old/serializerbinary.cpp63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/old/serializerbinary.cpp b/src/old/serializerbinary.cpp
deleted file mode 100644
index ea7ed93..0000000
--- a/src/old/serializerbinary.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
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