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