Go to the documentation of this file.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 Foundation_Bugcheck_INCLUDED
00040 #define Foundation_Bugcheck_INCLUDED
00041
00042
00043 #include "Poco/Foundation.h"
00044 #include <string>
00045 #if defined(_DEBUG)
00046 # include <iostream>
00047 #endif
00048
00049
00050 namespace Poco {
00051
00052
00053 class Foundation_API Bugcheck
00061 {
00062 public:
00063 static void assertion(const char* cond, const char* file, int line);
00066
00067 static void nullPointer(const char* ptr, const char* file, int line);
00070
00071 static void bugcheck(const char* file, int line);
00074
00075 static void bugcheck(const char* msg, const char* file, int line);
00078
00079 static void debugger(const char* file, int line);
00082
00083 static void debugger(const char* msg, const char* file, int line);
00086
00087 protected:
00088 static std::string what(const char* msg, const char* file, int line);
00089 };
00090
00091
00092 }
00093
00094
00095
00096
00097
00098 #if defined(_DEBUG)
00099 #define poco_assert_dbg(cond) \
00100 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
00101 #else
00102 #define poco_assert_dbg(cond)
00103 #endif
00104
00105
00106 #define poco_assert(cond) \
00107 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
00108
00109
00110 #define poco_check_ptr(ptr) \
00111 if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
00112
00113
00114 #define poco_bugcheck() \
00115 Poco::Bugcheck::bugcheck(__FILE__, __LINE__)
00116
00117
00118 #define poco_bugcheck_msg(msg) \
00119 Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
00120
00121
00122 #define poco_debugger() \
00123 Poco::Bugcheck::debugger(__FILE__, __LINE__)
00124
00125
00126 #define poco_debugger_msg(msg) \
00127 Poco::Bugcheck::debugger(msg, __FILE__, __LINE__)
00128
00129
00130 #if defined(_DEBUG)
00131 # define poco_stdout_dbg(outstr) \
00132 std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00133 #else
00134 # define poco_stdout_dbg(outstr)
00135 #endif
00136
00137
00138 #if defined(_DEBUG)
00139 # define poco_stderr_dbg(outstr) \
00140 std::cerr << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00141 #else
00142 # define poco_stderr_dbg(outstr)
00143 #endif
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 template <bool x>
00154 struct POCO_STATIC_ASSERTION_FAILURE;
00155
00156
00157 template <>
00158 struct POCO_STATIC_ASSERTION_FAILURE<true>
00159 {
00160 enum
00161 {
00162 value = 1
00163 };
00164 };
00165
00166
00167 template <int x>
00168 struct poco_static_assert_test
00169 {
00170 };
00171
00172
00173 #if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
00174 #define poco_static_assert(B) \
00175 typedef char POCO_JOIN(poco_static_assert_typedef_, __LINE__) \
00176 [POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>::value]
00177 #else
00178 #define poco_static_assert(B) \
00179 typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>)> \
00180 POCO_JOIN(poco_static_assert_typedef_, __LINE__)
00181 #endif
00182
00183
00184 #endif // Foundation_Bugcheck_INCLUDED