MNValid.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MN_VALID_H
00025 #define MN_VALID_H
00026
00027 #ifndef NDEBUG
00028
00029 #include <assert.h>
00030 #include <stdio.h>
00031
00037 #define DECLARE_VALID \
00038 private: \
00039 bool _valid; \
00040 bool _invalid; \
00041 public: \
00042 void validate( const char* file, int line ) const { \
00043 if( !_valid || _invalid ) { \
00044 fprintf( stderr, "object invalid in %s:%d\n", file, line ); \
00045 } \
00046 assert( _valid ); \
00047 assert( !_invalid ); \
00048 }
00049
00050 #define MAKE_VALID \
00051 _valid = true; \
00052 _invalid = false;
00053
00054 #define MAKE_INVALID \
00055 _valid = false; \
00056 _invalid = true;
00057
00058 #define CHECK_VALID \
00059 validate( __FILE__, __LINE__ );
00060
00061 #define CHECK_VALID_OBJ(a) \
00062 (a).validate( __FILE__, __LINE__ );
00063
00064 #define TESTDUMP 1
00065
00066 #ifdef TESTDUMP
00067 #include <stdio.h>
00068 #include <stdlib.h>
00069 #include <unistd.h>
00070 #include <fcntl.h>
00071
00072 static inline void testdumpTrunc( const char* filename )
00073 {
00074 int fd = ::open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0666 );
00075 ::close( fd );
00076 }
00077
00078 static inline void testdumpWrite( const char* filename, const char* buf, size_t len )
00079 {
00080 size_t sz;
00081 int fd = ::open( filename, O_APPEND | O_WRONLY );
00082 sz = ::write( fd, buf, len );
00083 if( sz != len )
00084 {
00085 fprintf( stderr, "tried to %d bytes to testdump, but wrote only %d\n", (int)len, (int)sz );
00086 }
00087 ::close( fd );
00088 }
00089 #else
00090 static inline void testdumpTrunc( const char* ) { }
00091 static inline void testdumpWrite( const char*, const char*, size_t ) { }
00092 #endif
00093
00094 #else
00095 # define DECLARE_VALID
00096 # define MAKE_VALID
00097 # define MAKE_INVALID
00098 # define CHECK_VALID
00099 # define CHECK_VALID_OBJ(a)
00100 #endif
00101
00102 #endif
00103
Generated on Sun Mar 6 13:35:49 2005 for Komssys by
1.3.8