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