Changeset 209:765619b7cbb2 in lemon for lemon/assert.h
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/assert.h
r142 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 29 29 30 30 inline void assert_fail_log(const char *file, int line, const char *function, 31 31 const char *message, const char *assertion) 32 32 { 33 33 std::cerr << file << ":" << line << ": "; … … 41 41 42 42 inline void assert_fail_abort(const char *file, int line, 43 44 43 const char *function, const char* message, 44 const char *assertion) 45 45 { 46 46 assert_fail_log(file, line, function, message, assertion); … … 49 49 50 50 namespace _assert_bits { 51 52 51 52 53 53 inline const char* cstringify(const std::string& str) { 54 54 return str.c_str(); … … 57 57 inline const char* cstringify(const char* str) { 58 58 return str; 59 } 59 } 60 60 } 61 61 } … … 67 67 #undef LEMON_DEBUG 68 68 69 #if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + 70 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + 69 #if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ 70 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 71 71 (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1 72 72 #error "LEMON assertion system is not set properly" 73 73 #endif 74 74 75 #if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + 76 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + 77 (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || 78 defined(LEMON_ENABLE_ASSERTS)) && 79 (defined(LEMON_DISABLE_ASSERTS) || 75 #if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ 76 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 77 (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ 78 defined(LEMON_ENABLE_ASSERTS)) && \ 79 (defined(LEMON_DISABLE_ASSERTS) || \ 80 80 defined(NDEBUG)) 81 81 #error "LEMON assertion system is not set properly" … … 137 137 /// \endcode 138 138 /// The checking is also disabled when the standard macro \c NDEBUG is defined. 139 /// 139 /// 140 140 /// The LEMON assertion system has a wide range of customization 141 141 /// properties. As a default behaviour the failed assertion prints a 142 142 /// short log message to the standard error and aborts the execution. 143 143 /// 144 /// The following modes can be used in the assertion system: 144 /// The following modes can be used in the assertion system: 145 145 /// 146 146 /// - \c LEMON_ASSERT_LOG The failed assertion prints a short log … … 156 156 /// \endcode 157 157 /// The name of the function should be defined as the \c 158 /// LEMON_CUSTOM_ASSERT_HANDLER macro name. 158 /// LEMON_CUSTOM_ASSERT_HANDLER macro name. 159 159 /// \code 160 160 /// #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler … … 167 167 /// \ref lemon/assert.h "assert.h" file is reincluded, then the 168 168 /// behaviour is changed appropiately to the new settings. 169 # define LEMON_ASSERT(exp, msg) 170 (static_cast<void> (!!(exp) ? 0 : ( 171 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, 172 LEMON_FUNCTION_NAME,\173 169 # define LEMON_ASSERT(exp, msg) \ 170 (static_cast<void> (!!(exp) ? 0 : ( \ 171 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ 172 LEMON_FUNCTION_NAME, \ 173 ::lemon::_assert_bits::cstringify(msg), #exp), 0))) 174 174 175 175 /// \ingroup exceptions … … 183 183 /// \endcode 184 184 /// 185 /// \see LEMON_ASSERT 186 # define LEMON_FIXME(msg) 187 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, 188 ::lemon::_assert_bits::cstringify(msg),\189 185 /// \see LEMON_ASSERT 186 # define LEMON_FIXME(msg) \ 187 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ 188 ::lemon::_assert_bits::cstringify(msg), \ 189 static_cast<const char*>(0))) 190 190 191 191 /// \ingroup exceptions … … 211 211 /// macro. 212 212 /// 213 /// \see LEMON_ASSERT 214 # define LEMON_DEBUG(exp, msg) 215 (static_cast<void> (!!(exp) ? 0 : ( 213 /// \see LEMON_ASSERT 214 # define LEMON_DEBUG(exp, msg) \ 215 (static_cast<void> (!!(exp) ? 0 : ( \ 216 216 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ 217 LEMON_FUNCTION_NAME,\218 217 LEMON_FUNCTION_NAME, \ 218 ::lemon::_assert_bits::cstringify(msg), #exp), 0))) 219 219 220 220 #else … … 225 225 # define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) 226 226 # else 227 # define LEMON_ASSERT(exp, msg) 228 (static_cast<void> (!!(exp) ? 0 : ( 227 # define LEMON_ASSERT(exp, msg) \ 228 (static_cast<void> (!!(exp) ? 0 : ( \ 229 229 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ 230 LEMON_FUNCTION_NAME,\231 ::lemon::_assert_bits::cstringify(msg),\232 233 # define LEMON_FIXME(msg) 234 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, 235 ::lemon::_assert_bits::cstringify(msg),\236 230 LEMON_FUNCTION_NAME, \ 231 ::lemon::_assert_bits::cstringify(msg), \ 232 #exp), 0))) 233 # define LEMON_FIXME(msg) \ 234 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ 235 ::lemon::_assert_bits::cstringify(msg), \ 236 static_cast<const char*>(0))) 237 237 238 238 # if LEMON_ENABLE_DEBUG … … 241 241 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ 242 242 LEMON_FUNCTION_NAME, \ 243 ::lemon::_assert_bits::cstringify(msg),\244 243 ::lemon::_assert_bits::cstringify(msg), \ 244 #exp), 0))) 245 245 # else 246 246 # define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
Note: See TracChangeset
for help on using the changeset viewer.