00001
00020 #ifndef SERIALIS_H
00021 #define SERIALIS_H
00022
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include "memry.h"
00027 #include "errcode.h"
00028 #include "fileerr.h"
00029
00037 extern DLLSYM void *de_serialise_bytes(FILE *f, int size);
00038 extern DLLSYM void serialise_bytes(FILE *f, void *ptr, int size);
00039 extern DLLSYM void serialise_INT32(FILE *f, INT32 the_int);
00040 extern DLLSYM INT32 de_serialise_INT32(FILE *f);
00041 extern DLLSYM void serialise_FLOAT64(FILE *f, double the_float);
00042 extern DLLSYM double de_serialise_FLOAT64(FILE *f);
00043 extern DLLSYM UINT32 reverse32(
00044 UINT32 num
00045 );
00046 extern DLLSYM UINT16 reverse16(
00047 UINT16 num
00048 );
00049
00053 #define QUOTE_IT( parm ) #parm
00054
00055 #define make_serialise( CLASSNAME ) \
00056 \
00057 NEWDELETE2(CLASSNAME) \
00058 \
00059 void serialise( \
00060 FILE* f) \
00061 { \
00062 CLASSNAME* shallow_copy; \
00063 \
00064 shallow_copy = (CLASSNAME*) alloc_struct( sizeof( *this ) ); \
00065 memmove( shallow_copy, this, sizeof( *this ) ); \
00066 \
00067 shallow_copy->prep_serialise(); \
00068 if (fwrite( (char*) shallow_copy, sizeof( *shallow_copy ), 1, f ) != 1)\
00069 WRITEFAILED.error( QUOTE_IT( CLASSNAME::serialise ), \
00070 ABORT, NULL ); \
00071 \
00072 free_struct( shallow_copy, sizeof( *this ) ); \
00073 this->dump( f ); \
00074 } \
00075 \
00076 static CLASSNAME* de_serialise( \
00077 FILE* f) \
00078 { \
00079 CLASSNAME* restored; \
00080 \
00081 restored = (CLASSNAME*) alloc_struct( sizeof( CLASSNAME ) );\
00082 if (fread( (char*) restored, sizeof( CLASSNAME ), 1, f ) != 1)\
00083 READFAILED.error( QUOTE_IT( CLASSNAME::de_serialise ), \
00084 ABORT, NULL ); \
00085 \
00086 restored->de_dump( f ); \
00087 return restored; \
00088 }
00089 #endif