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