| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| |
| <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
| <!-- Software License, Version 1.0. (See accompanying --> |
| <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
| <html> |
| <head> |
| <meta name="generator" content= |
| "HTML Tidy for Windows (vers 1st August 2002), see www.w3.org"> |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| <link rel="stylesheet" type="text/css" href="../boost.css"> |
| |
| <title>Boost.Python - <boost/python/manage_new_object.hpp></title> |
| </head> |
| |
| <body> |
| <table border="0" cellpadding="7" cellspacing="0" width="100%" summary= |
| "header"> |
| <tr> |
| <td valign="top" width="300"> |
| <h3><a href="../../../../index.htm"><img height="86" width="277" |
| alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3> |
| </td> |
| |
| <td valign="top"> |
| <h1 align="center"><a href="../index.html">Boost.Python</a></h1> |
| |
| <h2 align="center">Header |
| <boost/python/manage_new_object.hpp></h2> |
| </td> |
| </tr> |
| </table> |
| <hr> |
| |
| <h2>Contents</h2> |
| |
| <dl class="page-index"> |
| <dt><a href="#classes">Classes</a></dt> |
| |
| <dd> |
| <dl class="page-index"> |
| <dt><a href="#manage_new_object-spec">Class |
| <code>manage_new_object</code></a></dt> |
| |
| <dd> |
| <dl class="page-index"> |
| <dt><a href="#manage_new_object-spec-synopsis">Class |
| <code>manage_new_object</code> synopsis</a></dt> |
| |
| <dt><a href="#manage_new_object-spec-metafunctions">Class |
| <code>manage_new_object</code> metafunctions</a></dt> |
| </dl> |
| </dd> |
| </dl> |
| </dd> |
| |
| <dt><a href="#examples">Example</a></dt> |
| </dl> |
| <hr> |
| |
| <h2><a name="classes"></a>Classes</h2> |
| |
| <h3><a name="manage_new_object-spec"></a>Class |
| <code>manage_new_object</code></h3> |
| |
| <p><code>manage_new_object</code> is a model of <a href= |
| "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a> |
| which can be used to wrap C++ functions which return a pointer to an |
| object allocated with a <i>new-expression</i>, and expect the caller to |
| take responsibility for deleting that object.</p> |
| |
| <h4><a name="manage_new_object-spec-synopsis"></a>Class |
| <code>manage_new_object</code> synopsis</h4> |
| <pre> |
| namespace boost { namespace python |
| { |
| struct manage_new_object |
| { |
| template <class T> struct apply; |
| }; |
| }} |
| </pre> |
| |
| <h4><a name="manage_new_object-spec-metafunctions"></a>Class |
| <code>manage_new_object</code> metafunctions</h4> |
| <pre> |
| template <class T> struct apply |
| </pre> |
| |
| <dl class="metafunction-semantics"> |
| <dt><b>Requires:</b> <code>T</code> is <code>U*</code> for some |
| <code>U</code>.</dt> |
| |
| <dt><b>Returns:</b> <code>typedef <a href= |
| "to_python_indirect.html#to_python_indirect-spec">to_python_indirect</a><T> |
| type;</code></dt> |
| </dl> |
| |
| <h2><a name="examples"></a>Example</h2> |
| |
| <p>In C++:</p> |
| <pre> |
| #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) |
| ; |
| } |
| </pre> |
| In Python: |
| <pre> |
| >>> from my_module import * |
| >>> f = make_foo(3) # create a Foo object |
| >>> f.get_x() |
| 3 |
| </pre> |
| |
| <p>Revised |
| <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
| 13 November, 2002 |
| <!--webbot bot="Timestamp" endspan i-checksum="39359" --> |
| </p> |
| |
| <p><i>© Copyright <a href= |
| "http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p> |
| </body> |
| </html> |
| |