/home66/gary/public_html/cloudy/c08_branch/source/container_classes.cpp

Go to the documentation of this file.
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
00002  * others.  For conditions of distribution and use see copyright notice in license.txt */
00003 
00004 #include "cddefines.h"
00005 
00008 void do_dump_state(const void* buf, size_t nelem, size_t size, FILE* out, int32 magic)
00009 {
00010         DEBUG_ENTRY( "do_dump_state()" );
00011 
00012         bool lgErr = ( fwrite( &magic, sizeof(int32), 1, out ) != 1 );
00013         int32 help = (int32)sizeof(size_t);
00014         lgErr = lgErr || ( fwrite( &help, sizeof(int32), 1, out ) != 1 );
00015         lgErr = lgErr || ( fwrite( &size, sizeof(size_t), 1, out ) != 1 );
00016         lgErr = lgErr || ( fwrite( buf, size, nelem, out ) != nelem );
00017         if( lgErr )
00018         {
00019                 fprintf( ioQQQ, " I/O error while dumping state!\n" );
00020                 cdEXIT(EXIT_FAILURE);
00021         }
00022 }
00023 
00028 void do_restore_state(void* buf, size_t nelem, size_t size, FILE *in, int32 magic)
00029 {
00030         DEBUG_ENTRY( "do_restore_state()" );
00031 
00032         int32 help = 0;
00033         size_t help2 = 0;
00034         bool lgErr = ( fread( &help, sizeof(int32), 1, in ) != 1 );
00035         // this checks for correct version and prevents mixing up old style and new style data
00036         // it also prevents mixing up data from big-endian and little-endian machines.
00037         lgErr = lgErr || ( help != magic );
00038         lgErr = lgErr || ( fread( &help, sizeof(int32), 1, in ) != 1 );
00039         // this prevents mixing up data from 32-bit and 64-bit systems
00040         lgErr = lgErr || ( help != (int32)sizeof(size_t) );
00041         lgErr = lgErr || ( fread( &help2, sizeof(size_t), 1, in ) != 1 );
00042         // this may guard against reading an older, incompatible version of the array
00043         lgErr = lgErr || ( help2 != size );
00044         lgErr = lgErr || ( fread( buf, size, nelem, in ) != nelem );
00045         if( lgErr )
00046         {
00047                 fprintf( ioQQQ, " Error while restoring state!\n" );
00048                 cdEXIT(EXIT_FAILURE);
00049         }
00050 }

Generated on Mon Feb 16 12:01:13 2009 for cloudy by  doxygen 1.4.7