1 | // Copyright David Abrahams 2002.
|
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
3 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
5 | #ifndef DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
---|
6 | # define DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
---|
7 |
|
---|
8 | # include <boost/python/detail/prefix.hpp>
|
---|
9 | # include <boost/mpl/if.hpp>
|
---|
10 | # include <boost/python/to_python_value.hpp>
|
---|
11 | # include <boost/python/detail/value_arg.hpp>
|
---|
12 | # include <boost/type_traits/transform_traits.hpp>
|
---|
13 | # include <boost/type_traits/is_pointer.hpp>
|
---|
14 | # include <boost/type_traits/is_reference.hpp>
|
---|
15 | # include <boost/mpl/or.hpp>
|
---|
16 |
|
---|
17 | namespace boost { namespace python {
|
---|
18 |
|
---|
19 | template <class T> struct to_python_value;
|
---|
20 |
|
---|
21 | namespace detail
|
---|
22 | {
|
---|
23 | // for "readable" error messages
|
---|
24 | template <class T> struct specify_a_return_value_policy_to_wrap_functions_returning
|
---|
25 | # if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
---|
26 | {}
|
---|
27 | # endif
|
---|
28 | ;
|
---|
29 | }
|
---|
30 |
|
---|
31 | struct default_result_converter;
|
---|
32 |
|
---|
33 | struct default_call_policies
|
---|
34 | {
|
---|
35 | // Ownership of this argument tuple will ultimately be adopted by
|
---|
36 | // the caller.
|
---|
37 | template <class ArgumentPackage>
|
---|
38 | static bool precall(ArgumentPackage const&)
|
---|
39 | {
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | // Pass the result through
|
---|
44 | template <class ArgumentPackage>
|
---|
45 | static PyObject* postcall(ArgumentPackage const&, PyObject* result)
|
---|
46 | {
|
---|
47 | return result;
|
---|
48 | }
|
---|
49 |
|
---|
50 | typedef default_result_converter result_converter;
|
---|
51 | typedef PyObject* argument_package;
|
---|
52 | };
|
---|
53 |
|
---|
54 | struct default_result_converter
|
---|
55 | {
|
---|
56 | template <class R>
|
---|
57 | struct apply
|
---|
58 | {
|
---|
59 | typedef typename mpl::if_<
|
---|
60 | mpl::or_<is_pointer<R>, is_reference<R> >
|
---|
61 | , detail::specify_a_return_value_policy_to_wrap_functions_returning<R>
|
---|
62 | , boost::python::to_python_value<
|
---|
63 | typename detail::value_arg<R>::type
|
---|
64 | >
|
---|
65 | >::type type;
|
---|
66 | };
|
---|
67 | };
|
---|
68 |
|
---|
69 | // Exceptions for c strings an PyObject*s
|
---|
70 | template <>
|
---|
71 | struct default_result_converter::apply<char const*>
|
---|
72 | {
|
---|
73 | typedef boost::python::to_python_value<char const*const&> type;
|
---|
74 | };
|
---|
75 |
|
---|
76 | template <>
|
---|
77 | struct default_result_converter::apply<PyObject*>
|
---|
78 | {
|
---|
79 | typedef boost::python::to_python_value<PyObject*const&> type;
|
---|
80 | };
|
---|
81 |
|
---|
82 | }} // namespace boost::python
|
---|
83 |
|
---|
84 | #endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
---|