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