Bugcheck.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00037 //
00038 // Bugcheck.h
00039 //
00040 // $Id: Bugcheck.h,v 1.1 2008/03/31 19:13:28 iamcamiel Exp $
00041 //
00042 // Library: Foundation
00043 // Package: Core
00044 // Module:  Bugcheck
00045 //
00046 // Definition of the Bugcheck class and the self-testing macros.
00047 //
00048 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00049 // and Contributors.
00050 //
00051 // Permission is hereby granted, free of charge, to any person or organization
00052 // obtaining a copy of the software and accompanying documentation covered by
00053 // this license (the "Software") to use, reproduce, display, distribute,
00054 // execute, and transmit the Software, and to prepare derivative works of the
00055 // Software, and to permit third-parties to whom the Software is furnished to
00056 // do so, all subject to the following:
00057 // 
00058 // The copyright notices in the Software and this entire statement, including
00059 // the above license grant, this restriction and the following disclaimer,
00060 // must be included in all copies of the Software, in whole or in part, and
00061 // all derivative works of the Software, unless such copies or derivative
00062 // works are solely in the form of machine-executable object code generated by
00063 // a source language processor.
00064 // 
00065 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00066 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00067 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00068 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00069 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00070 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00071 // DEALINGS IN THE SOFTWARE.
00072 //
00073 
00074 
00075 #ifndef Foundation_Bugcheck_INCLUDED
00076 #define Foundation_Bugcheck_INCLUDED
00077 
00078 
00079 #include "VMS/Foundation.h"
00080 #include <string>
00081 
00082 
00083 namespace Poco {
00084 
00085 
00086 class Foundation_API Bugcheck
00094 {
00095 public:
00096         static void assertion(const char* cond, const char* file, int line);
00099                 
00100         static void nullPointer(const char* ptr, const char* file, int line);
00103 
00104         static void bugcheck(const char* file, int line);
00107 
00108         static void bugcheck(const char* msg, const char* file, int line);
00111 
00112         static void debugger(const char* file, int line);
00115 
00116         static void debugger(const char* msg, const char* file, int line);
00119 
00120 protected:
00121         static std::string what(const char* msg, const char* file, int line);
00122 };
00123 
00124 
00125 } // namespace Poco
00126 
00127 
00128 //
00129 // useful macros (these automatically supply line number and file name)
00130 //
00131 #if defined(_DEBUG)
00132         #define poco_assert_dbg(cond) \
00133                 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
00134 #else
00135         #define poco_assert_dbg(cond)
00136 #endif
00137 
00138 
00139 #define poco_assert(cond) \
00140         if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
00141 
00142 
00143 #define poco_check_ptr(ptr) \
00144         if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
00145 
00146 
00147 #define poco_bugcheck() \
00148         Poco::Bugcheck::bugcheck(__FILE__, __LINE__)
00149 
00150 
00151 #define poco_bugcheck_msg(msg) \
00152         Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
00153 
00154 
00155 #define poco_debugger() \
00156         Poco::Bugcheck::debugger(__FILE__, __LINE__)
00157 
00158 
00159 #define poco_debugger_msg(msg) \
00160         Poco::Bugcheck::debugger(msg, __FILE__, __LINE__)
00161 
00162 
00163 //
00164 // poco_static_assert
00165 // 
00166 // The following was ported from <boost/static_assert.hpp>
00167 //
00168 
00169 
00170 template <bool x>
00171 struct POCO_STATIC_ASSERTION_FAILURE;
00172 
00173 
00174 template <> 
00175 struct POCO_STATIC_ASSERTION_FAILURE<true> 
00176 {
00177         enum 
00178         { 
00179                 value = 1 
00180         }; 
00181 };
00182 
00183 
00184 template <int x> 
00185 struct poco_static_assert_test
00186 {
00187 };
00188 
00189 
00190 #if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
00191 #define poco_static_assert(B) \
00192         typedef char POCO_JOIN(poco_static_assert_typedef_, __LINE__) \
00193         [POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>::value]
00194 #else
00195 #define poco_static_assert(B) \
00196         typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>)> \
00197                 POCO_JOIN(poco_static_assert_typedef_, __LINE__)
00198 #endif
00199 
00200 
00201 #endif // Foundation_Bugcheck_INCLUDED

SourceForge.net Logo
Project space on SourceForge.net