source: XMLIO_V2/external/include/Poco/Bugcheck.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1//
2// Bugcheck.h
3//
4// $Id: //poco/1.3/Foundation/include/Poco/Bugcheck.h#3 $
5//
6// Library: Foundation
7// Package: Core
8// Module:  Bugcheck
9//
10// Definition of the Bugcheck class and the self-testing macros.
11//
12// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Foundation_Bugcheck_INCLUDED
40#define Foundation_Bugcheck_INCLUDED
41
42
43#include "Poco/Foundation.h"
44#include <string>
45#if defined(_DEBUG)
46#       include <iostream>
47#endif
48
49
50namespace Poco {
51
52
53class Foundation_API Bugcheck
54        /// This class provides some static methods that are
55        /// used by the
56        /// poco_assert_dbg(), poco_assert(), poco_check_ptr()
57        /// and poco_bugcheck() macros.
58        /// You should not invoke these methods
59        /// directly. Use the macros instead, as they
60        /// automatically provide useful context information.
61{
62public:
63        static void assertion(const char* cond, const char* file, int line);
64                /// An assertion failed. Break into the debugger, if
65                /// possible, then throw an AssertionViolationException.
66               
67        static void nullPointer(const char* ptr, const char* file, int line);
68                /// An null pointer was encountered. Break into the debugger, if
69                /// possible, then throw an NullPointerException.
70
71        static void bugcheck(const char* file, int line);
72                /// An internal error was encountered. Break into the debugger, if
73                /// possible, then throw an BugcheckException.
74
75        static void bugcheck(const char* msg, const char* file, int line);
76                /// An internal error was encountered. Break into the debugger, if
77                /// possible, then throw an BugcheckException.
78
79        static void debugger(const char* file, int line);
80                /// An internal error was encountered. Break into the debugger, if
81                /// possible.
82
83        static void debugger(const char* msg, const char* file, int line);
84                /// An internal error was encountered. Break into the debugger, if
85                /// possible.
86
87protected:
88        static std::string what(const char* msg, const char* file, int line);
89};
90
91
92} // namespace Poco
93
94
95//
96// useful macros (these automatically supply line number and file name)
97//
98#if defined(_DEBUG)
99        #define poco_assert_dbg(cond) \
100                if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
101#else
102        #define poco_assert_dbg(cond)
103#endif
104
105
106#define poco_assert(cond) \
107        if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
108
109
110#define poco_check_ptr(ptr) \
111        if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
112
113
114#define poco_bugcheck() \
115        Poco::Bugcheck::bugcheck(__FILE__, __LINE__)
116
117
118#define poco_bugcheck_msg(msg) \
119        Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
120
121
122#define poco_debugger() \
123        Poco::Bugcheck::debugger(__FILE__, __LINE__)
124
125
126#define poco_debugger_msg(msg) \
127        Poco::Bugcheck::debugger(msg, __FILE__, __LINE__)
128
129
130#if defined(_DEBUG)
131#       define poco_stdout_dbg(outstr) \
132        std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
133#else
134#       define poco_stdout_dbg(outstr)
135#endif
136
137
138#if defined(_DEBUG)
139#       define poco_stderr_dbg(outstr) \
140                std::cerr << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
141#else
142#       define poco_stderr_dbg(outstr)
143#endif
144
145
146//
147// poco_static_assert
148//
149// The following was ported from <boost/static_assert.hpp>
150//
151
152
153template <bool x>
154struct POCO_STATIC_ASSERTION_FAILURE;
155
156
157template <> 
158struct POCO_STATIC_ASSERTION_FAILURE<true> 
159{
160        enum 
161        { 
162                value = 1 
163        }; 
164};
165
166
167template <int x> 
168struct poco_static_assert_test
169{
170};
171
172
173#if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
174#define poco_static_assert(B) \
175        typedef char POCO_JOIN(poco_static_assert_typedef_, __LINE__) \
176        [POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>::value]
177#else
178#define poco_static_assert(B) \
179        typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>)> \
180                POCO_JOIN(poco_static_assert_typedef_, __LINE__)
181#endif
182
183
184#endif // Foundation_Bugcheck_INCLUDED
Note: See TracBrowser for help on using the repository browser.