2
0
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:
Dave Abrahams
2002-09-29 20:40:33 +00:00
parent 170bbea166
commit 19982e5551
6 changed files with 153 additions and 122 deletions

View File

@@ -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_&lt;WrappedClass&gt;::def_init(args&lt;</code><i>type-sequence...</i>
<code>&gt;())</code>, there exists a corresponding constructor
<code>class_&lt;WrappedClass&gt;::def(init&lt;</code><i>type-sequence...</i><code>
&gt;())</code>, there exists a corresponding constructor
<code>WrappedClass::WrappedClass(PyObject*,&nbsp;</code><i>type-sequence...</i>
<code>)</code>. If such a specialization exists, the
<code>WrappedClass</code> constructors will be called with a "back

View File

@@ -116,7 +116,7 @@ using namespace boost::python;
BOOST_PYTHON_MODULE_INIT(my_module)
{
def("make_foo", make_foo, return_value_policy&lt;manage_new_object&gt;())
class_&lt;Foo&gt;()
class_&lt;Foo&gt;("Foo")
.def("get_x", &amp;Foo::get_x)
;
}

View File

@@ -144,7 +144,7 @@ using namespace boost::python;
BOOST_PYTHON_MODULE_INIT(singleton)
{
def("get_it", get_it, reference_existing_object());
class_&lt;Singleton&gt;()
class_&lt;Singleton&gt;("Singleton")
.def("exchange", &amp;Singleton::exchange)
;
}

View File

@@ -186,13 +186,12 @@ class Foo
using namespace boost::python;
BOOST_PYTHON_MODULE_INIT(internal_refs)
{
class_&lt;Bar&gt;()
class_&lt;Bar&gt;("Bar")
.def("get_x", &amp;Bar::get_x)
.def("set_x", &amp;Bar::set_x)
;
class_&lt;Foo&gt;()
.def_init(args&lt;int&gt;())
class_&lt;Foo&gt;("Foo", init&lt;int&gt;())
.def("get_bar", &amp;Foo::get_bar
, return_internal_reference&lt;&gt;())
;

View File

@@ -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 - &lt;boost/python/return_value_policy.hpp&gt;</title>
<title>Boost.Python -
&lt;boost/python/return_value_policy.hpp&gt;</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 &lt;boost/python/return_value_policy.hpp&gt;</h2>
<h2 align="center">Header
&lt;boost/python/return_value_policy.hpp&gt;</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 &lt;boost/python/module.hpp&gt;
#include &lt;boost/python/module_init.hpp&gt;
#include &lt;boost/python/class.hpp&gt;
#include &lt;boost/python/copy_const_reference.hpp&gt;
#include &lt;boost/python/return_value_policy.hpp&gt;
@@ -118,20 +135,16 @@ struct Foo {
using namespace boost::python;
BOOST_PYTHON_MODULE_INIT(my_module)
{
module("my_module")
.add(
class_&lt;Bar&gt;()
)
.add(
class_&lt;Foo&gt;()
.def_init(args&lt;int&gt;())
.def("get_bar", &amp;Foo::get_bar
, return_value_policy&lt;copy_const_reference&gt;())
)
;
class_&lt;Bar&gt;("Bar");
class_&lt;Foo&gt;("Foo", init&lt;int&gt;())
.def("get_bar", &amp;Foo::get_bar
, return_value_policy&lt;copy_const_reference&gt;())
;
}
</pre>
<h3>Python Code</h3>
<h3>Python Code</h3>
<pre>
&gt;&gt;&gt; from my_module import *
&gt;&gt;&gt; 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>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. All Rights Reserved.</i>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
</body>
</html>

View File

@@ -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 - &lt;boost/python/to_python_converter.hpp&gt;</title>
<title>Boost.Python -
&lt;boost/python/to_python_converter.hpp&gt;</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 &lt;boost/python/to_python_converter.hpp&gt;</h2>
<h2 align="center">Header
&lt;boost/python/to_python_converter.hpp&gt;</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*&nbsp;p&nbsp;=&nbsp;Conversion::convert(x)</code>,<br>
if <code>p&nbsp;==&nbsp;0</code>, <code><a href="http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>()&nbsp;!=&nbsp;0</code>.
<td>
<code>PyObject*&nbsp;p&nbsp;=&nbsp;Conversion::convert(x)</code>,<br>
if <code>p&nbsp;==&nbsp;0</code>, <code><a href=
"http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>()&nbsp;!=&nbsp;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>&quot;noddy.h&quot;</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 &lt;boost/python/reference.hpp&gt;
#include &lt;boost/python/module.hpp&gt;
#include &quot;noddy.h&quot;
#include &lt;boost/python/module_init.hpp&gt;
#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(&quot;to_python_converter&quot;)
.def(&quot;make_tag&quot;, make_tag)
;
def("make_tag", make_tag);
to_python_converter&lt;tag, tag_to_noddy&gt;();
}
</pre>
<h3>Python code</h3>
<h3>Python code</h3>
<pre>
&gt;&gt;&gt; import to_python_converter
&gt;&gt;&gt; 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>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. All Rights Reserved.</i>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
</body>
</html>