00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00059 #include <stdarg.h>
00060
00061 #if !defined(INCLUDED_DEBUG_H)
00062 #define INCLUDED_DEBUG_H
00063
00064 #define DEBUG_BUFSIZE 1024
00065 #define DEBUG_INDENTATION 4
00066
00067 #ifdef HAVE___FUNCTION__
00068 #define FAILURE(cls, error_msg) \
00069 { \
00070 char where_msg[800]; \
00071 sprintf(where_msg, "%s, line %i, function '%s'", __FILE__, __LINE__, \
00072 __FUNCTION__); \
00073 throw C##cls##Exception(error_msg, where_msg); \
00074 }
00075
00076 #else
00077 #define FAILURE(cls, error_msg) \
00078 { \
00079 char where_msg[800]; \
00080 sprintf(where_msg, "%s, line %i", __FILE__, __LINE__); \
00081 throw C##cls##Exception(error_msg, where_msg); \
00082 }
00083 #endif
00084
00085 #define FAILURE_1(cls, error_msg, a) \
00086 { \
00087 char what_msg[800]; \
00088 sprintf(what_msg, error_msg, a); \
00089 FAILURE(cls, what_msg); \
00090 }
00091
00092 #define FAILURE_2(cls, error_msg, a, b) \
00093 { \
00094 char what_msg[800]; \
00095 sprintf(what_msg, error_msg, a, b); \
00096 FAILURE(cls, what_msg); \
00097 }
00098
00099 #define FAILURE_3(cls, error_msg, a, b, c) \
00100 { \
00101 char what_msg[800]; \
00102 sprintf(what_msg, error_msg, a, b, c); \
00103 FAILURE(cls, what_msg); \
00104 }
00105
00106 #define FAILURE_4(cls, error_msg, a, b, c, d) \
00107 { \
00108 char what_msg[800]; \
00109 sprintf(what_msg, error_msg, a, b, c, d); \
00110 FAILURE(cls, what_msg); \
00111 }
00112
00113 #define FAILURE_5(cls, error_msg, a, b, c, d, e) \
00114 { \
00115 char what_msg[800]; \
00116 sprintf(what_msg, error_msg, a, b, c, d, e); \
00117 FAILURE(cls, what_msg); \
00118 }
00119
00120 #define FAILURE_6(cls, error_msg, a, b, c, d, e, f) \
00121 { \
00122 char what_msg[800]; \
00123 sprintf(what_msg, error_msg, a, b, c, d, e, f); \
00124 FAILURE(cls, what_msg); \
00125 }
00126
00127 #define CHECK_ALLOCATION(ptr) \
00128 { \
00129 if((ptr) == NULL) \
00130 FAILURE(OutOfMemory, "Out of memory"); \
00131 }
00132
00133 #define CHECK_REALLOCATION(dst, src, type) \
00134 { \
00135 type* rea_x; \
00136 rea_x = (type*) src; \
00137 if((rea_x) == NULL) \
00138 { \
00139 FAILURE(OutOfMemory, "Out of memory"); \
00140 } \
00141 else \
00142 { \
00143 dst = rea_x; \
00144 } \
00145 }
00146
00147 void debug_indentation(int diff);
00148 void debug(char* fmt, ...);
00149 void fatal(char* fmt, ...);
00150 #endif