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