00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _OmniBase_assertions_h_
00011 #define _OmniBase_assertions_h_
00012
00013 #import <OmniBase/FrameworkDefines.h>
00014 #import <objc/objc.h>
00015
00016 #if defined(DEBUG) || defined(OMNI_FORCE_ASSERTIONS)
00017 #define OMNI_ASSERTIONS_ON
00018 #endif
00019
00020
00021 #if defined(OMNI_FORCE_ASSERTIONS_OFF)
00022 #undef OMNI_ASSERTIONS_ON
00023 #warning Forcing assertions off!
00024 #endif
00025
00026
00027
00028 #ifdef ASSERT
00029 #undef ASSERT
00030 #endif
00031
00032 typedef void (*OBAssertionFailureHandler)(const char *type, const char *expression, const char *file, unsigned int lineNumber);
00033
00034 #if defined(OMNI_ASSERTIONS_ON)
00035
00036 OmniBase_EXTERN void OBSetAssertionFailureHandler(OBAssertionFailureHandler handler);
00037
00038 OmniBase_EXTERN void OBAssertFailed(const char *type, const char *expression, const char *file, unsigned int lineNumber);
00039
00040
00041 #define OBPRECONDITION(expression) \
00042 do { \
00043 if (!(expression)) \
00044 OBAssertFailed("PRECONDITION", #expression, __FILE__, __LINE__); \
00045 } while (NO)
00046
00047 #define OBPOSTCONDITION(expression) \
00048 do { \
00049 if (!(expression)) \
00050 OBAssertFailed("POSTCONDITION", #expression, __FILE__, __LINE__); \
00051 } while (NO)
00052
00053 #define OBINVARIANT(expression) \
00054 do { \
00055 if (!(expression)) \
00056 OBAssertFailed("INVARIANT", #expression, __FILE__, __LINE__); \
00057 } while (NO)
00058
00059 #define OBASSERT(expression) \
00060 do { \
00061 if (!(expression)) \
00062 OBAssertFailed("ASSERT", #expression, __FILE__, __LINE__); \
00063 } while (NO)
00064
00065 #define OBASSERT_NOT_REACHED(reason) \
00066 do { \
00067 OBAssertFailed("NOTREACHED", reason, __FILE__, __LINE__); \
00068 } while (NO)
00069
00070
00071 #else // else insert blank lines into the code
00072
00073 #define OBPRECONDITION(expression)
00074 #define OBPOSTCONDITION(expression)
00075 #define OBINVARIANT(expression)
00076 #define OBASSERT(expression)
00077 #define OBASSERT_NOT_REACHED(reason)
00078
00079 #endif
00080
00081
00082 #endif // _OmniBase_assertions_h_