File indexing completed on 2025-01-18 09:30:26
0001
0002 #ifndef BOOST_CONTRACT_DETAIL_COND_POST_HPP_
0003 #define BOOST_CONTRACT_DETAIL_COND_POST_HPP_
0004
0005
0006
0007
0008
0009
0010 #include <boost/contract/core/exception.hpp>
0011 #include <boost/contract/core/config.hpp>
0012 #include <boost/contract/detail/condition/cond_base.hpp>
0013 #include <boost/contract/detail/none.hpp>
0014 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0015 #include <boost/contract/detail/type_traits/optional.hpp>
0016 #include <boost/optional.hpp>
0017 #include <boost/function.hpp>
0018 #include <boost/type_traits/remove_reference.hpp>
0019 #include <boost/mpl/if.hpp>
0020 #include <boost/preprocessor/facilities/empty.hpp>
0021 #endif
0022
0023
0024
0025 #define BOOST_CONTRACT_DETAIL_COND_POST_DEF_( \
0026 result_type, result_param, ftor_type, ftor_var, ftor_call) \
0027 public: \
0028 template<typename F> \
0029 void set_post(F const& f) { ftor_var = f; } \
0030 \
0031 protected: \
0032 void check_post(result_type const& result_param) { \
0033 if(failed()) return; \
0034 try { if(ftor_var) { ftor_call; } } \
0035 catch(...) { fail(&boost::contract::postcondition_failure); } \
0036 } \
0037 \
0038 private: \
0039 boost::function<ftor_type> ftor_var;
0040
0041
0042
0043 namespace boost { namespace contract { namespace detail {
0044
0045 template<typename VR>
0046 class cond_post : public cond_base {
0047 public:
0048 explicit cond_post(boost::contract::from from) : cond_base(from) {}
0049
0050 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0051 private: typedef typename boost::mpl::if_<is_optional<VR>,
0052 boost::optional<typename boost::remove_reference<typename
0053 optional_value_type<VR>::type>::type const&> const&
0054 ,
0055 VR const&
0056 >::type r_type;
0057
0058 BOOST_CONTRACT_DETAIL_COND_POST_DEF_(
0059 r_type,
0060 r,
0061 void (r_type),
0062
0063 BOOST_CONTRACT_ERROR_postcondition_result_parameter_required,
0064 BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r)
0065 )
0066 #endif
0067 };
0068
0069 template<>
0070 class cond_post<none> : public cond_base {
0071 public:
0072 explicit cond_post(boost::contract::from from) : cond_base(from) {}
0073
0074 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0075 BOOST_CONTRACT_DETAIL_COND_POST_DEF_(
0076 none,
0077 BOOST_PP_EMPTY(),
0078 void (),
0079
0080 BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed,
0081 BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed()
0082 )
0083 #endif
0084 };
0085
0086 } } }
0087
0088 #endif
0089