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