Assert.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef _ASSERT_
00023 #define _ASSERT_
00024 
00029 #include "Err.hxx"
00030 
00031 namespace CLAM
00032 {
00033 
00041 // Microsoft VisualC++ and ancestror MSC
00042 #ifdef _MSC_VER
00043 #define CLAM_BREAKPOINT {__asm {int 3}}
00044         
00045 // MetroWorks Code Warrior
00046 #elif defined (__MWERKS__)
00047 #define CLAM_BREAKPOINT {_asm {int 3}}
00048 
00049 // GNU GCC
00050 #elif defined (__GNUC__) && (defined  (__i386__) || defined(__x86_64__))
00051 #define CLAM_BREAKPOINT {__asm__ (" int $3 "); }
00052 
00053 /* g++ on powerpc linux */
00054 #elif defined (__GNUC__) && defined  (__powerpc__)
00055 #define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
00056 
00057 /* g++ on powerpc macosx */ 
00058 #elif defined (__GNUC__) && defined  (__POWERPC__)
00059 #define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
00060 
00061 // Insert your compiler here
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 
Generated by  doxygen 1.6.3