Chris@16: #if !defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: # ifndef INVOKE_DWA20021122_HPP Chris@16: # define INVOKE_DWA20021122_HPP Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: // This file declares a series of overloaded invoke(...) functions, Chris@16: // used to invoke wrapped C++ function (object)s from Python. Each one Chris@16: // accepts: Chris@16: // Chris@16: // - a tag which identifies the invocation syntax (e.g. member Chris@16: // functions must be invoked with a different syntax from regular Chris@16: // functions) Chris@16: // Chris@16: // - a pointer to a result converter type, used solely as a way of Chris@16: // transmitting the type of the result converter to the function (or Chris@16: // an int, if the return type is void). Chris@16: // Chris@16: // - the "function", which may be a function object, a function or Chris@16: // member function pointer, or a defaulted_virtual_fn. Chris@16: // Chris@16: // - The arg_from_python converters for each of the arguments to be Chris@16: // passed to the function being invoked. Chris@16: Chris@16: namespace boost { namespace python { namespace detail { Chris@16: Chris@16: // This "result converter" is really just used as a dispatch tag to Chris@16: // invoke(...), selecting the appropriate implementation Chris@16: typedef int void_result_to_python; Chris@16: Chris@16: template Chris@16: struct invoke_tag_ {}; Chris@16: Chris@16: // A metafunction returning the appropriate tag type for invoking an Chris@16: // object of type F with return type R. Chris@16: template Chris@16: struct invoke_tag Chris@16: : invoke_tag_< Chris@16: is_same::value Chris@16: , is_member_function_pointer::value Chris@16: > Chris@16: { Chris@16: }; Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_PYTHON_MAX_ARITY, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: }}} // namespace boost::python::detail Chris@16: Chris@16: # endif // INVOKE_DWA20021122_HPP Chris@16: #else Chris@16: Chris@16: # define N BOOST_PP_ITERATION() Chris@16: Chris@16: template Chris@16: inline PyObject* invoke(invoke_tag_, RC const& rc, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) Chris@16: { Chris@16: return rc(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) )); Chris@16: } Chris@16: Chris@16: template Chris@16: inline PyObject* invoke(invoke_tag_, RC const&, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) Chris@16: { Chris@16: f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) ); Chris@16: return none(); Chris@16: } Chris@16: Chris@16: template Chris@16: inline PyObject* invoke(invoke_tag_, RC const& rc, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) Chris@16: { Chris@16: return rc( (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)) ); Chris@16: } Chris@16: Chris@16: template Chris@16: inline PyObject* invoke(invoke_tag_, RC const&, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) Chris@16: { Chris@16: (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)); Chris@16: return none(); Chris@16: } Chris@16: Chris@16: # undef N Chris@16: Chris@16: #endif // BOOST_PP_IS_ITERATING