diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
| commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
| tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/old/serializerbinary.cpp | |
| parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
| parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
| download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip | |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/old/serializerbinary.cpp')
| -rw-r--r-- | src/old/serializerbinary.cpp | 63 |
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 | |||
| 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 | |||
