[29] | 1 | #if !defined(BOOST_PP_IS_ITERATING) |
---|
| 2 | |
---|
| 3 | // Copyright David Abrahams 2004. Distributed under the Boost |
---|
| 4 | // Software License, Version 1.0. (See accompanying |
---|
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
| 6 | #ifndef OVERRIDE_DWA2004721_HPP |
---|
| 7 | # define OVERRIDE_DWA2004721_HPP |
---|
| 8 | |
---|
| 9 | # include <boost/python/detail/prefix.hpp> |
---|
| 10 | |
---|
| 11 | # include <boost/python/converter/return_from_python.hpp> |
---|
| 12 | |
---|
| 13 | # include <boost/python/extract.hpp> |
---|
| 14 | # include <boost/python/handle.hpp> |
---|
| 15 | |
---|
| 16 | # include <boost/preprocessor/iterate.hpp> |
---|
| 17 | # include <boost/preprocessor/repeat.hpp> |
---|
| 18 | # include <boost/preprocessor/debug/line.hpp> |
---|
| 19 | # include <boost/preprocessor/repetition/enum_params.hpp> |
---|
| 20 | # include <boost/preprocessor/repetition/enum_binary_params.hpp> |
---|
| 21 | |
---|
| 22 | # include <boost/type.hpp> |
---|
| 23 | |
---|
| 24 | namespace boost { namespace python { |
---|
| 25 | |
---|
| 26 | class override; |
---|
| 27 | |
---|
| 28 | namespace detail |
---|
| 29 | { |
---|
| 30 | class wrapper_base; |
---|
| 31 | |
---|
| 32 | // The result of calling a method. |
---|
| 33 | class method_result |
---|
| 34 | { |
---|
| 35 | private: |
---|
| 36 | friend class boost::python::override; |
---|
| 37 | explicit method_result(PyObject* x) |
---|
| 38 | : m_obj(x) |
---|
| 39 | {} |
---|
| 40 | |
---|
| 41 | public: |
---|
| 42 | template <class T> |
---|
| 43 | operator T() |
---|
| 44 | { |
---|
| 45 | converter::return_from_python<T> converter; |
---|
| 46 | return converter(m_obj.release()); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | # if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(140050215)) |
---|
| 50 | template <class T> |
---|
| 51 | operator T*() |
---|
| 52 | { |
---|
| 53 | converter::return_from_python<T*> converter; |
---|
| 54 | return converter(m_obj.release()); |
---|
| 55 | } |
---|
| 56 | # endif |
---|
| 57 | |
---|
| 58 | # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) || BOOST_WORKAROUND(BOOST_INTEL_WIN, >= 900) |
---|
| 59 | // No operator T& |
---|
| 60 | # else |
---|
| 61 | |
---|
| 62 | template <class T> |
---|
| 63 | operator T&() const |
---|
| 64 | { |
---|
| 65 | converter::return_from_python<T&> converter; |
---|
| 66 | return converter(const_cast<handle<>&>(m_obj).release()); |
---|
| 67 | } |
---|
| 68 | # endif |
---|
| 69 | |
---|
| 70 | template <class T> |
---|
| 71 | T as(type<T>* = 0) |
---|
| 72 | { |
---|
| 73 | converter::return_from_python<T> converter; |
---|
| 74 | return converter(m_obj.release()); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | template <class T> |
---|
| 78 | T unchecked(type<T>* = 0) |
---|
| 79 | { |
---|
| 80 | return extract<T>(m_obj)(); |
---|
| 81 | } |
---|
| 82 | private: |
---|
| 83 | mutable handle<> m_obj; |
---|
| 84 | }; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | class override : public object |
---|
| 88 | { |
---|
| 89 | private: |
---|
| 90 | friend class detail::wrapper_base; |
---|
| 91 | override(handle<> x) |
---|
| 92 | : object(x) |
---|
| 93 | {} |
---|
| 94 | |
---|
| 95 | public: |
---|
| 96 | detail::method_result |
---|
| 97 | operator()() const |
---|
| 98 | { |
---|
| 99 | detail::method_result x( |
---|
| 100 | PyEval_CallFunction( |
---|
| 101 | this->ptr() |
---|
| 102 | , const_cast<char*>("()") |
---|
| 103 | )); |
---|
| 104 | return x; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | # define BOOST_PYTHON_fast_arg_to_python_get(z, n, _) \ |
---|
| 108 | , converter::arg_to_python<A##n>(a##n).get() |
---|
| 109 | |
---|
| 110 | # define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/override.hpp>)) |
---|
| 111 | # include BOOST_PP_ITERATE() |
---|
| 112 | |
---|
| 113 | # undef BOOST_PYTHON_fast_arg_to_python_get |
---|
| 114 | }; |
---|
| 115 | |
---|
| 116 | }} // namespace boost::python |
---|
| 117 | |
---|
| 118 | #endif // OVERRIDE_DWA2004721_HPP |
---|
| 119 | |
---|
| 120 | #else |
---|
| 121 | # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \ |
---|
| 122 | && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) |
---|
| 123 | # line BOOST_PP_LINE(__LINE__, override.hpp) |
---|
| 124 | # endif |
---|
| 125 | |
---|
| 126 | # define N BOOST_PP_ITERATION() |
---|
| 127 | |
---|
| 128 | template < |
---|
| 129 | BOOST_PP_ENUM_PARAMS_Z(1, N, class A) |
---|
| 130 | > |
---|
| 131 | detail::method_result |
---|
| 132 | operator()( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a) ) const |
---|
| 133 | { |
---|
| 134 | detail::method_result x( |
---|
| 135 | PyEval_CallFunction( |
---|
| 136 | this->ptr() |
---|
| 137 | , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") |
---|
| 138 | BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_fast_arg_to_python_get, nil) |
---|
| 139 | )); |
---|
| 140 | return x; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | # undef N |
---|
| 144 | #endif |
---|