|
||||
File indexing completed on 2025-01-18 09:30:25
0001 0002 #ifndef BOOST_CONTRACT_CHECK_MACRO_HPP_ 0003 #define BOOST_CONTRACT_CHECK_MACRO_HPP_ 0004 0005 // Copyright (C) 2008-2018 Lorenzo Caminiti 0006 // Distributed under the Boost Software License, Version 1.0 (see accompanying 0007 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). 0008 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html 0009 0010 /** @file 0011 Macros for implementation checks. 0012 */ 0013 0014 // IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. 0015 #include <boost/contract/core/config.hpp> 0016 #include <boost/contract/detail/noop.hpp> 0017 0018 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN 0019 /** 0020 Preferred way to assert implementation check conditions. 0021 0022 It is preferred to use this macro instead of programming implementation 0023 checks in a nullary functor passed to @RefClass{boost::contract::check} 0024 constructor because this macro will completely remove implementation checks 0025 from the code when @RefMacro{BOOST_CONTRACT_NO_CHECKS} is defined: 0026 0027 @code 0028 void f() { 0029 ... 0030 BOOST_CONTRACT_CHECK(cond); 0031 ... 0032 } 0033 @endcode 0034 0035 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and 0036 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels 0037 predefined by this library for implementation checks. 0038 0039 @see @RefSect{advanced.implementation_checks, Implementation Checks} 0040 0041 @param cond Boolean condition to check within implementation code (function 0042 body, etc.). 0043 (This is not a variadic macro parameter so any comma it might 0044 contain must be protected by round parenthesis and 0045 @c BOOST_CONTRACT_CHECK((cond)) will always work.) 0046 */ 0047 #define BOOST_CONTRACT_CHECK(cond) 0048 #elif !defined(BOOST_CONTRACT_NO_CHECKS) 0049 #include <boost/contract/detail/check.hpp> 0050 #include <boost/contract/detail/assert.hpp> 0051 0052 #define BOOST_CONTRACT_CHECK(cond) \ 0053 BOOST_CONTRACT_DETAIL_CHECK(BOOST_CONTRACT_DETAIL_ASSERT(cond)) 0054 #else 0055 #define BOOST_CONTRACT_CHECK(cond) /* nothing */ 0056 #endif 0057 0058 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN 0059 /** 0060 Preferred way to assert implementation check conditions that are 0061 computationally expensive, at least compared to the computational cost of 0062 executing the function body. 0063 0064 The specified condition will always be compiled and validated syntactically, 0065 but it will not be checked at run-time unless 0066 @RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default). 0067 This macro is defined by code equivalent to: 0068 0069 @code 0070 #ifdef BOOST_CONTRACT_AUDITS 0071 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ 0072 BOOST_CONTRACT_CHECK(cond) 0073 #else 0074 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ 0075 BOOST_CONTRACT_CHECK(true || cond) 0076 #endif 0077 @endcode 0078 0079 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and 0080 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels 0081 predefined by this library for implementation checks. 0082 If there is a need, programmers are free to implement their own assertion 0083 levels defining macros similar to the one above. 0084 0085 @see @RefSect{extras.assertion_levels, Assertion Levels} 0086 0087 @param cond Boolean condition to check within implementation code (function 0088 body, etc.). 0089 (This is not a variadic macro parameter so any comma it might 0090 contain must be protected by round parenthesis and 0091 @c BOOST_CONTRACT_CHECK_AUDIT((cond)) will always work.) 0092 */ 0093 #define BOOST_CONTRACT_CHECK_AUDIT(cond) 0094 #elif defined(BOOST_CONTRACT_AUDITS) 0095 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ 0096 BOOST_CONTRACT_CHECK(cond) 0097 #else 0098 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ 0099 BOOST_CONTRACT_DETAIL_NOEVAL(cond) 0100 #endif 0101 0102 /** 0103 Preferred way to document in the code implementation check conditions that are 0104 computationally prohibitive, at least compared to the computational cost of 0105 executing the function body. 0106 0107 The specified condition will always be compiled and validated syntactically, but 0108 it will never be checked at run-time. 0109 This macro is defined by code equivalent to: 0110 0111 @code 0112 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \ 0113 BOOST_CONTRACT_CHECK(true || cond) 0114 @endcode 0115 0116 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and 0117 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels predefined 0118 by this library for implementation checks. 0119 If there is a need, programmers are free to implement their own assertion levels 0120 defining macros similar to the one above. 0121 0122 @see @RefSect{extras.assertion_levels, Assertion Levels} 0123 0124 @param cond Boolean condition to check within implementation code (function 0125 body, etc.). 0126 (This is not a variadic macro parameter so any comma it might 0127 contain must be protected by round parenthesis and 0128 @c BOOST_CONTRACT_CHECK_AXIOM((cond)) will always work.) 0129 */ 0130 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \ 0131 BOOST_CONTRACT_DETAIL_NOEVAL(cond) 0132 0133 #endif // #include guard 0134
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |