TraceFct.h
Go to the documentation of this file.00001 #ifndef TraceFct_h_INCLUDED
00002 #define TraceFct_h_INCLUDED
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 #include <iosfwd>
00029 #include <list>
00030 #include <cstdlib>
00031
00032 #include <Exception/Exception.h>
00033
00045 # define _tf_assert(level,ex) \
00046 do \
00047 { \
00048 if (!(ex)) \
00049 TraceFct::exit( level, "Assertion failed: file\"%s\", line %d\n%s\n", \
00050 __FILE__, __LINE__, #ex); \
00051 } while(0)
00052
00063 #ifdef DOXYGEN
00064 # define TF_ASSERT_LEVEL
00065 #endif
00066
00067
00074 # define tf_assert(ex) _tf_assert(990,ex)
00075
00076 #ifdef TF_ASSERT_LEVEL
00077 # if TF_ASSERT_LEVEL > 0
00078
00085 # define tf_assert1(ex) _tf_assert(991,ex)
00086 # if TF_ASSERT_LEVEL > 1
00087
00094 # define tf_assert2(ex) _tf_assert(992,ex)
00095 # if TF_ASSERT_LEVEL > 2
00096
00103 # define tf_assert3(ex) _tf_assert(993,ex)
00104 # if TF_ASSERT_LEVEL > 3
00105
00112 # define tf_assert4(ex) _tf_assert(994,ex)
00113 # if TF_ASSERT_LEVEL > 4
00114
00122 # define tf_assert5(ex) _tf_assert(995,ex)
00123 # endif
00124 # endif
00125 # endif
00126 # endif
00127 # endif
00128 #endif
00129
00130 #ifndef tf_assert1
00131 # define tf_assert1(ex)
00132 #endif
00133
00134 #ifndef tf_assert2
00135 # define tf_assert2(ex)
00136 #endif
00137
00138 #ifndef tf_assert3
00139 # define tf_assert3(ex)
00140 #endif
00141
00142 #ifndef tf_assert4
00143 # define tf_assert4(ex)
00144 #endif
00145
00146 #ifndef tf_assert5
00147 # define tf_assert5(ex)
00148 #endif
00149
00150
00155 class TraceFct {
00156
00157 public:
00158 TraceFct( const char* name );
00159 TraceFct( string& name );
00160 TraceFct( string name, bool print_it, int num_fct_to_print );
00161 ~TraceFct( );
00162
00163 static void exit (int exit_code, const char *format, ...);
00164 static void exit (int exit_code, Exception& ex );
00165
00166 static void exit (int exit_code, const string& msg)
00167 { exit( exit_code, msg.c_str() ); };
00168
00169
00170 static void die (const char *format, ...);
00171
00172 static void die ( Exception& ex )
00173 { exit( EXIT_FAILURE, ex ); }
00174
00175 static void die ( const string& msg)
00176 { exit( EXIT_FAILURE, msg ); };
00177
00178 static void message (const char *format, ...);
00179 static void message ( Exception& ex )
00180 { print( false, ex ); }
00181 static void message (const string& msg)
00182 { message( msg.c_str() ); }
00183
00184 static void vmessage (const char *format, va_list args);
00185
00186 static void println ( Exception& ex )
00187 { print( true, ex ); }
00188 static void println (const string& msg)
00189 { print( true, msg.c_str() ); }
00190 static void println (const char* msg)
00191 { print( true, msg ); }
00192
00193 static void dump_stack (void);
00194 static void open( const string& filename );
00195 static void close(void);
00196
00197 private:
00198 static bool print_upon_enter_and_exit;
00199 static int stack_level_to_print;
00200 static string prefix;
00201
00202
00203
00204 static char outbuf[8192];
00205 static string progname;
00206 static ostream* ostr;
00207 static list<string> function_stack;
00208
00209 static char* init_prefix( void );
00210
00211 static void vexit_print(const char* format, va_list args );
00212 static void vprint(bool print_nl, const char *format, va_list args);
00213 static void print(bool print_nl, const char *format, ... );
00214 static void print(bool print_nl, Exception& ex );
00215
00216 };
00217
00218
00219
00220
00221 #endif