• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/type_traits.hpp>
12 # include <boost/python/detail/value_arg.hpp>
13 # include <boost/mpl/or.hpp>
14 # include <boost/mpl/front.hpp>
15 
16 namespace boost { namespace python {
17 
18 template <class T> struct to_python_value;
19 
20 namespace detail
21 {
22 // for "readable" error messages
23   template <class T> struct specify_a_return_value_policy_to_wrap_functions_returning
24 # if defined(__GNUC__) || defined(__EDG__)
25   {}
26 # endif
27   ;
28 }
29 
30 struct default_result_converter;
31 
32 struct default_call_policies
33 {
34     // Ownership of this argument tuple will ultimately be adopted by
35     // the caller.
36     template <class ArgumentPackage>
precallboost::python::default_call_policies37     static bool precall(ArgumentPackage const&)
38     {
39         return true;
40     }
41 
42     // Pass the result through
43     template <class ArgumentPackage>
postcallboost::python::default_call_policies44     static PyObject* postcall(ArgumentPackage const&, PyObject* result)
45     {
46         return result;
47     }
48 
49     typedef default_result_converter result_converter;
50     typedef PyObject* argument_package;
51 
52     template <class Sig>
53     struct extract_return_type : mpl::front<Sig>
54     {
55     };
56 
57 };
58 
59 struct default_result_converter
60 {
61     template <class R>
62     struct apply
63     {
64         typedef typename mpl::if_<
65             mpl::or_<detail::is_pointer<R>, detail::is_reference<R> >
66           , detail::specify_a_return_value_policy_to_wrap_functions_returning<R>
67           , boost::python::to_python_value<
68                 typename detail::value_arg<R>::type
69             >
70         >::type type;
71     };
72 };
73 
74 // Exceptions for c strings an PyObject*s
75 template <>
76 struct default_result_converter::apply<char const*>
77 {
78     typedef boost::python::to_python_value<char const*const&> type;
79 };
80 
81 template <>
82 struct default_result_converter::apply<PyObject*>
83 {
84     typedef boost::python::to_python_value<PyObject*const&> type;
85 };
86 
87 }} // namespace boost::python
88 
89 #endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP
90