cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
container_classes.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #include "cddefines.h"
5 #include "container_classes.h"
6 
7 #ifdef _MSC_VER
8 /* disable "'extern' before template explicit instantiation" */
9 # pragma warning( disable : 4231 )
10 #endif
11 
12 /* Explicit instantiations for debugging purposes */
17 #ifndef FLT_IS_DBL
19 #endif
21 
22 
24 void do_dump_state(const void* buf, size_t nelem, size_t size, FILE* out, int32 magic)
25 {
26  DEBUG_ENTRY( "do_dump_state()" );
27 
28  bool lgErr = ( fwrite( &magic, sizeof(int32), 1, out ) != 1 );
29  int32 help = (int32)sizeof(size_t);
30  lgErr = lgErr || ( fwrite( &help, sizeof(int32), 1, out ) != 1 );
31  lgErr = lgErr || ( fwrite( &size, sizeof(size_t), 1, out ) != 1 );
32  lgErr = lgErr || ( fwrite( buf, size, nelem, out ) != nelem );
33  if( lgErr )
34  {
35  fprintf( ioQQQ, " I/O error while dumping state!\n" );
37  }
38 }
39 
44 void do_restore_state(void* buf, size_t nelem, size_t size, FILE *in, int32 magic)
45 {
46  DEBUG_ENTRY( "do_restore_state()" );
47 
48  int32 help = 0;
49  size_t help2 = 0;
50  bool lgErr = ( fread( &help, sizeof(int32), 1, in ) != 1 );
51  // this checks for correct version and prevents mixing up old style and new style data
52  // it also prevents mixing up data from big-endian and little-endian machines.
53  lgErr = lgErr || ( help != magic );
54  lgErr = lgErr || ( fread( &help, sizeof(int32), 1, in ) != 1 );
55  // this prevents mixing up data from 32-bit and 64-bit systems
56  lgErr = lgErr || ( help != (int32)sizeof(size_t) );
57  lgErr = lgErr || ( fread( &help2, sizeof(size_t), 1, in ) != 1 );
58  // this may guard against reading an older, incompatible version of the array
59  lgErr = lgErr || ( help2 != size );
60  lgErr = lgErr || ( fread( buf, size, nelem, in ) != nelem );
61  if( lgErr )
62  {
63  fprintf( ioQQQ, " Error while restoring state!\n" );
65  }
66 }
void do_dump_state(const void *buf, size_t nelem, size_t size, FILE *out, int32 magic)
FILE * ioQQQ
Definition: cddefines.cpp:7
void do_restore_state(void *buf, size_t nelem, size_t size, FILE *in, int32 magic)
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:482
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
#define lgBOUNDSCHECKVAL
Definition: cddefines.h:173
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
#define INSTANTIATE_MULTI_ARR(TYPE, BC)