MOOS 0.2375
|
00001 #ifndef __MOOSAssert_h 00002 #define __MOOSAssert_h 00003 // MOOS_ASSERT_LEVEL = {0, 1, 2} 00004 // Level 0: No asserts 00005 // Level 1: Soft assert - outputs error message and tries to carry on. 00006 // Level 2: Hard assert - outputs error message and quits. 00007 00008 // ALLOW_RELEASE_ASSERTS 00009 // If not defined then assert statements are tested ONLY in debug builds. 00010 00011 #include "MOOSGenLibGlobalHelper.h" 00012 00013 #ifndef MOOS_ASSERT_LEVEL 00014 #define MOOS_ASSERT_LEVEL 1 00015 #endif 00016 00017 // This is a helper macro, to automatically provide filename and 00018 // line number details to the MOOSAssert function. 00019 // It also ensures that asserts are only compiled in when required. 00020 #if ((defined(_DEBUG) || defined(ALLOW_RELEASE_ASSERTS)) && (MOOS_ASSERT_LEVEL > 0)) 00021 #define _MOOSASSERT(bCond, msg) MOOSAssert(bCond, msg, __FILE__, __LINE__) 00022 #else 00023 #define _MOOSASSERT(bCond, msg) 00024 #endif 00025 00026 00027 00028 inline void MOOSAssert(bool cond, const char *msg=NULL, const char *filename=NULL, int line=0) 00029 { 00030 #if (defined(_DEBUG) || defined(ALLOW_RELEASE_ASSERTS)) 00031 #if (MOOS_ASSERT_LEVEL > 0) 00032 00033 if (!cond) 00034 { 00035 if (filename && line>0) 00036 { 00037 if (msg) 00038 { 00039 MOOSTrace("Assert failed at %s:%d. %s\n", filename, line, msg); 00040 } 00041 else 00042 { 00043 MOOSTrace("Assert failed at %s:%d.\n", filename, line); 00044 } 00045 } 00046 else 00047 { 00048 if (msg) 00049 { 00050 MOOSTrace("Assert failed. %s\n", msg); 00051 } 00052 else 00053 { 00054 MOOSTrace("Assert failed.\n"); 00055 } 00056 } 00057 00058 00059 #if (MOOS_ASSERT_LEVEL == 2) 00060 exit(); 00061 #endif 00062 } 00063 #endif 00064 #endif 00065 } 00066 00067 #endif // __MOOSAssert_h 00068