Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNValid.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 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 /* NDEBUG */ 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 /* MN_VALID_H */ 00103

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8