00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OASYS_DEBUG_UTILS_H_
00019 #define _OASYS_DEBUG_UTILS_H_
00020
00021 #include <cstdio>
00022 #include <cstdlib>
00023
00024 #include "FatalSignals.h"
00025
00026 #define ASSERT(x) \
00027 do { if (! (x)) { \
00028 fprintf(stderr, "ASSERTION FAILED (%s) at %s:%d\n", \
00029 (#x), __FILE__, __LINE__); \
00030 ::oasys::Breaker::break_here(); \
00031 ::oasys::FatalSignals::die(); \
00032 } } while(0);
00033
00034 #ifdef __GNUC__
00035
00036 #define ASSERTF(x, fmt, args...) \
00037 do { if (! (x)) { \
00038 fprintf(stderr, \
00039 "ASSERTION FAILED (%s) at %s:%d: " fmt "\n", \
00040 (#x), __FILE__, __LINE__, ## args); \
00041 ::oasys::Breaker::break_here(); \
00042 ::oasys::FatalSignals::die(); \
00043 } } while(0);
00044
00045 #define PANIC(fmt, args...) \
00046 do { \
00047 fprintf(stderr, "PANIC at %s:%d: " fmt "\n", \
00048 __FILE__, __LINE__ , ## args); \
00049 ::oasys::Breaker::break_here(); \
00050 ::oasys::FatalSignals::die(); \
00051 } while(0);
00052
00053 #endif // __GNUC__
00054
00055 #ifdef __win32__
00056
00057 #define ASSERTF(x, fmt, ...) \
00058 do { if (! (x)) { \
00059 fprintf(stderr, \
00060 "ASSERTION FAILED (" #x ") at %s:%d: " fmt "\n", \
00061 __FILE__, __LINE__, __VA_ARGS__ ); \
00062 ::oasys::Breaker::break_here(); \
00063 ::oasys::FatalSignals::die(); \
00064 } } while(0);
00065
00066 #define PANIC(fmt, ...) \
00067 do { \
00068 fprintf(stderr, "PANIC at %s:%d: " fmt "\n", \
00069 __FILE__, __LINE__ , __VA_ARGS__); \
00070 ::oasys::Breaker::break_here(); \
00071 ::oasys::FatalSignals::die(); \
00072 } while(0);
00073
00074 #endif
00075
00076 #define NOTREACHED \
00077 do { \
00078 fprintf(stderr, "NOTREACHED REACHED at %s:%d\n", \
00079 __FILE__, __LINE__); \
00080 ::oasys::Breaker::break_here(); \
00081 ::oasys::FatalSignals::die(); \
00082 } while(0);
00083
00084 #define NOTIMPLEMENTED \
00085 do { \
00086 fprintf(stderr, "%s NOT IMPLEMENTED at %s:%d\n", \
00087 __FUNCTION__, __FILE__, __LINE__); \
00088 ::oasys::Breaker::break_here(); \
00089 ::oasys::FatalSignals::die(); \
00090 } while(0);
00091
00096 template <int x> struct static_assert_test{};
00097 template <bool> struct STATIC_ASSERTION_FAILURE;
00098 template <> struct STATIC_ASSERTION_FAILURE<true>{};
00099
00100 #ifdef STATIC_ASSERT
00101 #undef STATIC_ASSERT
00102 #endif
00103
00104 #define STATIC_ASSERT(_x, _what) \
00105 typedef static_assert_test \
00106 < \
00107 sizeof(STATIC_ASSERTION_FAILURE<(bool)(_x)>) \
00108 > static_assert_typedef_ ## _what;
00109
00111 namespace oasys {
00112 class Breaker {
00113 public:
00119 static void break_here();
00120 };
00121
00125 #define delete_z(_obj) \
00126 do { delete _obj; _obj = 0; } while (0)
00127
00133 #define NO_COPY(_Classname) \
00134 private: _Classname(const _Classname& other)
00135
00136 #define NO_ASSIGN(_Classname) \
00137 private: _Classname& operator=(const _Classname& other)
00138
00139 #define NO_ASSIGN_COPY(_Classname) \
00140 NO_COPY(_Classname); \
00141 NO_ASSIGN(_Classname)
00143
00144 }
00145
00148 void oasys_break();
00149
00150 #include "../memory/Memory.h"
00151
00152 #endif