python/doc/reference/default_call_policies.qbk
2015-08-04 15:34:56 -04:00

59 lines
2.1 KiB
Plaintext

[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]