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

source code of boost/boost/python/default_call_policies.hpp