1 #if !defined(BOOST_PP_IS_ITERATING) 2 3 // Copyright David Abrahams 2002. 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 # ifndef INVOKE_DWA20021122_HPP 8 # define INVOKE_DWA20021122_HPP 9 10 # include <boost/python/detail/prefix.hpp> 11 # include <boost/python/detail/preprocessor.hpp> 12 # include <boost/python/detail/none.hpp> 13 14 # include <boost/preprocessor/iterate.hpp> 15 # include <boost/preprocessor/facilities/intercept.hpp> 16 # include <boost/preprocessor/repetition/enum_trailing_params.hpp> 17 # include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp> 18 # include <boost/preprocessor/repetition/enum_binary_params.hpp> 19 # include <boost/python/to_python_value.hpp> 20 21 // This file declares a series of overloaded invoke(...) functions, 22 // used to invoke wrapped C++ function (object)s from Python. Each one 23 // accepts: 24 // 25 // - a tag which identifies the invocation syntax (e.g. member 26 // functions must be invoked with a different syntax from regular 27 // functions) 28 // 29 // - a pointer to a result converter type, used solely as a way of 30 // transmitting the type of the result converter to the function (or 31 // an int, if the return type is void). 32 // 33 // - the "function", which may be a function object, a function or 34 // member function pointer, or a defaulted_virtual_fn. 35 // 36 // - The arg_from_python converters for each of the arguments to be 37 // passed to the function being invoked. 38 39 namespace boost { namespace python { namespace detail { 40 41 // This "result converter" is really just used as a dispatch tag to 42 // invoke(...), selecting the appropriate implementation 43 typedef int void_result_to_python; 44 45 template <bool void_return, bool member> 46 struct invoke_tag_ {}; 47 48 // A metafunction returning the appropriate tag type for invoking an 49 // object of type F with return type R. 50 template <class R, class F> 51 struct invoke_tag 52 : invoke_tag_< 53 is_same<R,void>::value 54 , is_member_function_pointer<F>::value 55 > 56 { 57 }; 58 59 # define BOOST_PP_ITERATION_PARAMS_1 \ 60 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/invoke.hpp>)) 61 # include BOOST_PP_ITERATE() 62 63 }}} // namespace boost::python::detail 64 65 # endif // INVOKE_DWA20021122_HPP 66 #else 67 68 # define N BOOST_PP_ITERATION() 69 70 template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)> 71 inline PyObject* invoke(invoke_tag_<false,false>, RC const& rc, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) 72 { 73 return rc(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) )); 74 } 75 76 template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)> 77 inline PyObject* invoke(invoke_tag_<true,false>, RC const&, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) 78 { 79 f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) ); 80 return none(); 81 } 82 83 template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)> 84 inline PyObject* invoke(invoke_tag_<false,true>, RC const& rc, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) 85 { 86 return rc( (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)) ); 87 } 88 89 template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)> 90 inline PyObject* invoke(invoke_tag_<true,true>, RC const&, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) 91 { 92 (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)); 93 return none(); 94 } 95 96 # undef N 97 98 #endif // BOOST_PP_IS_ITERATING 99