function.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef BOOST_CONTRACT_DETAIL_FUNCTION_HPP_
  2. #define BOOST_CONTRACT_DETAIL_FUNCTION_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/exception.hpp>
  8. #include <boost/contract/core/config.hpp>
  9. #include <boost/contract/detail/condition/cond_post.hpp>
  10. #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
  11. !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  12. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  13. !defined(BOOST_CONTRACT_NO_EXCEPTS))
  14. #include <boost/contract/detail/checking.hpp>
  15. #endif
  16. #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  17. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  18. #include <boost/config.hpp>
  19. #include <exception>
  20. #endif
  21. namespace boost { namespace contract { namespace detail {
  22. // Used for free function, private and protected member functions.
  23. class function : public cond_post</* VR = */ none> { // Non-copyable base.
  24. public:
  25. explicit function() : cond_post</* VR = */ none>(
  26. boost::contract::from_function) {}
  27. private:
  28. #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  29. !defined(BOOST_CONTRACT_NO_OLDS)
  30. void init() /* override */ {
  31. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  32. if(checking::already()) return;
  33. #endif
  34. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  35. {
  36. #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && \
  37. !defined( \
  38. BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION)
  39. checking k;
  40. #endif
  41. this->check_pre();
  42. }
  43. #endif
  44. #ifndef BOOST_CONTRACT_NO_OLDS
  45. this->copy_old();
  46. #endif
  47. }
  48. #endif
  49. public:
  50. #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  51. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  52. ~function() BOOST_NOEXCEPT_IF(false) {
  53. this->assert_initialized();
  54. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  55. if(checking::already()) return;
  56. checking k;
  57. #endif
  58. if(std::uncaught_exception()) {
  59. #ifndef BOOST_CONTRACT_NO_EXCEPTS
  60. this->check_except();
  61. #endif
  62. } else {
  63. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  64. this->check_post(none());
  65. #endif
  66. }
  67. }
  68. #endif
  69. };
  70. } } } // namespace
  71. #endif // #include guard