00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 extern DLLSYM void *de_serialise_bytes(FILE *f, int size);
00041 extern DLLSYM void serialise_bytes(FILE *f, void *ptr, int size);
00042 extern DLLSYM void serialise_INT32(FILE *f, inT32 the_int);
00043 extern DLLSYM inT32 de_serialise_INT32(FILE *f);
00044 extern DLLSYM void serialise_FLOAT64(FILE *f, double the_float);
00045 extern DLLSYM double de_serialise_FLOAT64(FILE *f);
00046
00047 extern DLLSYM uinT64 reverse64(uinT64);
00048 extern DLLSYM uinT32 reverse32(uinT32);
00049 extern DLLSYM uinT16 reverse16(uinT16);
00050
00051
00052
00053
00054
00055
00056
00057 #define QUOTE_IT( parm ) #parm
00058
00059 #define make_serialise( CLASSNAME ) \
00060 \
00061 NEWDELETE2(CLASSNAME) \
00062 \
00063 void serialise( \
00064 FILE* f) \
00065 { \
00066 CLASSNAME* shallow_copy; \
00067 \
00068 shallow_copy = (CLASSNAME*) alloc_struct( sizeof( *this ) ); \
00069 memmove( shallow_copy, this, sizeof( *this ) ); \
00070 \
00071 shallow_copy->prep_serialise(); \
00072 if (fwrite( (char*) shallow_copy, sizeof( *shallow_copy ), 1, f ) != 1) \
00073 WRITEFAILED.error( QUOTE_IT( CLASSNAME::serialise ), \
00074 ABORT, NULL ); \
00075 \
00076 free_struct( shallow_copy, sizeof( *this ) ); \
00077 this->dump( f ); \
00078 } \
00079 \
00080 static CLASSNAME* de_serialise( \
00081 FILE* f) \
00082 { \
00083 CLASSNAME* restored; \
00084 \
00085 restored = (CLASSNAME*) alloc_struct( sizeof( CLASSNAME ) ); \
00086 if (fread( (char*) restored, sizeof( CLASSNAME ), 1, f ) != 1) \
00087 READFAILED.error( QUOTE_IT( CLASSNAME::de_serialise ), \
00088 ABORT, NULL ); \
00089 \
00090 restored->de_dump( f ); \
00091 return restored; \
00092 }
00093 #endif