diff options
Diffstat (limited to 'src/serializerbinary.cpp')
-rw-r--r-- | src/serializerbinary.cpp | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/serializerbinary.cpp b/src/serializerbinary.cpp deleted file mode 100644 index ea7ed93..0000000 --- a/src/serializerbinary.cpp +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | #include "serializerbinary.h" | ||
2 | #include "serializable.h" | ||
3 | #include "exceptions.h" | ||
4 | |||
5 | SerializerBinary::SerializerBinary(FILE *fhFile, bool bLoading): | ||
6 | Serializer(bLoading), | ||
7 | fhFile(fhFile), | ||
8 | bCloseFile(false) | ||
9 | { | ||
10 | } | ||
11 | |||
12 | SerializerBinary::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 | |||
30 | SerializerBinary::~SerializerBinary() | ||
31 | { | ||
32 | close(); | ||
33 | } | ||
34 | |||
35 | void SerializerBinary::close() | ||
36 | { | ||
37 | if (fhFile != NULL && bCloseFile ) | ||
38 | { | ||
39 | fclose(fhFile); | ||
40 | fhFile = NULL; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | void SerializerBinary::write(const void * pData, int32_t nSize) | ||
45 | { | ||
46 | if( nSize == 0 ) | ||
47 | return; | ||
48 | |||
49 | fwrite(pData, nSize, 1, fhFile); | ||
50 | } | ||
51 | |||
52 | void 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 | |||