summaryrefslogtreecommitdiff
path: root/libs/python/doc/reference/default_call_policies.qbk
blob: 99b969be7dc86202cf72284cadc1242d14adb9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[section boost/python/default_call_policies.hpp]
[section Class `default_call_policies`]
`default_call_policies` is a model of [link concepts.callpolicies `CallPolicies`] with no `precall` or `postcall` behavior and a `result_converter` which handles by-value returns. Wrapped C++ functions and member functions `use default_call_policies` unless otherwise specified. You may find it convenient to derive new models of [link concepts.callpolicies `CallPolicies`] from `default_call_policies`. 
``
namespace boost { namespace python
{
    struct default_call_policies
    {
        static bool precall(PyObject*);
        static PyObject* postcall(PyObject*, PyObject* result);
        typedef default_result_converter result_converter;
        template <class Sig> struct extract_return_type : mpl::front<Sig>{};
    };
}}
``
[endsect]
[section Class `default_call_policies` static functions]
``bool precall(PyObject*);``
[variablelist
[[Returns][true]]
[[Throws][nothing]]
]
``PyObject* postcall(PyObject*, PyObject* result);``
[variablelist
[[Returns][result]]
[[Throws][nothing]]
]
[endsect]
[section Class `default_result_converter`]
default_result_converter is a model of [link concepts.resultconverter.resultconvertergenerator_concept `ResultConverterGenerator`] which can be used to wrap C++ functions returning non-pointer types, `char const*`, and `PyObject*`, by-value.
``
namespace boost { namespace python
{
    struct default_result_converter
    {
        template <class T> struct apply;
    };
}}
``
[endsect]
[section Class `default_result_converter` metafunctions]
``template <class T> struct apply``
[variablelist
[[Requires][T is not a reference type. If T is a pointer type, T is const char* or PyObject*. ]]
[[Returns][typedef to_python_value<T const&> type;]]
]
[endsect]
[section Example]
This example comes from the Boost.Python implementation itself. Because the return_value_policy class template does not implement precall or postcall behavior, its default base class is default_call_policies:
``
template <class Handler, class Base = default_call_policies>
struct return_value_policy : Base
{
   typedef Handler result_converter;
};
``
[endsect]
[endsect]