]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [section boost/python/default_call_policies.hpp] |
2 | [section Class `default_call_policies`] | |
3 | `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`. | |
4 | `` | |
5 | namespace boost { namespace python | |
6 | { | |
7 | struct default_call_policies | |
8 | { | |
9 | static bool precall(PyObject*); | |
10 | static PyObject* postcall(PyObject*, PyObject* result); | |
11 | typedef default_result_converter result_converter; | |
12 | template <class Sig> struct extract_return_type : mpl::front<Sig>{}; | |
13 | }; | |
14 | }} | |
15 | `` | |
16 | [endsect] | |
17 | [section Class `default_call_policies` static functions] | |
18 | ``bool precall(PyObject*);`` | |
19 | [variablelist | |
20 | [[Returns][true]] | |
21 | [[Throws][nothing]] | |
22 | ] | |
23 | ``PyObject* postcall(PyObject*, PyObject* result);`` | |
24 | [variablelist | |
25 | [[Returns][result]] | |
26 | [[Throws][nothing]] | |
27 | ] | |
28 | [endsect] | |
29 | [section Class `default_result_converter`] | |
30 | 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. | |
31 | `` | |
32 | namespace boost { namespace python | |
33 | { | |
34 | struct default_result_converter | |
35 | { | |
36 | template <class T> struct apply; | |
37 | }; | |
38 | }} | |
39 | `` | |
40 | [endsect] | |
41 | [section Class `default_result_converter` metafunctions] | |
42 | ``template <class T> struct apply`` | |
43 | [variablelist | |
44 | [[Requires][T is not a reference type. If T is a pointer type, T is const char* or PyObject*. ]] | |
45 | [[Returns][typedef to_python_value<T const&> type;]] | |
46 | ] | |
47 | [endsect] | |
48 | [section Example] | |
49 | 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: | |
50 | `` | |
51 | template <class Handler, class Base = default_call_policies> | |
52 | struct return_value_policy : Base | |
53 | { | |
54 | typedef Handler result_converter; | |
55 | }; | |
56 | `` | |
57 | [endsect] | |
58 | [endsect] |