Back to home page

EIC code displayed by LXR

 
 

    


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 // Copyright (C) 2008-2018 Lorenzo Caminiti
0006 // Distributed under the Boost Software License, Version 1.0 (see accompanying
0007 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
0008 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
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 /* PRIVATE */
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; /* Boost.Func for lambdas, etc. */
0040 
0041 /* CODE */
0042 
0043 namespace boost { namespace contract { namespace detail {
0044 
0045 template<typename VR>
0046 class cond_post : public cond_base { // Non-copyable 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             // Won't raise this error if NO_POST (for optimization).
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 { // Non-copyable 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             /* r */ BOOST_PP_EMPTY(),
0078             void (),
0079             // Won't raise this error if NO_POST (for optimization).
0080             BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed,
0081             BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed()
0082         )
0083     #endif
0084 };
0085 
0086 } } } // namespace
0087 
0088 #endif // #include guard
0089