From 3df557a87b39fc4c2ff14006506e6992d1620ab0 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 13 May 2006 01:52:31 +0000 Subject: david - initial NOT WORKING commit of SerializerText stuff... --- src/serializertext.cpp | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/serializertext.cpp (limited to 'src/serializertext.cpp') diff --git a/src/serializertext.cpp b/src/serializertext.cpp new file mode 100644 index 0000000..c650eae --- /dev/null +++ b/src/serializertext.cpp @@ -0,0 +1,170 @@ +#include "serializertext.h" + +SerializerText::SerializerText(FILE *fhFile, bool bLoading): + Serializer(bLoading), + fhFile(fhFile), + bCloseFile(false) +{ +} + +SerializerText::SerializerText(char *sFileName, bool bLoading): + Serializer(bLoading), + bCloseFile(true) +{ + if (bLoading) + { + fhFile = fopen(sFileName, "rt"); + } + else + { + fhFile = fopen(sFileName, "wt"); + } +} + +SerializerText::~SerializerText() +{ + close(); +} + +void SerializerText::close() +{ + if (fhFile != NULL) + { + fclose(fhFile); + fhFile = NULL; + } +} + +void SerializerText::write(void * pData, int32_t nSize) +{ + fwrite(pData, nSize, 1, fhFile); + fprintf(fhFile, "\n"); +} + +void SerializerText::read(void * pData, int32_t nSize) +{ + fread(pData, nSize, 1, fhFile); + fgetc(fhFile); +} + +Serializer &SerializerText::operator<<(bool p) +{ + fprintf(fhFile, "%hhd\n", p); + return *this; +} +Serializer &SerializerText::operator<<(int8_t p) +{ + fprintf(fhFile, "%hhd\n", p); + return *this; +} +Serializer &SerializerText::operator<<(int16_t p) +{ + fprintf(fhFile, "%hd\n", p); + return *this; +} +Serializer &SerializerText::operator<<(int32_t p) +{ + fprintf(fhFile, "%ld\n", p); + return *this; +} +Serializer &SerializerText::operator<<(int64_t p) +{ + fprintf(fhFile, "%lld\n", p); + return *this; +} +Serializer &SerializerText::operator<<(uint8_t p) +{ + fprintf(fhFile, "%hhu\n", p); + return *this; +} +Serializer &SerializerText::operator<<(uint16_t p) +{ + fprintf(fhFile, "%hu\n", p); + return *this; +} +Serializer &SerializerText::operator<<(uint32_t p) +{ + fprintf(fhFile, "%lu\n", p); + return *this; +} +Serializer &SerializerText::operator<<(uint64_t p) +{ + fprintf(fhFile, "%llu\n", p); + return *this; +} +Serializer &SerializerText::operator<<(float p) +{ + fprintf(fhFile, "%f\n", p); + return *this; +} +Serializer &SerializerText::operator<<(double p) +{ + fprintf(fhFile, "%f\n", p); + return *this; +} +Serializer &SerializerText::operator<<(long double p) +{ + fprintf(fhFile, "%Lf\n", p); + return *this; +} + +Serializer &SerializerText::operator>>(bool &p) +{ + fscanf(fhFile, "%hhd\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(int8_t &p) +{ + fscanf(fhFile, "%hhd\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(int16_t &p) +{ + fscanf(fhFile, "%hd\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(int32_t &p) +{ + fscanf(fhFile, "%ld\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(int64_t &p) +{ + fscanf(fhFile, "%lld\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(uint8_t &p) +{ + fscanf(fhFile, "%hhu\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(uint16_t &p) +{ + fscanf(fhFile, "%hu\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(uint32_t &p) +{ + fscanf(fhFile, "%lu\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(uint64_t &p) +{ + fscanf(fhFile, "%llu\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(float &p) +{ + fscanf(fhFile, "%f\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(double &p) +{ + fscanf(fhFile, "%f\n", &p); + return *this; +} +Serializer &SerializerText::operator>>(long double &p) +{ + fscanf(fhFile, "%Lf\n", &p); + return *this; +} -- cgit v1.2.3