static_public_function.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_FUNCTION_HPP_
  2. #define BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_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_inv.hpp>
  10. #include <boost/contract/detail/none.hpp>
  11. #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
  12. !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
  13. !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  14. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  15. !defined(BOOST_CONTRACT_NO_EXCEPTS))
  16. #include <boost/contract/detail/checking.hpp>
  17. #endif
  18. #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
  19. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  20. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  21. #include <boost/config.hpp>
  22. #include <exception>
  23. #endif
  24. namespace boost { namespace contract { namespace detail {
  25. // No subcontracting because static so no obj and no substitution principle.
  26. template<class C> // Non-copyable base.
  27. class static_public_function : public cond_inv</* VR = */ none, C> {
  28. public:
  29. explicit static_public_function() : cond_inv</* VR = */ none, C>(
  30. boost::contract::from_function, /* obj = */ 0) {}
  31. private:
  32. #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
  33. !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  34. !defined(BOOST_CONTRACT_NO_OLDS)
  35. void init() /* override */ {
  36. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  37. if(checking::already()) return;
  38. #endif
  39. #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
  40. !defined(BOOST_CONTRACT_NO_PRECONDITIONS)
  41. { // Acquire checking guard.
  42. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  43. checking k;
  44. #endif
  45. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  46. this->check_entry_static_inv();
  47. #endif
  48. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  49. #ifndef \
  50. BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
  51. this->check_pre();
  52. } // Release checking guard (after pre check).
  53. #else
  54. } // Release checking guard (before pre check).
  55. this->check_pre();
  56. #endif
  57. #else
  58. } // Release checking guard
  59. #endif
  60. #endif
  61. #ifndef BOOST_CONTRACT_NO_OLDS
  62. this->copy_old();
  63. #endif
  64. }
  65. #endif
  66. public:
  67. #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
  68. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  69. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  70. ~static_public_function() BOOST_NOEXCEPT_IF(false) {
  71. this->assert_initialized();
  72. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  73. if(checking::already()) return;
  74. checking k;
  75. #endif
  76. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  77. this->check_exit_static_inv();
  78. #endif
  79. if(std::uncaught_exception()) {
  80. #ifndef BOOST_CONTRACT_NO_EXCEPTS
  81. this->check_except();
  82. #endif
  83. } else {
  84. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  85. this->check_post(none());
  86. #endif
  87. }
  88. }
  89. #endif
  90. };
  91. } } } // namespace
  92. #endif // #include guard