check.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef BOOST_CONTRACT_DETAIL_CHECK_HPP_
  2. #define BOOST_CONTRACT_DETAIL_CHECK_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. #include <boost/contract/core/config.hpp>
  8. #ifndef BOOST_CONTRACT_NO_CHECKS
  9. #include <boost/contract/core/exception.hpp>
  10. /* PRIVATE */
  11. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  12. #include <boost/contract/detail/checking.hpp>
  13. #include <boost/contract/detail/name.hpp>
  14. #define BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ \
  15. if(!boost::contract::detail::checking::already())
  16. #define BOOST_CONTRACT_CHECK_CHECKING_VAR_(guard) \
  17. /* this name somewhat unique to min var shadow warnings */ \
  18. boost::contract::detail::checking BOOST_CONTRACT_DETAIL_NAME2( \
  19. guard, __LINE__);
  20. #else
  21. #define BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ /* nothing */
  22. #define BOOST_CONTRACT_CHECK_CHECKING_VAR_(guard) /* nothing */
  23. #endif
  24. /* PUBLIC */
  25. #define BOOST_CONTRACT_DETAIL_CHECK(assertion) \
  26. { \
  27. try { \
  28. BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ \
  29. { \
  30. BOOST_CONTRACT_CHECK_CHECKING_VAR_(k) \
  31. { assertion; } \
  32. } \
  33. } catch(...) { boost::contract::check_failure(); } \
  34. }
  35. #else
  36. #define BOOST_CONTRACT_DETAIL_CHECK(assertion) {}
  37. #endif
  38. #endif // #include guard