Assert.hxx
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 #ifndef _ASSERT_
00023 #define _ASSERT_
00024
00029 #include "Err.hxx"
00030
00031 namespace CLAM
00032 {
00033
00041
00042 #ifdef _MSC_VER
00043 #define CLAM_BREAKPOINT {__asm {int 3}}
00044
00045
00046 #elif defined (__MWERKS__)
00047 #define CLAM_BREAKPOINT {_asm {int 3}}
00048
00049
00050 #elif defined (__GNUC__) && (defined (__i386__) || defined(__x86_64__))
00051 #define CLAM_BREAKPOINT {__asm__ (" int $3 "); }
00052
00053
00054 #elif defined (__GNUC__) && defined (__powerpc__)
00055 #define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
00056
00057
00058 #elif defined (__GNUC__) && defined (__POWERPC__)
00059 #define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
00060
00061
00062 #else
00063 #warning Breakpoint code unknown for the platform. You can add it defining the CLAM_BREAKPOINT macro at file Assert.hxx.
00064 #define CLAM_BREAKPOINT {}
00065 #endif
00066
00067
00068 #if ! defined(_DEBUG)
00069 #define CLAM_USE_RELEASE_ASSERTS
00070 #endif
00071
00072
00074 #if defined(CLAM_USE_RELEASE_ASSERTS)
00075 #define CLAM_ABORT(message) \
00076 do { \
00077 throw CLAM::ErrAssertionFailed( message, __FILE__, __LINE__); \
00078 } while(0)
00079 #else
00080 #define CLAM_ABORT(message) \
00081 do { \
00082 if ( !CLAM::ErrAssertionFailed::breakpointInCLAMAssertEnabled ) { \
00083 throw CLAM::ErrAssertionFailed( message, __FILE__, __LINE__); \
00084 } else { \
00085 CLAM::ExecuteAssertFailedHandler ( message, __FILE__, __LINE__); \
00086 CLAM_BREAKPOINT; \
00087 } \
00088 } while(0)
00089 #endif
00090
00093
00145 #if defined(CLAM_DISABLE_CHECKS)
00146 #define CLAM_BEGIN_CHECK if (0) {
00147 #define CLAM_END_CHECK }
00148 #define CLAM_ASSERT( expression, message )
00149 #define CLAM_WARNING( expression, message )
00150 #else
00151 #define CLAM_BEGIN_CHECK {
00152 #define CLAM_END_CHECK }
00153 #define CLAM_ASSERT( expression, message ) \
00154 do { \
00155 if (!(expression)) { \
00156 CLAM_ABORT(message); \
00157 } } while (0)
00158 #define CLAM_WARNING( expression, message ) \
00159 do { \
00160 if (!(expression)) { \
00161 CLAM::ExecuteWarningHandler ( message, __FILE__, __LINE__); \
00162 } } while (0)
00163 #endif
00164
00165
00180 #if defined(CLAM_DISABLE_CHECKS) || defined(CLAM_USE_RELEASE_ASSERTS)
00181 # define CLAM_BEGIN_DEBUG_CHECK if (0) {
00182 # define CLAM_END_DEBUG_CHECK }
00183 # define CLAM_DEBUG_ASSERT( expression, message )
00184 # define CLAM_DEBUG_WARNING( expression, message )
00185 #else
00186 # define CLAM_BEGIN_DEBUG_CHECK {
00187 # define CLAM_END_DEBUG_CHECK }
00188 # define CLAM_DEBUG_ASSERT( expression, message ) \
00189 do { \
00190 if (!(expression)) { \
00191 CLAM_ABORT(message); \
00192 } } while (0)
00193 # define CLAM_DEBUG_WARNING( expression, message ) \
00194 do { \
00195 if (!(expression)) { \
00196 CLAM::ExecuteWarningHandler ( message, __FILE__, __LINE__); \
00197 } } while (0)
00198 #endif
00199
00200
00215 class ErrAssertionFailed : public Err {
00216 public:
00221 static bool breakpointInCLAMAssertEnabled;
00222
00223 ErrAssertionFailed(const char* message, const char* filename, int linenumber);
00224 virtual ~ErrAssertionFailed() throw () { }
00225 };
00226
00233 typedef void (*AssertFailedHandlerType) (const char* message, const char* filename, int lineNumber);
00243 AssertFailedHandlerType SetAssertFailedHandler(AssertFailedHandlerType handler);
00244
00248 void ExecuteAssertFailedHandler(const char* message, const char* filename, int linenumber);
00249
00256 typedef void (*WarningHandlerType) (const char* message, const char* filename, int lineNumber);
00266 WarningHandlerType SetWarningHandler(WarningHandlerType handler);
00267
00271 void ExecuteWarningHandler(const char* message, const char* filename, int linenumber);
00272
00273
00274 }
00275
00276 #endif //_ASSERT_
00277