Bugcheck.h
Go to the documentation of this file.
00001 //
00002 // Bugcheck.h
00003 //
00004 // $Id: //poco/1.3/Foundation/include/Poco/Bugcheck.h#3 $
00005 //
00006 // Library: Foundation
00007 // Package: Core
00008 // Module:  Bugcheck
00009 //
00010 // Definition of the Bugcheck class and the self-testing macros.
00011 //
00012 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00013 // and Contributors.
00014 //
00015 // Permission is hereby granted, free of charge, to any person or organization
00016 // obtaining a copy of the software and accompanying documentation covered by
00017 // this license (the "Software") to use, reproduce, display, distribute,
00018 // execute, and transmit the Software, and to prepare derivative works of the
00019 // Software, and to permit third-parties to whom the Software is furnished to
00020 // do so, all subject to the following:
00021 // 
00022 // The copyright notices in the Software and this entire statement, including
00023 // the above license grant, this restriction and the following disclaimer,
00024 // must be included in all copies of the Software, in whole or in part, and
00025 // all derivative works of the Software, unless such copies or derivative
00026 // works are solely in the form of machine-executable object code generated by
00027 // a source language processor.
00028 // 
00029 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00030 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00031 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00032 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00033 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00034 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00035 // DEALINGS IN THE SOFTWARE.
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 } // namespace Poco
00093 
00094 
00095 //
00096 // useful macros (these automatically supply line number and file name)
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 // poco_static_assert
00148 // 
00149 // The following was ported from <boost/static_assert.hpp>
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


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19