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