public_function.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #ifndef BOOST_CONTRACT_DETAIL_PUBLIC_FUNCTION_HPP_
  2. #define BOOST_CONTRACT_DETAIL_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/virtual.hpp>
  8. #include <boost/contract/core/exception.hpp>
  9. #include <boost/contract/core/config.hpp>
  10. #include <boost/contract/detail/condition/cond_subcontracting.hpp>
  11. #include <boost/contract/detail/tvariadic.hpp>
  12. #include <boost/contract/core/virtual.hpp>
  13. #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
  14. !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
  15. !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  16. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  17. !defined(BOOST_CONTRACT_NO_EXCEPTS))
  18. #include <boost/contract/detail/checking.hpp>
  19. #endif
  20. #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
  21. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  22. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  23. #include <boost/config.hpp>
  24. #endif
  25. #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  26. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  27. #include <exception>
  28. #endif
  29. namespace boost { namespace contract { namespace detail {
  30. template<
  31. class O, typename VR, typename F, class C
  32. BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
  33. BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args)
  34. >
  35. class public_function : // Non-copyable base.
  36. public cond_subcontracting<
  37. O, VR, F, C
  38. BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
  39. BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args)
  40. >
  41. {
  42. public:
  43. explicit public_function(
  44. boost::contract::virtual_* v, C* obj, VR& r
  45. BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
  46. BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1,
  47. BOOST_CONTRACT_MAX_ARGS, Args, &, args)
  48. ) :
  49. cond_subcontracting<
  50. O, VR, F, C
  51. BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
  52. BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1,
  53. BOOST_CONTRACT_MAX_ARGS, Args)
  54. >(
  55. boost::contract::from_function, v, obj, r
  56. BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
  57. BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1,
  58. BOOST_CONTRACT_MAX_ARGS, args)
  59. )
  60. {}
  61. private:
  62. #if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
  63. !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
  64. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  65. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  66. void init() /* override */ {
  67. #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  68. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  69. this->init_subcontracted_old();
  70. #endif
  71. if(!this->base_call()) {
  72. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  73. if(checking::already()) return;
  74. #endif
  75. { // Acquire checking guard.
  76. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  77. checking k;
  78. #endif
  79. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  80. this->check_subcontracted_entry_inv();
  81. #endif
  82. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  83. #ifndef \
  84. BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
  85. this->check_subcontracted_pre();
  86. } // Release checking guard (after pre check).
  87. #else
  88. } // Release checking guard (before pre check).
  89. this->check_subcontracted_pre();
  90. #endif
  91. #else
  92. } // Release checking guard.
  93. #endif
  94. #ifndef BOOST_CONTRACT_NO_OLDS
  95. this->copy_subcontracted_old();
  96. #endif
  97. } else {
  98. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  99. this->check_subcontracted_entry_inv();
  100. #endif
  101. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  102. this->check_subcontracted_pre();
  103. #endif
  104. #ifndef BOOST_CONTRACT_NO_OLDS
  105. this->copy_subcontracted_old();
  106. #endif
  107. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  108. this->check_subcontracted_exit_inv();
  109. #endif
  110. if(std::uncaught_exception()) {
  111. #ifndef BOOST_CONTRACT_NO_EXCEPTS
  112. this->check_subcontracted_except();
  113. #endif
  114. } else {
  115. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  116. this->check_subcontracted_post();
  117. #endif
  118. }
  119. }
  120. }
  121. #endif
  122. public:
  123. #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
  124. !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
  125. !defined(BOOST_CONTRACT_NO_EXCEPTS)
  126. ~public_function() BOOST_NOEXCEPT_IF(false) {
  127. this->assert_initialized();
  128. if(!this->base_call()) {
  129. #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
  130. if(checking::already()) return;
  131. checking k;
  132. #endif
  133. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  134. this->check_subcontracted_exit_inv();
  135. #endif
  136. if(std::uncaught_exception()) {
  137. #ifndef BOOST_CONTRACT_NO_EXCEPTS
  138. this->check_subcontracted_except();
  139. #endif
  140. } else {
  141. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  142. this->check_subcontracted_post();
  143. #endif
  144. }
  145. }
  146. }
  147. #endif
  148. };
  149. } } } // namespace
  150. #endif // #include guard