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