mirror of
https://github.com/boostorg/python.git
synced 2026-01-20 04:42:28 +00:00
doc update
[SVN r15562]
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
p.c3 {font-style: italic}
|
||||
h2.c2 {text-align: center}
|
||||
h1.c1 {text-align: center}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -97,8 +97,8 @@ namespace boost { namespace python
|
||||
|
||||
<dt>Specializations may substitute a value convertible to
|
||||
<code>true</code> for <code>value</code> iff for each invocation of
|
||||
<code>class_<WrappedClass>::def_init(args<</code><i>type-sequence...</i>
|
||||
<code>>())</code>, there exists a corresponding constructor
|
||||
<code>class_<WrappedClass>::def(init<</code><i>type-sequence...</i><code>
|
||||
>())</code>, there exists a corresponding constructor
|
||||
<code>WrappedClass::WrappedClass(PyObject*, </code><i>type-sequence...</i>
|
||||
<code>)</code>. If such a specialization exists, the
|
||||
<code>WrappedClass</code> constructors will be called with a "back
|
||||
|
||||
@@ -116,7 +116,7 @@ using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
def("make_foo", make_foo, return_value_policy<manage_new_object>())
|
||||
class_<Foo>()
|
||||
class_<Foo>("Foo")
|
||||
.def("get_x", &Foo::get_x)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(singleton)
|
||||
{
|
||||
def("get_it", get_it, reference_existing_object());
|
||||
class_<Singleton>()
|
||||
class_<Singleton>("Singleton")
|
||||
.def("exchange", &Singleton::exchange)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -186,13 +186,12 @@ class Foo
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(internal_refs)
|
||||
{
|
||||
class_<Bar>()
|
||||
class_<Bar>("Bar")
|
||||
.def("get_x", &Bar::get_x)
|
||||
.def("set_x", &Bar::set_x)
|
||||
;
|
||||
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
class_<Foo>("Foo", init<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_internal_reference<>())
|
||||
;
|
||||
|
||||
@@ -1,89 +1,106 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
|
||||
<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/return_value_policy.hpp></title>
|
||||
<title>Boost.Python -
|
||||
<boost/python/return_value_policy.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="../../../../c++boost.gif" border="0"></a></h3>
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277"
|
||||
alt="C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/return_value_policy.hpp></h2>
|
||||
<h2 align="center">Header
|
||||
<boost/python/return_value_policy.hpp></h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
<dt><a href="#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#return_value_policy-spec">Class Template <code>return_value_policy</code></a>
|
||||
<dt><a href="#return_value_policy-spec">Class Template
|
||||
<code>return_value_policy</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#return_value_policy-spec-synopsis">Class Template
|
||||
<code>return_value_policy</code> synopsis</a>
|
||||
<code>return_value_policy</code> synopsis</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
<dt><a href="#examples">Example</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code>return_value_policy</code> instantiations are simply models
|
||||
of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> which are composed of a <a href=
|
||||
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a> and optional <code>Base</code> <a href=
|
||||
"CallPolicies.html">CallPolicies</a>.
|
||||
<code>return_value_policy</code> instantiations are simply models of <a
|
||||
href="CallPolicies.html">CallPolicies</a> which are composed of a <a
|
||||
href=
|
||||
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>
|
||||
and optional <code>Base</code> <a href=
|
||||
"CallPolicies.html">CallPolicies</a>.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="return_value_policy-spec"></a>Class template <code>return_value_policy</code></h3>
|
||||
|
||||
<h3><a name="return_value_policy-spec"></a>Class template
|
||||
<code>return_value_policy</code></h3>
|
||||
|
||||
<table border="1" summary="return_value_policy template parameters">
|
||||
<caption>
|
||||
<b><code>return_value_policy</code> template parameters</b>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Default
|
||||
|
||||
<tr>
|
||||
<td><a href="ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>
|
||||
<th>Parameter</th>
|
||||
|
||||
<th>Requirements</th>
|
||||
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><a href=
|
||||
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a></td>
|
||||
|
||||
<td>A model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a>.
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a>.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><code>Base</code>
|
||||
<td><code>Base</code></td>
|
||||
|
||||
<td>A model of <a href="CallPolicies.html">CallPolicies</a>
|
||||
|
||||
<td><code><a href="default_call_policies.html#default_call_policies-spec">default_call_policies</a></code>
|
||||
<td>A model of <a href="CallPolicies.html">CallPolicies</a></td>
|
||||
|
||||
<td><code><a href=
|
||||
"default_call_policies.html#default_call_policies-spec">default_call_policies</a></code></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4><a name="return_value_policy-spec-synopsis"></a>Class template <code>return_value_policy</code> synopsis</h4>
|
||||
<h4><a name="return_value_policy-spec-synopsis"></a>Class template
|
||||
<code>return_value_policy</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
@@ -97,9 +114,9 @@ namespace boost { namespace python
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<h3>C++ Module Definition</h3>
|
||||
<h3>C++ Module Definition</h3>
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/module_init.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/copy_const_reference.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
@@ -118,20 +135,16 @@ struct Foo {
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
module("my_module")
|
||||
.add(
|
||||
class_<Bar>()
|
||||
)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_value_policy<copy_const_reference>())
|
||||
)
|
||||
;
|
||||
class_<Bar>("Bar");
|
||||
|
||||
class_<Foo>("Foo", init<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_value_policy<copy_const_reference>())
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
<h3>Python Code</h3>
|
||||
|
||||
<h3>Python Code</h3>
|
||||
<pre>
|
||||
>>> from my_module import *
|
||||
>>> f = Foo(3) # create a Foo object
|
||||
@@ -140,9 +153,13 @@ BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 February, 2002
|
||||
15 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
<p><i>© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
||||
Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,96 +1,114 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
|
||||
<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/to_python_converter.hpp></title>
|
||||
<title>Boost.Python -
|
||||
<boost/python/to_python_converter.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="../../../../c++boost.gif" border="0"></a></h3>
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277"
|
||||
alt="C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/to_python_converter.hpp></h2>
|
||||
<h2 align="center">Header
|
||||
<boost/python/to_python_converter.hpp></h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
<dt><a href="#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#to_python_converter-spec">Class Template <code>to_python_converter</code></a>
|
||||
<dt><a href="#to_python_converter-spec">Class Template
|
||||
<code>to_python_converter</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#to_python_converter-spec-synopsis">Class Template
|
||||
<code>to_python_converter</code> synopsis</a>
|
||||
<code>to_python_converter</code> synopsis</a></dt>
|
||||
|
||||
<dt><a href="#to_python_converter-spec-ctors">Class Template
|
||||
<code>to_python_converter</code> constructor</a>
|
||||
<code>to_python_converter</code> constructor</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
<dt><a href="#examples">Example</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code>to_python_converter</code> registers a conversion from
|
||||
objects of a given C++ type into a Python object.
|
||||
<code>to_python_converter</code> registers a conversion from objects of a
|
||||
given C++ type into a Python object.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="to_python_converter-spec"></a>Class template <code>to_python_converter</code></h3>
|
||||
|
||||
<code>to_python_converter</code> adds a wrapper around a static
|
||||
member function of its second template parameter, handling
|
||||
low-level details such as insertion into the converter registry.
|
||||
<h3><a name="to_python_converter-spec"></a>Class template
|
||||
<code>to_python_converter</code></h3>
|
||||
<code>to_python_converter</code> adds a wrapper around a static member
|
||||
function of its second template parameter, handling low-level details
|
||||
such as insertion into the converter registry.
|
||||
|
||||
<table border="1" summary="to_python_converter template parameters">
|
||||
<caption>
|
||||
<b><code>to_python_converter</code> template parameters</b><br>
|
||||
In the table below, <b><code>x</code></b> denotes an object of type <code>T</code>
|
||||
In the table below, <b><code>x</code></b> denotes an object of type
|
||||
<code>T</code>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Description
|
||||
|
||||
<tr>
|
||||
<td><code>T</code>
|
||||
<th>Parameter</th>
|
||||
|
||||
<th>Requirements</th>
|
||||
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><code>T</code></td>
|
||||
|
||||
<td>
|
||||
</td>
|
||||
|
||||
<td>The C++ type of the source object in the conversion
|
||||
<td>The C++ type of the source object in the conversion</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><code>Conversion</code>
|
||||
<td><code>Conversion</code></td>
|
||||
|
||||
<td><code>PyObject* p = Conversion::convert(x)</code>,<br>
|
||||
if <code>p == 0</code>, <code><a href="http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>() != 0</code>.
|
||||
<td>
|
||||
<code>PyObject* p = Conversion::convert(x)</code>,<br>
|
||||
if <code>p == 0</code>, <code><a href=
|
||||
"http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>() != 0</code>.</td>
|
||||
|
||||
<td>A class type whose static member function
|
||||
<code>convert</code> does the real work of the conversion.
|
||||
|
||||
<tr>
|
||||
<td>A class type whose static member function <code>convert</code>
|
||||
does the real work of the conversion.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4><a name="to_python_converter-spec-synopsis"></a>Class template <code>to_python_converter</code> synopsis</h4>
|
||||
<h4><a name="to_python_converter-spec-synopsis"></a>Class template
|
||||
<code>to_python_converter</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
@@ -102,34 +120,31 @@ namespace boost { namespace python
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="to_python_converter-spec-ctors"></a>Class template <code>to_python_converter</code> constructor</h4>
|
||||
<h4><a name="to_python_converter-spec-ctors"></a>Class template
|
||||
<code>to_python_converter</code> constructor</h4>
|
||||
<pre>
|
||||
to_python_converter();
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Effects:</b> Registers a to_python converter which uses
|
||||
<code>Conversion::convert()</code> to do its work.
|
||||
|
||||
<code>Conversion::convert()</code> to do its work.</dt>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
This example presumes that someone has implemented the standard <a href=
|
||||
"http://www.python.org/doc/2.2/ext/dnt-basics.html">noddy example
|
||||
module</a> from the Python documentation, and placed the corresponding
|
||||
declarations in <code>"noddy.h"</code>. Because
|
||||
<code>noddy_NoddyObject</code> is the ultimate trivial extension type,
|
||||
the example is a bit contrived: it wraps a function for which all
|
||||
information is contained in the <i>type</i> of its return value.
|
||||
|
||||
This example presumes that someone has implemented the standard <a
|
||||
href="http://www.python.org/doc/2.2/ext/dnt-basics.html">noddy example
|
||||
module</a> from the Python documentation, and placed the corresponding
|
||||
declarations in <code>"noddy.h"</code>. Because
|
||||
<code>noddy_NoddyObject</code> is the ultimate trivial extension type,
|
||||
the example is a bit contrived: it wraps a function for which all
|
||||
information is contained in the <i>type</i> of its return value.
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
<pre>
|
||||
#include <boost/python/reference.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include "noddy.h"
|
||||
#include <boost/python/module_init.hpp>
|
||||
#include "noddy.h"
|
||||
|
||||
struct tag {};
|
||||
tag make_tag() { return tag(); }
|
||||
@@ -146,15 +161,12 @@ struct tag_to_noddy
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(to_python_converter)
|
||||
{
|
||||
module("to_python_converter")
|
||||
.def("make_tag", make_tag)
|
||||
;
|
||||
def("make_tag", make_tag);
|
||||
to_python_converter<tag, tag_to_noddy>();
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3>Python code</h3>
|
||||
|
||||
<h3>Python code</h3>
|
||||
<pre>
|
||||
>>> import to_python_converter
|
||||
>>> def always_none():
|
||||
@@ -180,10 +192,13 @@ BOOST_PYTHON_MODULE_INIT(to_python_converter)
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
29 September, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
<p><i>© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
||||
Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user