source: NonGTP/Boost/boost/python/default_call_policies.hpp @ 857

Revision 857, 2.3 KB checked in by igarcia, 19 years ago (diff)
Line 
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
17namespace boost { namespace python {
18
19template <class T> struct to_python_value;
20
21namespace 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
31struct default_result_converter;
32
33struct 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
54struct 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
70template <>
71struct default_result_converter::apply<char const*>
72{
73    typedef boost::python::to_python_value<char const*const&> type;
74};
75
76template <>
77struct 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
Note: See TracBrowser for help on using the repository browser.