diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:33:54 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:36:09 +0900 |
commit | d9ec475d945d3035377a0d89ed42e382d8988891 (patch) | |
tree | 34aff2cee4b209906243ab5499d61f3edee2982f /libs/python/doc/reference/manage_new_object.qbk | |
parent | 71d216b90256936a9638f325af9bc69d720e75de (diff) | |
download | boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.gz boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.bz2 boost-d9ec475d945d3035377a0d89ed42e382d8988891.zip |
Imported Upstream version 1.60.0
Change-Id: Ie709530d6d5841088ceaba025cbe175a4ef43050
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'libs/python/doc/reference/manage_new_object.qbk')
-rw-r--r-- | libs/python/doc/reference/manage_new_object.qbk | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libs/python/doc/reference/manage_new_object.qbk b/libs/python/doc/reference/manage_new_object.qbk new file mode 100644 index 0000000000..95cc6859c7 --- /dev/null +++ b/libs/python/doc/reference/manage_new_object.qbk @@ -0,0 +1,56 @@ +[section boost/python/manage_new_object.hpp] +[section Class `manage_new_object`] +`manage_new_object` is a model of [link concepts.resultconverter.resultconvertergenerator_concept ResultConverterGenerator] which can be used to wrap C++ functions which return a pointer to an object allocated with a new-expression, and expect the caller to take responsibility for deleting that object. +`` +namespace boost { namespace python +{ + struct manage_new_object + { + template <class T> struct apply; + }; +}} +`` +[endsect] +[section Class `manage_new_object` metafunctions] +``template <class T> struct apply`` +[variablelist +[[Requires][`T` is `U*` for some `U`.]] +[[Returns][`typedef to_python_indirect<T> type;`]] +] +[endsect] +[section Example] +In C++: +`` +#include <boost/python/module.hpp> +#include <boost/python/class.hpp> +#include <boost/python/manage_new_object.hpp> +#include <boost/python/return_value_policy.hpp> + + +struct Foo { + Foo(int x) : x(x){} + int get_x() { return x; } + int x; +}; + +Foo* make_foo(int x) { return new Foo(x); } + +// Wrapper code +using namespace boost::python; +BOOST_PYTHON_MODULE(my_module) +{ + def("make_foo", make_foo, return_value_policy<manage_new_object>()) + class_<Foo>("Foo") + .def("get_x", &Foo::get_x) + ; +} +`` +Python code: +`` +>>> from my_module import * +>>> f = make_foo(3) # create a Foo object +>>> f.get_x() +3 +`` +[endsect] +[endsect] |