ccutil/serialis.cpp

Go to the documentation of this file.
00001 
00025 #include          "mfcpch.h"     //precompiled headers
00026 #include "serialis.h"
00027 #include "scanutils.h"
00028 
00032 DLLSYM void *de_serialise_bytes(FILE *f, int size) { 
00033   void *ptr;
00034 
00035   ptr = alloc_mem (size);
00036   /*
00037   printf( "De_serialising bytes\n" );
00038   printf( "  Addr: %d    Size: %d\n", int(ptr), size );
00039   */
00040   if (fread (ptr, size, 1, f) != 1)
00041     READFAILED.error ("de_serialise_bytes", ABORT, NULL);
00042   return ptr;
00043 }
00044 
00045 
00049 DLLSYM void serialise_bytes(FILE *f, void *ptr, int size) { 
00050   /*
00051   printf( "Serialising bytes\n" );
00052   printf( "  Addr: %d    Size: %d\n", int(ptr), size );
00053   */
00054   if (fwrite (ptr, size, 1, f) != 1)
00055     WRITEFAILED.error ("serialise_bytes", ABORT, NULL);
00056 }
00057 
00058 
00062 DLLSYM void serialise_INT32(FILE *f, INT32 the_int) { 
00063   if (fprintf (f, INT32FORMAT "\n", the_int) < 0)
00064     WRITEFAILED.error ("serialise_INT32", ABORT, NULL);
00065 }
00066 
00067 
00071 DLLSYM INT32 de_serialise_INT32(FILE *f) { 
00072   INT32 the_int;
00073 
00074   if (fscanf (f, INT32FORMAT, &the_int) != 1)
00075     READFAILED.error ("de_serialise_INT32", ABORT, NULL);
00076   return the_int;
00077 }
00078 
00079 
00083 DLLSYM void serialise_FLOAT64(FILE *f, double the_float) { 
00084   if (fprintf (f, "%g\n", the_float) < 0)
00085     WRITEFAILED.error ("serialise_FLOAT64", ABORT, NULL);
00086 }
00087 
00088 
00092 DLLSYM double de_serialise_FLOAT64(FILE *f) { 
00093   double the_float;
00094 
00095   if (fscanf (f, "%lg", &the_float) != 1)
00096     READFAILED.error ("de_serialise_FLOAT64", ABORT, NULL);
00097   return the_float;
00098 }
00099 
00100 
00104 DLLSYM UINT32 reverse32(            //switch endian
00105                         UINT32 num  //number to fix
00106                        ) {
00107   return (reverse16 ((UINT16) (num & 0xffff)) << 16)
00108     | reverse16 ((UINT16) ((num >> 16) & 0xffff));
00109 }
00110 
00111 
00115 DLLSYM UINT16 reverse16(            //switch endian
00116                         UINT16 num  //number to fix
00117                        ) {
00118   return ((num & 0xff) << 8) | ((num >> 8) & 0xff);
00119 }

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1