[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,261 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;1.&#160;Concepts</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="index.html" title="Boost.Python Reference Manual">
<link rel="next" href="concepts/dereferenceable.html" title="Dereferenceable">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="concepts/dereferenceable.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="concepts"></a>Chapter&#160;1.&#160;Concepts</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="concepts.html#concepts.callpolicies">CallPolicies</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.callpolicies_composition">CallPolicies
Composition</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/dereferenceable.html">Dereferenceable</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/extractor.html">Extractor</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.concept_requirements">Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.notes">Notes</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/holdergenerator.html">HolderGenerator</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/resultconverter.html">ResultConverter</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconverter_concept_requirem">ResultConverter
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept">ResultConverterGenerator
Concept Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/objectwrapper.html">ObjectWrapper</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen">ObjectWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements">TypeWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.caveat">Caveat</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.callpolicies"></a><a class="link" href="concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.callpolicies_composition">CallPolicies
Composition</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.concept_requirements">Concept
Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.introduction"></a><a class="link" href="concepts.html#concepts.callpolicies.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Models of the CallPolicies concept are used to specialize the behavior
of Python callable objects generated by Boost.Python to wrapped C++ objects
like function and member function pointers, providing three behaviors:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="computeroutput"><span class="identifier">precall</span></code> - Python argument
tuple management before the wrapped object is invoked
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">result_converter</span></code> -
C++ return value handling
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">postcall</span></code> - Python argument
tuple and result management after the wrapped object is invoked
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">extract_return_type</span></code>
- metafunction for extracting the return type from a given signature
type sequence
</li>
</ol></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.callpolicies_composition"></a><a class="link" href="concepts.html#concepts.callpolicies.callpolicies_composition" title="CallPolicies Composition">CallPolicies
Composition</a>
</h3></div></div></div>
<p>
In order to allow the use of multiple models of CallPolicies in the same
callable object, Boost.Python's CallPolicies class templates provide a
chaining interface which allows them to be recursively composed. This interface
takes the form of an optional template parameter, <code class="computeroutput"><span class="identifier">Base</span></code>,
which defaults to <code class="computeroutput"><span class="identifier">default_call_policies</span></code>.
By convention, the <code class="computeroutput"><span class="identifier">precall</span></code>
function of the <code class="computeroutput"><span class="identifier">Base</span></code> is
invoked after the <code class="computeroutput"><span class="identifier">precall</span></code>
function supplied by the <code class="computeroutput"><span class="identifier">outer</span></code>
template, and the <code class="computeroutput"><span class="identifier">postcall</span></code>
function of the <code class="computeroutput"><span class="identifier">Base</span></code> is
invoked before the <code class="computeroutput"><span class="identifier">postcall</span></code>
function of the <code class="computeroutput"><span class="identifier">outer</span></code> template.
If a <code class="computeroutput"><span class="identifier">result_converter</span></code> is
supplied by the <code class="computeroutput"><span class="identifier">outer</span></code> template,
it replaces any <code class="computeroutput"><span class="identifier">result_converter</span></code>
supplied by the <code class="computeroutput"><span class="identifier">Base</span></code>. For
an example, see <code class="computeroutput"><span class="identifier">return_internal_reference</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.concept_requirements"></a><a class="link" href="concepts.html#concepts.callpolicies.concept_requirements" title="Concept Requirements">Concept
Requirements</a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
<th>
<p>
Result/Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">precall</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="keyword">bool</span></code>
</p>
</td>
<td>
<p>
returns <code class="computeroutput"><span class="keyword">false</span></code> and
<code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span> <span class="special">!=</span>
<span class="number">0</span></code> upon failure, <code class="computeroutput"><span class="keyword">true</span></code> otherwise.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">P</span><span class="special">::</span><span class="identifier">result_converter</span></code>
</p>
</td>
<td>
<p>
A model of <code class="computeroutput"><span class="identifier">ResultConverterGenerator</span></code>.
</p>
</td>
<td>
<p>
An MPL unary Metafunction Class used produce the "preliminary"
result object.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">postcall</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
<span class="identifier">r</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">0</span></code> and <code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span>
<span class="special">!=</span> <span class="number">0</span></code>
upon failure. Must "conserve references" even in the
event of an exception. In other words, if <code class="computeroutput"><span class="identifier">r</span></code>
is not returned, its reference count must be decremented; if
another existing object is returned, its reference count must
be incremented.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">P</span><span class="special">::</span><span class="identifier">extract_return_type</span></code>
</p>
</td>
<td>
<p>
A model of Metafunction.
</p>
</td>
<td>
<p>
An MPL unary Metafunction used extract the return type from a
given signature. By default it is derived from <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">front</span></code>.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="concepts/dereferenceable.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,104 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Dereferenceable</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="next" href="extractor.html" title="Extractor">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../concepts.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="extractor.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.dereferenceable"></a><a class="link" href="dereferenceable.html" title="Dereferenceable">Dereferenceable</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="dereferenceable.html#concepts.dereferenceable.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="dereferenceable.html#concepts.dereferenceable.concept_requirements">Concept
Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.dereferenceable.introduction"></a><a class="link" href="dereferenceable.html#concepts.dereferenceable.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Instances of a <code class="computeroutput"><span class="identifier">Dereferenceable</span></code>
type can be used like a pointer to access an lvalue.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.dereferenceable.concept_requirements"></a><a class="link" href="dereferenceable.html#concepts.dereferenceable.concept_requirements" title="Concept Requirements">Concept
Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">T</span></code> is
a model of Dereferenceable, and <code class="computeroutput"><span class="identifier">x</span></code>
denotes an object of type <code class="computeroutput"><span class="identifier">T</span></code>.
In addition, all pointers are <code class="computeroutput"><span class="identifier">Dereferenceable</span></code>.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Result
</p>
</th>
<th>
<p>
Operational Semantics
</p>
</th>
</tr></thead>
<tbody><tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_pointer</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">*</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">&amp;*</span><span class="identifier">x</span></code>,
or a null pointer
</p>
</td>
</tr></tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../concepts.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="extractor.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,135 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Extractor</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="dereferenceable.html" title="Dereferenceable">
<link rel="next" href="holdergenerator.html" title="HolderGenerator">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="dereferenceable.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="holdergenerator.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.extractor"></a><a class="link" href="extractor.html" title="Extractor">Extractor</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="extractor.html#concepts.extractor.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="extractor.html#concepts.extractor.concept_requirements">Concept Requirements</a></span></dt>
<dt><span class="section"><a href="extractor.html#concepts.extractor.notes">Notes</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.introduction"></a><a class="link" href="extractor.html#concepts.extractor.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
An Extractor is a class which Boost.Python can use to extract C++ objects
from Python objects, and is typically used by facilities that define <code class="computeroutput"><span class="identifier">from_python</span></code> conversions for "traditional"
Python extension types.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.concept_requirements"></a><a class="link" href="extractor.html#concepts.extractor.concept_requirements" title="Concept Requirements">Concept Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">X</span></code> denotes
a model of <code class="computeroutput"><span class="identifier">Extractor</span></code> and
<code class="computeroutput"><span class="identifier">a</span></code> denotes an instance of
a Python object type.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">X</span><span class="special">::</span><span class="identifier">execute</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
non-void
</p>
</td>
<td>
<p>
Returns the C++ object being extracted. The execute function
must not be overloaded.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">&amp;</span><span class="identifier">a</span><span class="special">.</span><span class="identifier">ob_type</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">PyTypeObject</span><span class="special">**</span></code>
</p>
</td>
<td>
<p>
Points to the <code class="computeroutput"><span class="identifier">ob_type</span></code>
field of an object which is layout-compatible with <code class="computeroutput"><span class="identifier">PyObject</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.notes"></a><a class="link" href="extractor.html#concepts.extractor.notes" title="Notes">Notes</a>
</h3></div></div></div>
<p>
Informally, an Extractor's execute member must be a non-overloaded static
function whose single argument is a Python object type. Acceptable Python
object types include those publicly (and unambiguously) derived from PyObject,
and POD types which are layout-compatible with PyObject.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="dereferenceable.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="holdergenerator.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,92 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>HolderGenerator</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="extractor.html" title="Extractor">
<link rel="next" href="resultconverter.html" title="ResultConverter">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="extractor.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="resultconverter.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.holdergenerator"></a><a class="link" href="holdergenerator.html" title="HolderGenerator">HolderGenerator</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="holdergenerator.html#concepts.holdergenerator.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="holdergenerator.html#concepts.holdergenerator.concept_requirements">Concept
Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.holdergenerator.introduction"></a><a class="link" href="holdergenerator.html#concepts.holdergenerator.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
A HolderGenerator is a unary metafunction class which returns types suitable
for holding instances of its argument in a wrapped C++ class instance.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.holdergenerator.concept_requirements"></a><a class="link" href="holdergenerator.html#concepts.holdergenerator.concept_requirements" title="Concept Requirements">Concept
Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">G</span></code> denotes
an type which models <code class="computeroutput"><span class="identifier">HolderGenerator</span></code>,
and <code class="computeroutput"><span class="identifier">X</span></code> denotes a class type.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
</tr></thead>
<tbody><tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">G</span><span class="special">::</span><span class="identifier">apply</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
</p>
</td>
<td>
<p>
A concrete subclass of <code class="computeroutput"><span class="identifier">instance_holder</span></code>
which can hold objects of type <code class="computeroutput"><span class="identifier">X</span></code>.
</p>
</td>
</tr></tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="extractor.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="resultconverter.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,132 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>ObjectWrapper</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="resultconverter.html" title="ResultConverter">
<link rel="next" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="resultconverter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../high_level_components.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.objectwrapper"></a><a class="link" href="objectwrapper.html" title="ObjectWrapper">ObjectWrapper</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="objectwrapper.html#concepts.objectwrapper.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen">ObjectWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements">TypeWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="objectwrapper.html#concepts.objectwrapper.caveat">Caveat</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.objectwrapper.introduction"></a><a class="link" href="objectwrapper.html#concepts.objectwrapper.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
This page defines two concepts used to describe classes which manage a
Python objects, and which are intended to support usage with a Python-like
syntax.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.objectwrapper.objectwrapper_concept_requiremen"></a><a class="link" href="objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen" title="ObjectWrapper Concept Requirements">ObjectWrapper
Concept Requirements</a>
</h3></div></div></div>
<p>
Models of the ObjectWrapper concept have <a class="link" href="../object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object">object</a>
as a publicly-accessible base class, and are used to supply special construction
behavior and/or additional convenient functionality through (often templated)
member functions. Except when the return type R is itself an <a class="link" href="objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>,
a member function invocation of the form
</p>
<pre class="programlisting"><span class="identifier">x</span><span class="special">.</span><span class="identifier">some_function</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,...</span><span class="identifier">an</span><span class="special">)</span></pre>
<p>
always has semantics equivalent to:
</p>
<pre class="programlisting"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">R</span><span class="special">&gt;(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"some_function"</span><span class="special">)(</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">a1</span><span class="special">),</span> <span class="identifier">object</span><span class="special">(</span><span class="identifier">a2</span><span class="special">),...</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">an</span><span class="special">)))()</span></pre>
<p>
(see <a class="link" href="objectwrapper.html#concepts.objectwrapper.caveat" title="Caveat">caveat</a> below).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.objectwrapper.typewrapper_concept_requirements"></a><a class="link" href="objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper
Concept Requirements</a>
</h3></div></div></div>
<p>
TypeWrapper is a refinement of <a class="link" href="objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen" title="ObjectWrapper Concept Requirements">ObjectWrapper</a>
which is associated with a particular Python type <code class="computeroutput"><span class="identifier">X</span></code>.
For a given TypeWrapper <code class="computeroutput"><span class="identifier">T</span></code>,
a valid constructor expression
</p>
<pre class="programlisting"><span class="identifier">T</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,...</span><span class="identifier">an</span><span class="special">)</span></pre>
<p>
builds a new T object managing the result of invoking X with arguments
corresponding to
</p>
<pre class="programlisting"><span class="identifier">object</span><span class="special">(</span><span class="identifier">a1</span><span class="special">),</span> <span class="identifier">object</span><span class="special">(</span><span class="identifier">a2</span><span class="special">),...</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">an</span><span class="special">)</span></pre>
<p>
. When used as arguments to wrapped C++ functions, or as the template parameter
to <a class="link" href="../to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract" title="Class template extract">extract&lt;&gt;</a>,
only instances of the associated Python type will be considered a match.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.objectwrapper.caveat"></a><a class="link" href="objectwrapper.html#concepts.objectwrapper.caveat" title="Caveat">Caveat</a>
</h3></div></div></div>
<p>
The upshot of the special member function invocation rules when the return
type is a TypeWrapper is that it is possible for the returned object to
manage a Python object of an inappropriate type. This is not usually a
serious problem; the worst-case result is that errors will be detected
at runtime a little later than they might otherwise be. For an example
of how this can occur, note that the <a class="link" href="../object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict" title="Class dict">dict</a>
member function <code class="computeroutput"><span class="identifier">items</span></code> returns
an object of type <a class="link" href="../object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list" title="Class list">list</a>.
Now suppose the user defines this <code class="computeroutput"><span class="identifier">dict</span></code>
subclass in Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">mydict</span><span class="special">(</span><span class="identifier">dict</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">def</span> <span class="identifier">items</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="identifier">tuple</span><span class="special">(</span><span class="identifier">dict</span><span class="special">.</span><span class="identifier">items</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span> <span class="special">#</span> <span class="keyword">return</span> <span class="identifier">a</span> <span class="identifier">tuple</span>
</pre>
<p>
Since an instance of <code class="computeroutput"><span class="identifier">mydict</span></code>
is also an instance of <code class="computeroutput"><span class="identifier">dict</span></code>,
when used as an argument to a wrapped C++ function, <a class="link" href="../object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict" title="Class dict">boost::python::dict</a>
can accept objects of Python type <code class="computeroutput"><span class="identifier">mydict</span></code>.
Invoking <code class="computeroutput"><span class="identifier">items</span><span class="special">()</span></code>
on this object can result in an instance of <a class="link" href="../object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list" title="Class list">boost::python::list</a>
which actually holds a Python <code class="computeroutput"><span class="identifier">tuple</span></code>.
Subsequent attempts to use <code class="computeroutput"><span class="identifier">list</span></code>
methods (e.g. <code class="computeroutput"><span class="identifier">append</span></code>, or
any other mutating operation) on this object will raise the same exception
that would occur if you tried to do it from Python.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="resultconverter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../high_level_components.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,210 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>ResultConverter</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="holdergenerator.html" title="HolderGenerator">
<link rel="next" href="objectwrapper.html" title="ObjectWrapper">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="holdergenerator.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="objectwrapper.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.resultconverter"></a><a class="link" href="resultconverter.html" title="ResultConverter">ResultConverter</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="resultconverter.html#concepts.resultconverter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="resultconverter.html#concepts.resultconverter.resultconverter_concept_requirem">ResultConverter
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept">ResultConverterGenerator
Concept Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.resultconverter.introduction"></a><a class="link" href="resultconverter.html#concepts.resultconverter.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
A ResultConverter for a type <code class="computeroutput"><span class="identifier">T</span></code>
is a type whose instances can be used to convert C++ return values of type
<code class="computeroutput"><span class="identifier">T</span></code> <code class="computeroutput"><span class="identifier">to_python</span></code>.
A ResultConverterGenerator is an MPL unary metafunction class which, given
the return type of a C++ function, returns a ResultConverter for that type.
ResultConverters in Boost.Python generally inspect library's registry of
converters to find a suitable converter, but converters which don't use
the registry are also possible.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.resultconverter.resultconverter_concept_requirem"></a><a class="link" href="resultconverter.html#concepts.resultconverter.resultconverter_concept_requirem" title="ResultConverter Concept Requirements">ResultConverter
Concept Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">C</span></code> denotes
a ResultConverter type for a type <code class="computeroutput"><span class="identifier">R</span></code>,
<code class="computeroutput"><span class="identifier">c</span></code> denotes an object of
type <code class="computeroutput"><span class="identifier">C</span></code>, and <code class="computeroutput"><span class="identifier">r</span></code> denotes an object of type <code class="computeroutput"><span class="identifier">R</span></code>.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">C</span> <span class="identifier">c</span></code>
</p>
</td>
<td>
</td>
<td>
<p>
Constructs a <code class="computeroutput"><span class="identifier">c</span></code>
object.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">c</span><span class="special">.</span><span class="identifier">convertible</span><span class="special">()</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="keyword">bool</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">false</span></code> iff no conversion
from any <code class="computeroutput"><span class="identifier">R</span></code> value
to a Python object is possible.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">c</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
</p>
</td>
<td>
<p>
A pointer to a Python object corresponding to <code class="computeroutput"><span class="identifier">r</span></code>,
or <code class="computeroutput"><span class="number">0</span></code> iff <code class="computeroutput"><span class="identifier">r</span></code> could not be converted <code class="computeroutput"><span class="identifier">to_python</span></code>, in which case <code class="computeroutput"><span class="identifier">PyErr_Occurred</span></code> should return
non-zero.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">c</span><span class="special">.</span><span class="identifier">get_pytype</span><span class="special">()</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span></code>
</p>
</td>
<td>
<p>
A pointer to a Python Type object corresponding to result of
the conversion, or <code class="computeroutput"><span class="number">0</span></code>.
Used for documentation generation. If <code class="computeroutput"><span class="number">0</span></code>
is returned the generated type in the documentation will be object.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.resultconverter.resultconvertergenerator_concept"></a><a class="link" href="resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator
Concept Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">G</span></code> denotes
a ResultConverterGenerator type and <code class="computeroutput"><span class="identifier">R</span></code>
denotes a possible C++ function return type.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
</tr></thead>
<tbody><tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">G</span><span class="special">::</span><span class="identifier">apply</span><span class="special">&lt;</span><span class="identifier">R</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
</p>
</td>
<td>
<p>
A ResultConverter type for <code class="computeroutput"><span class="identifier">R</span></code>.
</p>
</td>
</tr></tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="holdergenerator.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="objectwrapper.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,205 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;6.&#160;Embedding</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html" title="boost/python/register_ptr_to_python.hpp">
<link rel="next" href="embedding/boost_python_import_hpp.html" title="boost/python/import.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="embedding/boost_python_import_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="embedding"></a>Chapter&#160;6.&#160;Embedding</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp">boost/python/exec.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_eval">Function
<code class="computeroutput"><span class="identifier">eval</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec">Function
<code class="computeroutput"><span class="identifier">exec</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec_file">Function
<code class="computeroutput"><span class="identifier">exec_file</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html">boost/python/import.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.function_import">Function
<code class="computeroutput"><span class="identifier">import</span></code></a></span></dt>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.examples">Examples</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="embedding.boost_python_exec_hpp"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp" title="boost/python/exec.hpp">boost/python/exec.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_eval">Function
<code class="computeroutput"><span class="identifier">eval</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec">Function
<code class="computeroutput"><span class="identifier">exec</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec_file">Function
<code class="computeroutput"><span class="identifier">exec_file</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_exec_hpp.introduction"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a mechanism for embedding the python interpreter into C++ code.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_exec_hpp.function_eval"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp.function_eval" title="Function eval">Function
<code class="computeroutput"><span class="identifier">eval</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">eval</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">expression</span><span class="special">,</span>
<span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span>
<span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">());</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Evaluate Python expression from expression in the context specified
by the dictionaries globals and locals.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the value of the expression.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_exec_hpp.function_exec"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp.function_exec" title="Function exec">Function
<code class="computeroutput"><span class="identifier">exec</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">exec</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">code</span><span class="special">,</span>
<span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span>
<span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">());</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Execute Python source code from code in the context specified by
the dictionaries globals and locals.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the result of executing the code.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_exec_hpp.function_exec_file"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp.function_exec_file" title="Function exec_file">Function
<code class="computeroutput"><span class="identifier">exec_file</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">exec_file</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">filename</span><span class="special">,</span>
<span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span>
<span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">());</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Execute Python source code from the file named by filename in the
context specified by the dictionaries globals and locals.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the result of executing the code.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_exec_hpp.examples"></a><a class="link" href="embedding.html#embedding.boost_python_exec_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
The following example demonstrates the use of import and exec to define
a function in python, and later call it from within C++.
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">greet</span><span class="special">()</span>
<span class="special">{</span>
<span class="comment">// Retrieve the main module.</span>
<span class="identifier">object</span> <span class="identifier">main</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"__main__"</span><span class="special">);</span>
<span class="comment">// Retrieve the main module's namespace</span>
<span class="identifier">object</span> <span class="identifier">global</span><span class="special">(</span><span class="identifier">main</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span>
<span class="comment">// Define greet function in Python.</span>
<span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">exec</span><span class="special">(</span>
<span class="string">"def greet(): \n"</span>
<span class="string">" return 'Hello from Python!' \n"</span><span class="special">,</span>
<span class="identifier">global</span><span class="special">,</span> <span class="identifier">global</span><span class="special">);</span>
<span class="comment">// Create a reference to it.</span>
<span class="identifier">object</span> <span class="identifier">greet</span> <span class="special">=</span> <span class="identifier">global</span><span class="special">[</span><span class="string">"greet"</span><span class="special">];</span>
<span class="comment">// Call it.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">message</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">greet</span><span class="special">());</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">message</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Instead of embedding the python script into a string, we could also store
it in an a file...
</p>
<pre class="programlisting"><span class="identifier">def</span> <span class="identifier">greet</span><span class="special">():</span>
<span class="keyword">return</span> <span class="char">'Hello from Python!'</span>
</pre>
<p>
... and execute that instead.
</p>
<pre class="programlisting"> <span class="comment">// ...</span>
<span class="comment">// Load the greet function from a file.</span>
<span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">exec_file</span><span class="special">(</span><span class="identifier">script</span><span class="special">,</span> <span class="identifier">global</span><span class="special">,</span> <span class="identifier">global</span><span class="special">);</span>
<span class="comment">// ...</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="embedding/boost_python_import_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,94 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/import.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../embedding.html" title="Chapter&#160;6.&#160;Embedding">
<link rel="prev" href="../embedding.html" title="Chapter&#160;6.&#160;Embedding">
<link rel="next" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../embedding.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../embedding.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../utility_and_infrastructure.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="embedding.boost_python_import_hpp"></a><a class="link" href="boost_python_import_hpp.html" title="boost/python/import.hpp">boost/python/import.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.function_import">Function
<code class="computeroutput"><span class="identifier">import</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_import_hpp.introduction"></a><a class="link" href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a mechanism for importing python modules.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_import_hpp.function_import"></a><a class="link" href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.function_import" title="Function import">Function
<code class="computeroutput"><span class="identifier">import</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">import</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Imports the module named by name.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds a reference to the imported module.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="embedding.boost_python_import_hpp.examples"></a><a class="link" href="boost_python_import_hpp.html#embedding.boost_python_import_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
The following example demonstrates the use of import to access a function
in python, and later call it from within C++.
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">print_python_version</span><span class="special">()</span>
<span class="special">{</span>
<span class="comment">// Load the sys module.</span>
<span class="identifier">object</span> <span class="identifier">sys</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"sys"</span><span class="special">);</span>
<span class="comment">// Extract the python version.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">version</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">sys</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"version"</span><span class="special">));</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">version</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../embedding.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../embedding.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../utility_and_infrastructure.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,287 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;4.&#160;Function Invocation and Creation</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="object_wrappers/boost_python_tuple_hpp.html" title="boost/python/tuple.hpp">
<link rel="next" href="function_invocation_and_creation/boost_python_call_hpp.html" title="boost/python/call.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="object_wrappers/boost_python_tuple_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="function_invocation_and_creation/boost_python_call_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="function_invocation_and_creation"></a>Chapter&#160;4.&#160;Function Invocation and Creation</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp">boost/python/args.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg">Class
<code class="computeroutput"><span class="identifier">arg</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_constructor">Class
<code class="computeroutput"><span class="identifier">arg</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_operator">Class
<code class="computeroutput"><span class="identifier">arg</span></code> operator=</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.keyword_expression_operator">Keyword-expression
operator,</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html">boost/python/call.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call">Function
<code class="computeroutput"><span class="identifier">call</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html">boost/python/call_method.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.function_call_method">Function
<code class="computeroutput"><span class="identifier">call_method</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html">boost/python/data_members.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html">boost/python/make_function.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html">boost/python/overloads.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.overloaddispatcher_concept">OverloadDispatcher
Concept</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html">boost/python/ptr.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_t">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
types</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_c">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
constructors and destructor</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_o">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
observer functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions">Metafunctions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html">boost/python/raw_function.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function">Function
<code class="computeroutput"><span class="identifier">raw_function</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html">Function
documentation</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat">boost/python/function_doc_signature.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp">boost/python/pytype_function.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html">Models
of CallPolicies</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_default_call_polici">boost/python/default_call_policies.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_arg_hpp">boost/python/return_arg.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_internal_ref">boost/python/return_internal_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_value_policy">boost/python/return_value_policy.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_with_custodian_and_">boost/python/with_custodian_and_ward.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html">Models
of ResultConverter</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_">boost/python/to_python_indirect.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp">boost/python/to_python_value.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html">Models
of ResultConverterGenerator</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc">boost/python/copy_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe">boost/python/copy_non_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h">boost/python/manage_new_object.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_">boost/python/reference_existing_object.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp">boost/python/return_by_value.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point">boost/python/return_opaque_pointer.hpp</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_args_hpp"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp" title="boost/python/args.hpp">boost/python/args.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg">Class
<code class="computeroutput"><span class="identifier">arg</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_constructor">Class
<code class="computeroutput"><span class="identifier">arg</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_operator">Class
<code class="computeroutput"><span class="identifier">arg</span></code> operator=</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.keyword_expression_operator">Keyword-expression
operator,</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.introduction"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions">keyword-expressions</a></span></dt></dl></div>
<p>
Supplies a family of overloaded functions for specifying argument keywords
for wrapped C++ functions.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expressions</a>
</h4></div></div></div>
<p>
A keyword-expression results in an object which holds a sequence of
<a class="link" href="glossary.html#ntbs">ntbs</a>es, and whose type encodes the number
of keywords specified. The keyword-expression may contain default values
for some or all of the keywords it holds
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.class_arg"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg" title="Class arg">Class
<code class="computeroutput"><span class="identifier">arg</span></code></a>
</h3></div></div></div>
<p>
The objects of class arg are keyword-expressions holding one keyword (
size one )
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">arg</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">arg</span> <span class="special">&amp;</span><span class="keyword">operator</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">value</span><span class="special">);</span>
<span class="keyword">explicit</span> <span class="identifier">arg</span> <span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">name</span><span class="special">){</span><span class="identifier">elements</span><span class="special">[</span><span class="number">0</span><span class="special">].</span><span class="identifier">name</span> <span class="special">=</span> <span class="identifier">name</span><span class="special">;}</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.class_arg_constructor"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_constructor" title="Class arg constructor">Class
<code class="computeroutput"><span class="identifier">arg</span></code> constructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">arg</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The argument must be a <a class="link" href="glossary.html#ntbs">ntbs</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Constructs an arg object holding a keyword with name name.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.class_arg_operator"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_operator" title="Class arg operator=">Class
<code class="computeroutput"><span class="identifier">arg</span></code> operator=</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">arg</span> <span class="special">&amp;</span><span class="keyword">operator</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">value</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The argument must convertible to python.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Assigns default value for the keyword.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
Reference to <code class="computeroutput"><span class="keyword">this</span></code>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.keyword_expression_operator"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.keyword_expression_operator" title="Keyword-expression operator,">Keyword-expression
operator,</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">keyword</span><span class="special">-</span><span class="identifier">expression</span> <span class="keyword">operator</span> <span class="special">,</span> <span class="special">(</span><span class="identifier">keyword</span><span class="special">-</span><span class="identifier">expression</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">arg</span> <span class="special">&amp;</span><span class="identifier">kw</span><span class="special">)</span> <span class="keyword">const</span>
<span class="identifier">keyword</span><span class="special">-</span><span class="identifier">expression</span> <span class="keyword">operator</span> <span class="special">,</span> <span class="special">(</span><span class="identifier">keyword</span><span class="special">-</span><span class="identifier">expression</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">name</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The argument name must be a <a class="link" href="glossary.html#ntbs">ntbs</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Extends the keyword-expression argument with one more keyword.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
The extended keyword-expression.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_args_hpp.example"></a><a class="link" href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">z</span><span class="special">=</span><span class="number">0.0</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">w</span><span class="special">=</span><span class="number">1.0</span><span class="special">);</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">xxx</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="special">(</span><span class="identifier">arg</span><span class="special">(</span><span class="string">"x"</span><span class="special">),</span> <span class="string">"y"</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"z"</span><span class="special">)=</span><span class="number">0.0</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"w"</span><span class="special">)=</span><span class="number">1.0</span><span class="special">));</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="object_wrappers/boost_python_tuple_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="function_invocation_and_creation/boost_python_call_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,96 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/call.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="next" href="boost_python_call_method_hpp.html" title="boost/python/call_method.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function_invocation_and_creation.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_call_method_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_call_hpp"></a><a class="link" href="boost_python_call_hpp.html" title="boost/python/call.hpp">boost/python/call.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call">Function
<code class="computeroutput"><span class="identifier">call</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.introduction"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<pre class="programlisting"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">call</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="identifier">defines</span> <span class="identifier">the</span> <span class="identifier">call</span> <span class="identifier">family</span> <span class="identifier">of</span> <span class="identifier">overloaded</span> <span class="identifier">function</span> <span class="identifier">templates</span><span class="special">,</span> <span class="identifier">used</span> <span class="identifier">to</span> <span class="identifier">invoke</span> <span class="identifier">Python</span> <span class="identifier">callable</span> <span class="identifier">objects</span> <span class="identifier">from</span> <span class="identifier">C</span><span class="special">++.</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.function_call"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call" title="Function call">Function
<code class="computeroutput"><span class="identifier">call</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="special">...</span> <span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">R</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">callable</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="special">...</span> <span class="identifier">An</span> <span class="keyword">const</span><span class="special">&amp;)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
R is a pointer type, reference type, or a complete type with an accessible
copy constructor
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Invokes callable(a1, a2, ...an) in Python, where a1...an are the
arguments to call(), converted to Python objects.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
The result of the Python call, converted to the C++ type R.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
For a complete semantic description and rationale, see this page.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.example"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
The following C++ function applies a Python callable object to its two
arguments and returns the result. If a Python exception is raised or the
result can't be converted to a double, an exception is thrown.
</p>
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">apply2</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">func</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">func</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function_invocation_and_creation.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_call_method_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,156 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/call_method.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_call_hpp.html" title="boost/python/call.hpp">
<link rel="next" href="boost_python_data_members_hpp.html" title="boost/python/data_members.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_call_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_data_members_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_call_method_hpp"></a><a class="link" href="boost_python_call_method_hpp.html" title="boost/python/call_method.hpp">boost/python/call_method.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.function_call_method">Function
<code class="computeroutput"><span class="identifier">call_method</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_method_hpp.introduction"></a><a class="link" href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/call_method.hpp&gt; defines the call_method family of
overloaded function templates, used to invoke callable attributes of Python
objects from C++.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_method_hpp.function_call_method"></a><a class="link" href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.function_call_method" title="Function call_method">Function
<code class="computeroutput"><span class="identifier">call_method</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="special">...</span> <span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">R</span> <span class="identifier">call_method</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">method</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="special">...</span> <span class="identifier">An</span> <span class="keyword">const</span><span class="special">&amp;)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">R</span></code> is a pointer type,
reference type, or a complete type with an accessible copy constructor
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Invokes <code class="computeroutput"><span class="identifier">self</span><span class="special">.</span><span class="identifier">method</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span> <span class="special">...</span><span class="identifier">an</span><span class="special">)</span></code> in Python, where <code class="computeroutput"><span class="identifier">a1</span><span class="special">...</span><span class="identifier">an</span></code>
are the arguments to <code class="computeroutput"><span class="identifier">call_method</span><span class="special">()</span></code>, converted to Python objects. For
a complete semantic description, see this page.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
The result of the Python call, converted to the C++ type <code class="computeroutput"><span class="identifier">R</span></code>.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">call_method</span></code> is critical
to implementing C++ virtual functions which are overridable in Python,
as shown by the example below.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_method_hpp.example"></a><a class="link" href="boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
The following C++ illustrates the use of <code class="computeroutput"><span class="identifier">call_method</span></code>
in wrapping a class with a virtual function that can be overridden in Python:
C++ Module Definition
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstring</span><span class="special">&gt;</span>
<span class="comment">// class to be wrapped</span>
<span class="keyword">class</span> <span class="identifier">Base</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">virtual</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">class_name</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"Base"</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">Base</span><span class="special">();</span>
<span class="special">};</span>
<span class="keyword">bool</span> <span class="identifier">is_base</span><span class="special">(</span><span class="identifier">Base</span><span class="special">*</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="special">!</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">strcmp</span><span class="special">(</span><span class="identifier">b</span><span class="special">-&gt;</span><span class="identifier">class_name</span><span class="special">(),</span> <span class="string">"Base"</span><span class="special">);</span>
<span class="special">}</span>
<span class="comment">// Wrapper code begins here</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// Callback class</span>
<span class="keyword">class</span> <span class="identifier">Base_callback</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Base</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">Base_callback</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_self</span><span class="special">(</span><span class="identifier">self</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">class_name</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">call_method</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">m_self</span><span class="special">,</span> <span class="string">"class_name"</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">Base_name</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">Base</span><span class="special">::</span><span class="identifier">class_name</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="keyword">const</span> <span class="identifier">m_self</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"is_base"</span><span class="special">,</span> <span class="identifier">is_base</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">,</span><span class="identifier">Base_callback</span><span class="special">,</span> <span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"class_name"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Base_callback</span><span class="special">::</span><span class="identifier">Base_name</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_module</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">(</span><span class="identifier">Base</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">def</span> <span class="identifier">__init__</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">Base</span><span class="special">.</span><span class="identifier">__init__</span><span class="special">(</span><span class="identifier">self</span><span class="special">)</span>
<span class="special">...</span> <span class="identifier">def</span> <span class="identifier">class_name</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="identifier">self</span><span class="special">.</span><span class="identifier">__class__</span><span class="special">.</span><span class="identifier">__name__</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">is_base</span><span class="special">(</span><span class="identifier">Base</span><span class="special">())</span> <span class="special">#</span> <span class="identifier">calls</span> <span class="identifier">the</span> <span class="identifier">class_name</span><span class="special">()</span> <span class="identifier">method</span> <span class="identifier">from</span> <span class="identifier">C</span><span class="special">++</span>
<span class="number">1</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">is_base</span><span class="special">(</span><span class="identifier">Derived</span><span class="special">())</span>
<span class="number">0</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_call_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_data_members_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,215 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/data_members.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_call_method_hpp.html" title="boost/python/call_method.hpp">
<link rel="next" href="boost_python_make_function_hpp.html" title="boost/python/make_function.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_call_method_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_make_function_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_data_members_hpp"></a><a class="link" href="boost_python_data_members_hpp.html" title="boost/python/data_members.hpp">boost/python/data_members.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_data_members_hpp.introduction"></a><a class="link" href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">make_getter</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">make_setter</span><span class="special">()</span></code>
are the functions used internally by <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu" title="Class template class_ modifier functions"><code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;&gt;::</span><span class="identifier">def_readonly</span></code></a> and <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu" title="Class template class_ modifier functions"><code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;&gt;::</span><span class="identifier">def_readwrite</span></code></a> to produce Python
callable objects which wrap C++ data members.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_data_members_hpp.functions"></a><a class="link" href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="identifier">C</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="identifier">C</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
Policies is a model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies"><code class="computeroutput"><span class="identifier">CallPolicies</span></code></a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a Python callable object which accepts a single argument
that can be converted from_python to C*, and returns the corresponding
member D member of the C object, converted to_python. If policies
is supplied, it will be applied to the function as described here.
Otherwise, the library attempts to determine whether D is a user-defined
class type, and if so uses return_internal_reference&lt;&gt; for
Policies. Note that this test may inappropriately choose return_internal_reference&lt;&gt;
in some cases when D is a smart pointer type. This is a known defect.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_getter</span><span class="special">(</span><span class="identifier">D</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
Policies is a model of CallPolicies.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a Python callable object which accepts no arguments and returns
d or *p, converted to_python on demand. If policies is supplied,
it will be applied to the function as described here. Otherwise,
the library attempts to determine whether D is a user-defined class
type, and if so uses reference_existing_object for Policies.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span> <span class="identifier">C</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span> <span class="identifier">C</span><span class="special">::*</span><span class="identifier">pm</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
Policies is a model of CallPolicies.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a Python callable object which, when called from Python,
expects two arguments which can be converted from_python to C* and
D const&amp;, respectively, and sets the corresponding D member of
the C object. If policies is supplied, it will be applied to the
function as described here.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span><span class="special">&amp;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span><span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">D</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_setter</span><span class="special">(</span><span class="identifier">D</span><span class="special">*</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
Policies is a model of CallPolicies.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a Python callable object which accepts one argument, which
is converted from Python to D const&amp; and written into d or *p,
respectively. If policies is supplied, it will be applied to the
function as described here.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_data_members_hpp.example"></a><a class="link" href="boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
The code below uses make_getter and make_setter to expose a data member
as functions:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">data_members</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">y</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">int</span> <span class="identifier">y</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE_INIT</span><span class="special">(</span><span class="identifier">data_members_example</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get"</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">y</span><span class="special">))</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="identifier">make_setter</span><span class="special">(&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">y</span><span class="special">))</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
It can be used this way in Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">data_members_example</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">X</span><span class="special">(</span><span class="number">1</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span>
<span class="number">1</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="number">2</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span>
<span class="number">2</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_call_method_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_make_function_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,194 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/make_function.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_data_members_hpp.html" title="boost/python/data_members.hpp">
<link rel="next" href="boost_python_overloads_hpp.html" title="boost/python/overloads.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_data_members_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_overloads_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_make_function_hpp"></a><a class="link" href="boost_python_make_function_hpp.html" title="boost/python/make_function.hpp">boost/python/make_function.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_make_function_hpp.introduction"></a><a class="link" href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
make_function() and make_constructor() are the functions used internally
by def() and class_&lt;&gt;::def() to produce Python callable objects which
wrap C++ functions and member functions.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_make_function_hpp.functions"></a><a class="link" href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">KeywordsOrSignature</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">,</span> <span class="identifier">KeywordsOrSignature</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ks</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Signature</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">,</span> <span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">,</span> <span class="identifier">Signature</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sig</span><span class="special">)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
F is a function pointer or member function pointer type. If policies
are supplied, it must be a model of CallPolicies. If kewords are
supplied, it must be the result of a keyword-expression specifying
no more arguments than the arity of f.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<p>
Creates a Python callable object which, when called from Python,
converts its arguments to C++ and calls f. If F is a pointer-to-member-function
type, the target object of the function call (*this) will be taken
from the first Python argument, and subsequent Python arguments will
be used as the arguments to f.
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If policies are supplied, it will be applied to the function
as described here.
</li>
<li class="listitem">
If keywords are supplied, the keywords will be applied in order
to the final arguments of the resulting function.
</li>
<li class="listitem">
If Signature is supplied, it should be an instance of an MPL
front-extensible sequence representing the function's return
type followed by its argument types. Pass a Signature when wrapping
function object types whose signatures can't be deduced, or when
you wish to override the types which will be passed to the wrapped
function.
</li>
</ul></div>
</dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
<dt><span class="term">Caveats</span></dt>
<dd><p>
An argument of pointer type may be 0 if None is passed from Python.
An argument type which is a constant reference may refer to a temporary
which was created from the Python object for just the duration of
the call to the wrapped function, for example a std::vector conjured
up by the conversion process from a Python list. Use a non-const
reference argument when a persistent lvalue is required.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_constructor</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_constructor</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">KeywordsOrSignature</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_constructor</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">,</span> <span class="identifier">KeywordsOrSignature</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ks</span><span class="special">)</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Signature</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">make_constructor</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">,</span> <span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">,</span> <span class="identifier">Signature</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sig</span><span class="special">)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
F is a function pointer type. If policies are supplied, it must be
a model of CallPolicies. If kewords are supplied, it must be the
result of a keyword-expression specifying no more arguments than
the arity of f.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a Python callable object which, when called from Python,
converts its arguments to C++ and calls f.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An instance of object which holds the new Python callable object.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_make_function_hpp.example"></a><a class="link" href="boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
C++ function exposed below returns a callable object wrapping one of two
functions.
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">make_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">foo</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"foo"</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">bar</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"bar"</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">choose_function</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">selector</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">selector</span><span class="special">)</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">make_function</span><span class="special">(</span><span class="identifier">foo</span><span class="special">);</span>
<span class="keyword">else</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">make_function</span><span class="special">(</span><span class="identifier">bar</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">make_function_test</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"choose_function"</span><span class="special">,</span> <span class="identifier">choose_function</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
It can be used this way in Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">make_function_test</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">choose_function</span><span class="special">(</span><span class="number">1</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">g</span> <span class="special">=</span> <span class="identifier">choose_function</span><span class="special">(</span><span class="number">0</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span><span class="special">()</span>
<span class="char">'foo'</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">g</span><span class="special">()</span>
<span class="char">'bar'</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_data_members_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_overloads_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,208 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/overloads.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_make_function_hpp.html" title="boost/python/make_function.hpp">
<link rel="next" href="boost_python_ptr_hpp.html" title="boost/python/ptr.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_make_function_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ptr_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_overloads_hpp"></a><a class="link" href="boost_python_overloads_hpp.html" title="boost/python/overloads.hpp">boost/python/overloads.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.overloaddispatcher_concept">OverloadDispatcher
Concept</a></span></dt>
<dt><span class="section"><a href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_overloads_hpp.introduction"></a><a class="link" href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions">overload-dispatch-expressions</a></span></dt></dl></div>
<p>
Defines facilities for generating families of overloaded Python functions
and extension class methods from C++ functions and member functions with
default arguments, or from similar families of C++ overloads
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions"></a><a class="link" href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">overload-dispatch-expressions</a>
</h4></div></div></div>
<p>
An overload-dispatch-expression is used to describe a family of overloaded
methods to be generated for an extension class. It has the following
properties:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">docstring</span></dt>
<dd><p>
An <a class="link" href="../glossary.html#ntbs">ntbs</a> whose value will bound to the
methods' <code class="computeroutput"><span class="identifier">__doc__</span></code>
attribute
</p></dd>
<dt><span class="term">keywords</span></dt>
<dd><p>
A <a class="link" href="../function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expression</a>
which will be used to name (a trailing subsequence of) the arguments
to the generated methods.
</p></dd>
<dt><span class="term">call policies</span></dt>
<dd><p>
An instance of some type which models CallPolicies.
</p></dd>
<dt><span class="term">minimum arity</span></dt>
<dd><p>
The minimum number of arguments to be accepted by a generated method
overload.
</p></dd>
<dt><span class="term">maximum arity</span></dt>
<dd><p>
The maximum number of arguments to be accepted by a generated method
overload.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_overloads_hpp.overloaddispatcher_concept"></a><a class="link" href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.overloaddispatcher_concept" title="OverloadDispatcher Concept">OverloadDispatcher
Concept</a>
</h3></div></div></div>
<p>
An OverloadDispatcher X is a class which has a minimum arity and a maximum
arity, and for which the following following are valid overload-dispatch-expressions,
with the same minimum and maximum arity as the OverloadDispatcher.
</p>
<pre class="programlisting"><span class="identifier">X</span><span class="special">()</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">)</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">docstring</span><span class="special">)</span>
<span class="identifier">X</span><span class="special">()[</span><span class="identifier">policies</span><span class="special">]</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">)[</span><span class="identifier">policies</span><span class="special">]</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)[</span><span class="identifier">policies</span><span class="special">]</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">docstring</span><span class="special">)[</span><span class="identifier">policies</span><span class="special">]</span>
</pre>
<p>
* If policies are supplied, it must be an instance of a type which models
<a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>, and will be
used as the result's call policies. Otherwise the result's call policies
will be an instance of <a class="link" href="models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_default_call_polici" title="boost/python/default_call_policies.hpp"><code class="computeroutput"><span class="identifier">default_call_policies</span></code></a>. * If docstring
is supplied it must be an <a class="link" href="../glossary.html#ntbs">ntbs</a>, and will be
used as the result's docstring. Otherwise the result has an empty docstring.
* If keywords is supplied it must be the result of a <a class="link" href="../function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expression</a>
whose length is no greater than X's maximum arity, and will be used as
the result's keywords. Otherwise the result's keywords will be empty.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_overloads_hpp.macros"></a><a class="link" href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.macros" title="Macros">Macros</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">func_id</span><span class="special">,</span> <span class="identifier">min_args</span><span class="special">,</span> <span class="identifier">max_args</span><span class="special">)</span>
</pre>
<p>
Expands to the definition of an OverloadDispatcher called name in the current
scope which can be used to generate the following function invocation:
</p>
<pre class="programlisting"><span class="identifier">func_id</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,...</span><span class="identifier">ai</span><span class="special">);</span></pre>
<p>
for all <code class="computeroutput"><span class="identifier">min_args</span> <span class="special">&lt;=</span>
<span class="identifier">i</span> <span class="special">&lt;=</span>
<span class="identifier">max_args</span></code>.
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">member_name</span><span class="special">,</span> <span class="identifier">min_args</span><span class="special">,</span> <span class="identifier">max_args</span><span class="special">)</span>
</pre>
<p>
Expands to the definition of an OverloadDispatcher called name in the current
scope which can be used to generate the following function invocation:
</p>
<pre class="programlisting"><span class="identifier">x</span><span class="special">.</span><span class="identifier">member_name</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,...</span><span class="identifier">ai</span><span class="special">);</span></pre>
<p>
for all min_args &lt;= i &lt;= max_args, where x is a reference to an object
of class type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_overloads_hpp.example"></a><a class="link" href="boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">args</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">tuple</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">overloads</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_internal_reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">tuple</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">4.25</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">z</span> <span class="special">=</span> <span class="string">"wow"</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">f_overloads</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
<span class="keyword">struct</span> <span class="identifier">Y</span> <span class="special">{};</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">4.25</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">z</span> <span class="special">=</span> <span class="string">"wow"</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">inner</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Y</span> <span class="identifier">inner</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">f_member_overloads</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">args_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span>
<span class="identifier">f_overloads</span><span class="special">(</span>
<span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span> <span class="string">"y"</span><span class="special">,</span> <span class="string">"z"</span><span class="special">),</span> <span class="string">"This is f's docstring"</span>
<span class="special">));</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;(</span><span class="string">"Y"</span><span class="special">)</span>
<span class="special">;</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="string">"This is X's docstring"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f1"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span>
<span class="identifier">f_member_overloads</span><span class="special">(</span>
<span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span> <span class="string">"y"</span><span class="special">,</span> <span class="string">"z"</span><span class="special">),</span> <span class="string">"f's docstring"</span>
<span class="special">)[</span><span class="identifier">return_internal_reference</span><span class="special">&lt;&gt;()]</span>
<span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_make_function_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ptr_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,287 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/ptr.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_overloads_hpp.html" title="boost/python/overloads.hpp">
<link rel="next" href="boost_python_raw_function_hpp.html" title="boost/python/raw_function.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_overloads_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_raw_function_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_ptr_hpp"></a><a class="link" href="boost_python_ptr_hpp.html" title="boost/python/ptr.hpp">boost/python/ptr.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_t">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
types</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_c">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
constructors and destructor</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_o">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
observer functions</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions">Metafunctions</a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.introduction"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/ptr.hpp&gt; defines the ptr() function template, which
allows users to specify how to convert C++ pointer values to python in
the context of implementing overridable virtual functions, invoking Python
callable objects, or explicitly converting C++ objects to Python. Normally,
when passing pointers to Python callbacks, the pointee is copied to ensure
that the Python object never holds a dangling reference. To specify that
the new Python object should merely contain a copy of a pointer p, the
user can pass ptr(p) instead of passing p directly. This interface is meant
to mirror the use of boost::ref(), which can be similarly used to prevent
copying of referents.
</p>
<p>
ptr(p) returns an instance of <a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper" title="Class template pointer_wrapper"><code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code></a>,
which can be detected using the <a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_is_pointer_wrappe" title="Class template is_pointer_wrapper"><code class="computeroutput"><span class="identifier">is_pointer_wrapper</span><span class="special">&lt;&gt;</span></code></a>
metafunction; <a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_unwrap_pointer" title="Class template unwrap_pointer"><code class="computeroutput"><span class="identifier">unwrap_pointer</span><span class="special">&lt;&gt;</span></code></a>
is a metafunction which extracts the original pointer type from a <code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code>.
These classes can be thought of as implementation details.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.functions"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">pointer_wrapper</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">ptr</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
T is a pointer type.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
pointer_wrapper&lt;T&gt;(x)
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper" title="Class template pointer_wrapper">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code></a>
</h3></div></div></div>
<p>
A "type envelope" which is returned by <code class="computeroutput"><span class="identifier">ptr</span><span class="special">()</span></code>, used to indicate reference semantics
for pointers passed to Python callbacks.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Ptr</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">pointer_wrapper</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">typedef</span> <span class="identifier">Ptr</span> <span class="identifier">type</span><span class="special">;</span>
<span class="keyword">explicit</span> <span class="identifier">pointer_wrapper</span><span class="special">(</span><span class="identifier">Ptr</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">operator</span> <span class="identifier">Ptr</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">Ptr</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_t"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_t" title="Class template pointer_wrapper types">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
types</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">Ptr</span> <span class="identifier">type</span><span class="special">;</span>
</pre>
<p>
The type of the pointer being wrapped.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_c"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_c" title="Class template pointer_wrapper constructors and destructor">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
constructors and destructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">pointer_wrapper</span><span class="special">(</span><span class="identifier">Ptr</span> <span class="identifier">x</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">Ptr</span></code> is a pointer
type
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Stores <code class="computeroutput"><span class="identifier">x</span></code> in a the
<code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code>.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_o"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_o" title="Class template pointer_wrapper observer functions">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
observer functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">Ptr</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">Ptr</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
a copy of the stored pointer.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
pointer_wrapper is intended to be a stand-in for the actual pointer
type, but sometimes it's better to have an explicit way to retrieve
the pointer.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.metafunctions"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions" title="Metafunctions">Metafunctions</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_is_pointer_wrappe">Class
template <code class="computeroutput"><span class="identifier">is_pointer_wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_unwrap_pointer">Class
template <code class="computeroutput"><span class="identifier">unwrap_pointer</span></code></a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_is_pointer_wrappe"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_is_pointer_wrappe" title="Class template is_pointer_wrapper">Class
template <code class="computeroutput"><span class="identifier">is_pointer_wrapper</span></code></a>
</h4></div></div></div>
<p>
A unary metafunction whose value is true iff its argument is a pointer_wrapper&lt;&gt;.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">is_pointer_wrapper</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">unspecified</span> <span class="identifier">value</span> <span class="special">=</span> <span class="special">...;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">true</span></code> iff <code class="computeroutput"><span class="identifier">T</span></code> is a specialization of <code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code>.
value is an integral constant convertible to bool of unspecified
type
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_unwrap_pointer"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions.class_template_unwrap_pointer" title="Class template unwrap_pointer">Class
template <code class="computeroutput"><span class="identifier">unwrap_pointer</span></code></a>
</h4></div></div></div>
<p>
A unary metafunction which extracts the wrapped pointer type from a specialization
of pointer_wrapper&lt;&gt;.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">unwrap_pointer</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">unspecified</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="identifier">type</span></code> if <code class="computeroutput"><span class="identifier">T</span></code>
is a specialization of <code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code>, <code class="computeroutput"><span class="identifier">T</span></code>
otherwise
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_ptr_hpp.example"></a><a class="link" href="boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
This example illustrates the use of ptr() to prevent an object from being
copied:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">call</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">ptr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">expensive_to_copy</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">};</span>
<span class="keyword">void</span> <span class="identifier">pass_as_arg</span><span class="special">(</span><span class="identifier">expensive_to_copy</span><span class="special">*</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">f</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// call the Python function f, passing a Python object built around</span>
<span class="comment">// which refers to *x by-pointer.</span>
<span class="comment">//</span>
<span class="comment">// *** Note: ensuring that *x outlives the argument to f() is ***</span>
<span class="comment">// *** up to the user! Failure to do so could result in a crash! ***</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">ptr</span><span class="special">(</span><span class="identifier">x</span><span class="special">));</span>
<span class="special">}</span>
<span class="special">...</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_overloads_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_raw_function_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,111 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/raw_function.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_ptr_hpp.html" title="boost/python/ptr.hpp">
<link rel="next" href="function_documentation.html" title="Function documentation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_ptr_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="function_documentation.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_raw_function_hpp"></a><a class="link" href="boost_python_raw_function_hpp.html" title="boost/python/raw_function.hpp">boost/python/raw_function.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function">Function
<code class="computeroutput"><span class="identifier">raw_function</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_raw_function_hpp.introduction"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">raw_function</span><span class="special">(...)</span></code>
is used to convert a function taking a <a class="link" href="../object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple" title="Class tuple"><code class="computeroutput"><span class="identifier">tuple</span></code></a> and a <a class="link" href="../object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict" title="Class dict"><code class="computeroutput"><span class="identifier">dict</span></code></a> into a Python callable object
which accepts a variable number of arguments and arbitrary keyword arguments.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function" title="Function raw_function">Function
<code class="computeroutput"><span class="identifier">raw_function</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">raw_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">min_args</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
f(tuple(), dict()) is well-formed.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
a callable object which requires at least min_args arguments. When
called, the actual non-keyword arguments will be passed in a tuple
as the first argument to f, and the keyword arguments will be passed
in a dict as the second argument to f.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_raw_function_hpp.example"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">tuple</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">dict</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">raw_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">tuple</span> <span class="identifier">raw</span><span class="special">(</span><span class="identifier">tuple</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">kw</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">args</span><span class="special">,</span> <span class="identifier">kw</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">raw_test</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"raw"</span><span class="special">,</span> <span class="identifier">raw_function</span><span class="special">(</span><span class="identifier">raw</span><span class="special">));</span>
<span class="special">}</span>
</pre>
<p>
Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">raw_test</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">raw</span><span class="special">(</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="identifier">foo</span> <span class="special">=</span> <span class="char">'bar'</span><span class="special">,</span> <span class="identifier">baz</span> <span class="special">=</span> <span class="number">42</span><span class="special">)</span>
<span class="special">((</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">),</span> <span class="special">{</span><span class="char">'foo'</span><span class="special">:</span> <span class="char">'bar'</span><span class="special">,</span> <span class="char">'baz'</span><span class="special">:</span> <span class="number">42</span><span class="special">})</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_ptr_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="function_documentation.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,458 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Function documentation</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="boost_python_raw_function_hpp.html" title="boost/python/raw_function.hpp">
<link rel="next" href="models_of_callpolicies.html" title="Models of CallPolicies">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_raw_function_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="models_of_callpolicies.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.function_documentation"></a><a class="link" href="function_documentation.html" title="Function documentation">Function
documentation</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat">boost/python/function_doc_signature.hpp</a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp">boost/python/pytype_function.hpp</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_function_doc_signat"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat" title="boost/python/function_doc_signature.hpp">boost/python/function_doc_signature.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.class_function_doc_signature_gen">Class
<code class="computeroutput"><span class="identifier">function_doc_signature_generator</span></code></a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.introduction"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
Boost.Python supports docstrings with automatic appending of Pythonic
and C++ signatures. This feature is implemented by class <code class="computeroutput"><span class="identifier">function_doc_signature_generator</span></code>. The
class uses all of the overloads, supplied arg names and default values,
as well as the user-defined docstrings, to generate documentation for
a given function.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.class_function_doc_signature_gen"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.class_function_doc_signature_gen" title="Class function_doc_signature_generator">Class
<code class="computeroutput"><span class="identifier">function_doc_signature_generator</span></code></a>
</h4></div></div></div>
<p>
The class has only one public function which returns a list of strings
documenting the overloads of a function.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">objects</span> <span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">function_doc_signature_generator</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">list</span> <span class="identifier">function_doc_signatures</span><span class="special">(</span><span class="identifier">function</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">f</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.example"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">args</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">tuple</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">overloads</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">raw_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">tuple</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">4.25</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">z</span> <span class="special">=</span> <span class="string">"wow"</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">f_overloads</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">tuple</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">4.25</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">z</span> <span class="special">=</span> <span class="string">"wow"</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">X_f_overloads</span><span class="special">,</span> <span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
<span class="identifier">tuple</span> <span class="identifier">raw_func</span><span class="special">(</span><span class="identifier">tuple</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">kw</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">args</span><span class="special">,</span> <span class="identifier">kw</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">args_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="special">(</span><span class="identifier">arg</span><span class="special">(</span><span class="string">"x"</span><span class="special">)=</span><span class="number">1</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"y"</span><span class="special">)=</span><span class="number">4.25</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"z"</span><span class="special">)=</span><span class="string">"wow"</span><span class="special">)</span>
<span class="special">,</span> <span class="string">"This is f's docstring"</span>
<span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"raw"</span><span class="special">,</span> <span class="identifier">raw_function</span><span class="special">(</span><span class="identifier">raw_func</span><span class="special">));</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f1"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">f_overloads</span><span class="special">(</span><span class="string">"f1's docstring"</span><span class="special">,</span> <span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span> <span class="string">"y"</span><span class="special">,</span> <span class="string">"z"</span><span class="special">)));</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="string">"This is X's docstring"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;&gt;(</span><span class="identifier">args</span><span class="special">(</span><span class="string">"self"</span><span class="special">)))</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span>
<span class="special">,</span> <span class="string">"This is X.f's docstring"</span>
<span class="special">,</span> <span class="identifier">args</span><span class="special">(</span><span class="string">"self"</span><span class="special">,</span><span class="string">"x"</span><span class="special">,</span> <span class="string">"y"</span><span class="special">,</span> <span class="string">"z"</span><span class="special">))</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">args_ext</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">help</span><span class="special">(</span><span class="identifier">args_ext</span><span class="special">)</span>
<span class="identifier">Help</span> <span class="identifier">on</span> <span class="identifier">module</span> <span class="identifier">args_ext</span><span class="special">:</span>
<span class="identifier">NAME</span>
<span class="identifier">args_ext</span>
<span class="identifier">FILE</span>
<span class="identifier">args_ext</span><span class="special">.</span><span class="identifier">pyd</span>
<span class="identifier">CLASSES</span>
<span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span><span class="special">.</span><span class="identifier">instance</span><span class="special">(</span><span class="identifier">__builtin__</span><span class="special">.</span><span class="identifier">object</span><span class="special">)</span>
<span class="identifier">X</span>
<span class="keyword">class</span> <span class="identifier">X</span><span class="special">(</span><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span><span class="special">.</span><span class="identifier">instance</span><span class="special">)</span>
<span class="special">|</span> <span class="identifier">This</span> <span class="keyword">is</span> <span class="identifier">X</span><span class="string">'s docstring
|
| Method resolution order:
| X
| Boost.Python.instance
| __builtin__.object
|
| Methods defined here:
|
| __init__(...)
| __init__( (object)self) -&gt; None :
| C++ signature:
| void __init__(struct _object *)
|
| f(...)
| f( (X)self, (int)x, (float)y, (str)z) -&gt; tuple : This is X.f'</span><span class="identifier">s</span> <span class="identifier">docstring</span>
<span class="special">|</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="special">|</span> <span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">struct</span> <span class="identifier">X</span> <span class="special">{</span><span class="identifier">lvalue</span><span class="special">},</span><span class="identifier">int</span><span class="special">,</span><span class="identifier">double</span><span class="special">,</span><span class="identifier">char</span> <span class="identifier">const</span> <span class="special">*)</span>
<span class="special">|</span>
<span class="special">|</span> <span class="special">.................</span>
<span class="special">|</span>
<span class="identifier">FUNCTIONS</span>
<span class="identifier">f</span><span class="special">(...)</span>
<span class="identifier">f</span><span class="special">([</span> <span class="special">(</span><span class="identifier">int</span><span class="special">)</span><span class="identifier">x</span><span class="special">=</span><span class="number">1</span> <span class="special">[,</span> <span class="special">(</span><span class="identifier">float</span><span class="special">)</span><span class="identifier">y</span><span class="special">=</span><span class="number">4.25</span> <span class="special">[,</span> <span class="special">(</span><span class="identifier">str</span><span class="special">)</span><span class="identifier">z</span><span class="special">=</span><span class="string">'wow'</span><span class="special">]]])</span> <span class="special">-&gt;</span> <span class="identifier">tuple</span> <span class="special">:</span> <span class="identifier">This</span> <span class="keyword">is</span> <span class="identifier">f</span><span class="string">'s docstring
C++ signature:
class boost::python::tuple f([ int=1 [,double=4.25 [,char const *='</span><span class="identifier">wow</span><span class="string">']]])
f1(...)
f1([ (int)x [, (float)y [, (str)z]]]) -&gt; tuple : f1'</span><span class="identifier">s</span> <span class="identifier">docstring</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span> <span class="identifier">f1</span><span class="special">([</span> <span class="identifier">int</span> <span class="special">[,</span><span class="identifier">double</span> <span class="special">[,</span><span class="identifier">char</span> <span class="identifier">const</span> <span class="special">*]]])</span>
<span class="identifier">raw</span><span class="special">(...)</span>
<span class="identifier">object</span> <span class="identifier">raw</span><span class="special">(</span><span class="identifier">tuple</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">kwds</span><span class="special">)</span> <span class="special">:</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="identifier">object</span> <span class="identifier">raw</span><span class="special">(</span><span class="identifier">tuple</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">kwds</span><span class="special">)</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp" title="boost/python/pytype_function.hpp">boost/python/pytype_function.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_wrap_pytype">Class
<code class="computeroutput"><span class="identifier">wrap_pytype</span></code></a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_registered_pytype">Class
<code class="computeroutput"><span class="identifier">registered_pytype</span></code></a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_expected_from_python_type">Class
<code class="computeroutput"><span class="identifier">expected_from_python_type</span></code></a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_to_python_target_type">Class
<code class="computeroutput"><span class="identifier">to_python_target_type</span></code></a></span></dt>
<dt><span class="section"><a href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.introduction"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
To support Pythonic signatures the converters should supply a <code class="computeroutput"><span class="identifier">get_pytype</span></code> function returning a pointer
to the associated <code class="computeroutput"><span class="identifier">PyTypeObject</span></code>.
See for example <a class="link" href="../concepts/resultconverter.html" title="ResultConverter"><code class="computeroutput"><span class="identifier">ResultConverter</span></code></a> or <a class="link" href="../to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert.class_template_to_python_convert" title="Class template to_python_converter constructor"><code class="computeroutput"><span class="identifier">to_python_converter</span></code></a>. The classes
in this header file are meant to be used when implmenting <code class="computeroutput"><span class="identifier">get_pytype</span></code>. There are also <code class="computeroutput"><span class="identifier">_direct</span></code> versions of the templates of
<code class="computeroutput"><span class="keyword">class</span> <span class="identifier">T</span></code>
which should be used with undecorated type parameter, expected to be
in the conversion registry when the module loads.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_wrap_pytype"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_wrap_pytype" title="Class wrap_pytype">Class
<code class="computeroutput"><span class="identifier">wrap_pytype</span></code></a>
</h4></div></div></div>
<p>
This template generates a static <code class="computeroutput"><span class="identifier">get_pytype</span></code>
member returning the template parameter.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">converter</span><span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">pytype</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">wrap_pytype</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">get_pytype</span><span class="special">(){</span><span class="keyword">return</span> <span class="identifier">pytype</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
<span class="special">}}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_registered_pytype"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_registered_pytype" title="Class registered_pytype">Class
<code class="computeroutput"><span class="identifier">registered_pytype</span></code></a>
</h4></div></div></div>
<p>
This template should be used with template parameters which are (possibly
decorated) types exported to python using <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;"><code class="computeroutput"><span class="identifier">class_</span></code></a>. The generated a static
<code class="computeroutput"><span class="identifier">get_pytype</span></code> member returns
the corresponding python type.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">converter</span><span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">registered_pytype</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">get_pytype</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_expected_from_python_type"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_expected_from_python_type" title="Class expected_from_python_type">Class
<code class="computeroutput"><span class="identifier">expected_from_python_type</span></code></a>
</h4></div></div></div>
<p>
This template generates a static <code class="computeroutput"><span class="identifier">get_pytype</span></code>
member which inspects the registered <code class="computeroutput"><span class="identifier">from_python</span></code>
converters for the type <code class="computeroutput"><span class="identifier">T</span></code>
and returns a matching python type.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">converter</span><span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">expected_from_python_type</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">get_pytype</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_to_python_target_type"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.class_to_python_target_type" title="Class to_python_target_type">Class
<code class="computeroutput"><span class="identifier">to_python_target_type</span></code></a>
</h4></div></div></div>
<p>
This template generates a static <code class="computeroutput"><span class="identifier">get_pytype</span></code>
member returning the python type to which <code class="computeroutput"><span class="identifier">T</span></code>
can be converted.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">converter</span><span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">to_python_target_type</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">get_pytype</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.example"></a><a class="link" href="function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.example" title="Example">Example</a>
</h4></div></div></div>
<p>
This example presumes that someone has implemented the standard noddy
example module from the Python documentation, and placed the corresponding
declarations in "noddy.h". Because <code class="computeroutput"><span class="identifier">noddy_NoddyObject</span></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 type
of its return value.
</p>
<p>
C++ module definition:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="string">"noddy.h"</span>
<span class="keyword">struct</span> <span class="identifier">tag</span> <span class="special">{};</span>
<span class="identifier">tag</span> <span class="identifier">make_tag</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">tag</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">tag_to_noddy</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_PYTHON_SUPPORTS_PY_SIGNATURES</span> <span class="comment">//unnecessary overhead if py signatures are not supported</span>
<span class="special">:</span> <span class="identifier">wrap_pytype</span><span class="special">&lt;&amp;</span><span class="identifier">noddy_NoddyType</span><span class="special">&gt;</span> <span class="comment">//inherits get_pytype from wrap_pytype</span>
<span class="preprocessor">#endif</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">tag</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">PyObject_New</span><span class="special">(</span><span class="identifier">noddy_NoddyObject</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">noddy_NoddyType</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">to_python_converter</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"make_tag"</span><span class="special">,</span> <span class="identifier">make_tag</span><span class="special">);</span>
<span class="identifier">to_python_converter</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">,</span> <span class="identifier">tag_to_noddy</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_PYTHON_SUPPORTS_PY_SIGNATURES</span> <span class="comment">//invalid if py signatures are not supported</span>
<span class="special">,</span> <span class="keyword">true</span>
<span class="preprocessor">#endif</span>
<span class="special">&gt;();</span> <span class="comment">//"true" because tag_to_noddy has member get_pytype</span>
<span class="special">}</span>
</pre>
<p>
The following example registers to and from python converters using the
templates expected_from_python_type and to_pyhton_target_type.
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">extract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">to_python_converter</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">A</span>
<span class="special">{</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">B</span>
<span class="special">{</span>
<span class="identifier">A</span> <span class="identifier">a</span><span class="special">;</span>
<span class="identifier">B</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">&amp;</span> <span class="identifier">a_</span><span class="special">):</span><span class="identifier">a</span><span class="special">(</span><span class="identifier">a_</span><span class="special">){}</span>
<span class="special">};</span>
<span class="comment">// Converter from A to python int</span>
<span class="keyword">struct</span> <span class="identifier">BToPython</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_PYTHON_SUPPORTS_PY_SIGNATURES</span> <span class="comment">//unnecessary overhead if py signatures are not supported</span>
<span class="special">:</span> <span class="identifier">converter</span><span class="special">::</span><span class="identifier">to_python_target_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="comment">//inherits get_pytype</span>
<span class="preprocessor">#endif</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">convert</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">incref</span><span class="special">(</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">b</span><span class="special">.</span><span class="identifier">a</span><span class="special">).</span><span class="identifier">ptr</span><span class="special">());</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="comment">// Conversion from python int to A</span>
<span class="keyword">struct</span> <span class="identifier">BFromPython</span>
<span class="special">{</span>
<span class="identifier">BFromPython</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">registry</span><span class="special">::</span><span class="identifier">push_back</span>
<span class="special">(</span> <span class="special">&amp;</span><span class="identifier">convertible</span>
<span class="special">,</span> <span class="special">&amp;</span><span class="identifier">construct</span>
<span class="special">,</span> <span class="identifier">type_id</span><span class="special">&lt;</span> <span class="identifier">B</span> <span class="special">&gt;()</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_PYTHON_SUPPORTS_PY_SIGNATURES</span> <span class="comment">//invalid if py signatures are not supported</span>
<span class="special">,</span> <span class="special">&amp;</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">expected_from_python_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;::</span><span class="identifier">get_pytype</span><span class="comment">//convertible to A can be converted to B</span>
<span class="preprocessor">#endif</span>
<span class="special">);</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span><span class="special">*</span> <span class="identifier">convertible</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">obj_ptr</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">&amp;&gt;</span> <span class="identifier">ex</span><span class="special">(</span><span class="identifier">obj_ptr</span><span class="special">);</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">ex</span><span class="special">.</span><span class="identifier">check</span><span class="special">())</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">obj_ptr</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">construct</span><span class="special">(</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">obj_ptr</span><span class="special">,</span>
<span class="identifier">converter</span><span class="special">::</span><span class="identifier">rvalue_from_python_stage1_data</span><span class="special">*</span> <span class="identifier">data</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">void</span><span class="special">*</span> <span class="identifier">storage</span> <span class="special">=</span> <span class="special">(</span>
<span class="special">(</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">rvalue_from_python_storage</span><span class="special">&lt;</span> <span class="identifier">B</span> <span class="special">&gt;*)</span><span class="identifier">data</span><span class="special">)-&gt;</span> <span class="identifier">storage</span><span class="special">.</span><span class="identifier">bytes</span><span class="special">;</span>
<span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">&amp;&gt;</span> <span class="identifier">ex</span><span class="special">(</span><span class="identifier">obj_ptr</span><span class="special">);</span>
<span class="keyword">new</span> <span class="special">(</span><span class="identifier">storage</span><span class="special">)</span> <span class="identifier">B</span><span class="special">(</span><span class="identifier">ex</span><span class="special">());</span>
<span class="identifier">data</span><span class="special">-&gt;</span><span class="identifier">convertible</span> <span class="special">=</span> <span class="identifier">storage</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">B</span> <span class="identifier">func</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">b</span> <span class="special">;</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">pytype_function_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">to_python_converter</span><span class="special">&lt;</span> <span class="identifier">B</span> <span class="special">,</span> <span class="identifier">BToPython</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_PYTHON_SUPPORTS_PY_SIGNATURES</span> <span class="comment">//invalid if py signatures are not supported</span>
<span class="special">,</span><span class="keyword">true</span>
<span class="preprocessor">#endif</span>
<span class="special">&gt;();</span> <span class="comment">//has get_pytype</span>
<span class="identifier">BFromPython</span><span class="special">();</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;(</span><span class="string">"A"</span><span class="special">)</span> <span class="special">;</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"func"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">func</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">pytype_function_ext</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">func</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">func</span><span class="special">(</span> <span class="special">(</span><span class="identifier">A</span><span class="special">)</span><span class="identifier">arg1</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="identifier">A</span> <span class="special">:</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="keyword">struct</span> <span class="identifier">B</span> <span class="identifier">func</span><span class="special">(</span><span class="keyword">struct</span> <span class="identifier">B</span><span class="special">)</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_raw_function_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="models_of_callpolicies.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,308 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Models of ResultConverter</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="models_of_callpolicies.html" title="Models of CallPolicies">
<link rel="next" href="models_of_resultconvertergenerat.html" title="Models of ResultConverterGenerator">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="models_of_callpolicies.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="models_of_resultconvertergenerat.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.models_of_resultconverter"></a><a class="link" href="models_of_resultconverter.html" title="Models of ResultConverter">Models
of ResultConverter</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_">boost/python/to_python_indirect.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp">boost/python/to_python_value.hpp</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_" title="boost/python/to_python_indirect.hpp">boost/python/to_python_indirect.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_observe">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code> observers</a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_statics">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code> statics</a></span></dt>
</dl></div>
<pre class="programlisting"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">to_python_indirect</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="identifier">supplies</span> <span class="identifier">a</span> <span class="identifier">way</span> <span class="identifier">to</span> <span class="identifier">construct</span> <span class="keyword">new</span> <span class="identifier">Python</span> <span class="identifier">objects</span> <span class="identifier">that</span> <span class="identifier">hold</span> <span class="identifier">wrapped</span> <span class="identifier">C</span><span class="special">++</span> <span class="keyword">class</span> <span class="identifier">instances</span> <span class="identifier">via</span> <span class="identifier">a</span> <span class="identifier">pointer</span> <span class="keyword">or</span> <span class="identifier">smart</span> <span class="identifier">pointer</span><span class="special">.</span>
<span class="special">[</span><span class="identifier">endsect</span><span class="special">]</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect" title="Class to_python_indirect">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code></a>
</h5></div></div></div>
<p>
Class template <code class="computeroutput"><span class="identifier">to_python_indirect</span></code>
converts objects of its first argument type to python as extension
class instances, using the ownership policy provided by its 2nd argument.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
T
</p>
</td>
<td>
<p>
Either <code class="computeroutput"><span class="identifier">U</span> <span class="identifier">cv</span><span class="special">&amp;</span></code>
(where cv is any optional cv-qualification) or a <a class="link" href="../concepts/dereferenceable.html" title="Dereferenceable">Dereferenceable</a>
type such that <code class="computeroutput"><span class="special">*</span><span class="identifier">x</span></code> is convertible to <code class="computeroutput"><span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;</span></code>, where <code class="computeroutput"><span class="identifier">U</span></code> is a class type.
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">A</span></code> type deferencing
a C++ class exposed to Python using class template <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;"><code class="computeroutput"><span class="identifier">class_</span></code></a>.
</p>
</td>
</tr>
<tr>
<td>
<p>
MakeHolder
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">h</span> <span class="special">=</span>
<span class="identifier">MakeHolder</span><span class="special">::</span><span class="identifier">execute</span><span class="special">(</span><span class="identifier">p</span><span class="special">);</span></code>
</p>
</td>
<td>
<p>
A class whose static <code class="computeroutput"><span class="identifier">execute</span><span class="special">()</span></code> creates an <code class="computeroutput"><span class="identifier">instance_holder</span></code>.
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
Instantiations of to_python_indirect are models of <a class="link" href="../concepts/resultconverter.html" title="ResultConverter"><code class="computeroutput"><span class="identifier">ResultConverter</span></code></a>.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">MakeHolder</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">to_python_indirect</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">convertible</span><span class="special">();</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="identifier">ptr_or_reference</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span><span class="special">*</span> <span class="identifier">type</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_observe"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_observe" title="Class to_python_indirect observers">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code> observers</a>
</h5></div></div></div>
<pre class="programlisting"><span class="identifier">PyObject</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">x</span></code> refers to an
object (if it is a pointer type, it is non-null). <code class="computeroutput"><span class="identifier">convertible</span><span class="special">()</span>
<span class="special">==</span> <span class="keyword">true</span></code>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates an appropriately-typed Boost.Python extension class instance,
uses MakeHolder to create an instance_holder from x, installs
the instance_holder in the new extension class instance, and
returns a pointer to it.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_statics"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.introduction.class_to_python_indirect_statics" title="Class to_python_indirect statics">Class
<code class="computeroutput"><span class="identifier">to_python_indirect</span></code> statics</a>
</h5></div></div></div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">convertible</span><span class="special">()</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Returns true iff any module has registered a Python type corresponding
to U.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.example"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_.example" title="Example">Example</a>
</h4></div></div></div>
<p>
This example replicates the functionality of <a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object" title="Class reference_existing_object"><code class="computeroutput"><span class="identifier">reference_existing_object</span></code></a>, but
without some of the compile-time error checking.
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">make_reference_holder</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">objects</span><span class="special">::</span><span class="identifier">instance_holder</span><span class="special">*</span> <span class="identifier">result_type</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="identifier">result_type</span> <span class="identifier">execute</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">new</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">objects</span><span class="special">::</span><span class="identifier">pointer_holder</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*,</span> <span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">reference_existing_object</span>
<span class="special">{</span>
<span class="comment">// metafunction returning the ResultConverter</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">apply</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">to_python_indirect</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">make_reference_holder</span><span class="special">&gt;</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">};</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp" title="boost/python/to_python_value.hpp">boost/python/to_python_value.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_template_to_python_value">Class
template <code class="computeroutput"><span class="identifier">to_python_value</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_to_python_value_observers">Class
<code class="computeroutput"><span class="identifier">to_python_value</span></code> observers</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.introduction"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">to_python_value</span></code> is a
model of <a class="link" href="../concepts/resultconverter.html" title="ResultConverter">ResultConverter</a>
which copies its argument into a new Python object.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_template_to_python_value"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_template_to_python_value" title="Class template to_python_value">Class
template <code class="computeroutput"><span class="identifier">to_python_value</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">to_python_value</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">add_reference</span><span class="special">&lt;</span>
<span class="keyword">typename</span> <span class="identifier">add_const</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span>
<span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">argument_type</span><span class="special">;</span>
<span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">convertible</span><span class="special">();</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">argument_type</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_to_python_value_observers"></a><a class="link" href="models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp.class_to_python_value_observers" title="Class to_python_value observers">Class
<code class="computeroutput"><span class="identifier">to_python_value</span></code> observers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">convertible</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">true</span></code> iff a converter
has been registered which can convert <code class="computeroutput"><span class="identifier">T</span></code>
to python by-value.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">PyObject</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">argument_type</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">convertible</span><span class="special">()</span>
<span class="special">==</span> <span class="keyword">true</span></code>
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
converts <code class="computeroutput"><span class="identifier">x</span></code> to python
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
the resulting Python object iff a converter for <code class="computeroutput"><span class="identifier">T</span></code>
has been registered, <code class="computeroutput"><span class="number">0</span></code>
otherwise.
</p></dd>
</dl>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="models_of_callpolicies.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="models_of_resultconvertergenerat.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,683 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Models of ResultConverterGenerator</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
<link rel="prev" href="models_of_resultconverter.html" title="Models of ResultConverter">
<link rel="next" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="models_of_resultconverter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../to_from_python_type_conversion.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat"></a><a class="link" href="models_of_resultconvertergenerat.html" title="Models of ResultConverterGenerator">Models
of ResultConverterGenerator</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc">boost/python/copy_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe">boost/python/copy_non_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h">boost/python/manage_new_object.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_">boost/python/reference_existing_object.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp">boost/python/return_by_value.hpp</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point">boost/python/return_opaque_pointer.hpp</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc" title="boost/python/copy_const_reference.hpp">boost/python/copy_const_reference.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference">Class
<code class="computeroutput"><span class="identifier">copy_const_reference</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference_metaf">Class
<code class="computeroutput"><span class="identifier">copy_const_reference</span></code> metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference" title="Class copy_const_reference">Class
<code class="computeroutput"><span class="identifier">copy_const_reference</span></code></a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">copy_const_reference</span></code>
is a model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
which can be used to wrap C++ functions returning a reference-to-const
type such that the referenced value is copied into a new Python object.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">copy_const_reference</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference_metaf"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.class_copy_const_reference_metaf" title="Class copy_const_reference metafunctions">Class
<code class="computeroutput"><span class="identifier">copy_const_reference</span></code> metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;</span></code> for some <code class="computeroutput"><span class="identifier">U</span></code>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">to_python_value</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc.example" title="Example">Example</a>
</h4></div></div></div>
<p>
C++ module definition:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">copy_const_reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// classes to wrap</span>
<span class="keyword">struct</span> <span class="identifier">Bar</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">struct</span> <span class="identifier">Foo</span> <span class="special">{</span>
<span class="identifier">Foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="special">{</span> <span class="identifier">b</span><span class="special">.</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">Bar</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">get_bar</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">Bar</span> <span class="identifier">b</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">// Wrapper code</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Bar</span><span class="special">&gt;(</span><span class="string">"Bar"</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Foo</span><span class="special">&gt;(</span><span class="string">"Foo"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get_bar"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">get_bar</span>
<span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">copy_const_reference</span><span class="special">&gt;())</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_module</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">Foo</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">create</span> <span class="identifier">a</span> <span class="identifier">Foo</span> <span class="identifier">object</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">get_bar</span><span class="special">()</span> <span class="special">#</span> <span class="identifier">make</span> <span class="identifier">a</span> <span class="identifier">copy</span> <span class="identifier">of</span> <span class="identifier">the</span> <span class="identifier">internal</span> <span class="identifier">Bar</span> <span class="identifier">object</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe" title="boost/python/copy_non_const_reference.hpp">boost/python/copy_non_const_reference.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference">Class
<code class="computeroutput"><span class="identifier">copy_non_const_reference</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference_m">Class
<code class="computeroutput"><span class="identifier">copy_non_const_reference</span></code>
metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference" title="Class copy_non_const_reference">Class
<code class="computeroutput"><span class="identifier">copy_non_const_reference</span></code></a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">copy_non_const_reference</span></code>
is a model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
which can be used to wrap C++ functions returning a reference-to-non-const
type such that the referenced value is copied into a new Python object.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">copy_non_const_reference</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference_m"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.class_copy_non_const_reference_m" title="Class copy_non_const_reference metafunctions">Class
<code class="computeroutput"><span class="identifier">copy_non_const_reference</span></code>
metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">U</span> <span class="special">&amp;</span></code>
for some non-const <code class="computeroutput"><span class="identifier">U</span></code>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">to_python_value</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type</span></code>;
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe.example" title="Example">Example</a>
</h4></div></div></div>
<p>
C++ module definition:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">copy_non_const_reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// classes to wrap</span>
<span class="keyword">struct</span> <span class="identifier">Bar</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">struct</span> <span class="identifier">Foo</span> <span class="special">{</span>
<span class="identifier">Foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="special">{</span> <span class="identifier">b</span><span class="special">.</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">Bar</span><span class="special">&amp;</span> <span class="identifier">get_bar</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">Bar</span> <span class="identifier">b</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">// Wrapper code</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Bar</span><span class="special">&gt;(</span><span class="string">"Bar"</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Foo</span><span class="special">&gt;(</span><span class="string">"Foo"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get_bar"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">get_bar</span>
<span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">copy_non_const_reference</span><span class="special">&gt;())</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_module</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">Foo</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">create</span> <span class="identifier">a</span> <span class="identifier">Foo</span> <span class="identifier">object</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">get_bar</span><span class="special">()</span> <span class="special">#</span> <span class="identifier">make</span> <span class="identifier">a</span> <span class="identifier">copy</span> <span class="identifier">of</span> <span class="identifier">the</span> <span class="identifier">internal</span> <span class="identifier">Bar</span> <span class="identifier">object</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h" title="boost/python/manage_new_object.hpp">boost/python/manage_new_object.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object">Class
<code class="computeroutput"><span class="identifier">manage_new_object</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object_metafunc">Class
<code class="computeroutput"><span class="identifier">manage_new_object</span></code> metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object" title="Class manage_new_object">Class
<code class="computeroutput"><span class="identifier">manage_new_object</span></code></a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">manage_new_object</span></code> is
a model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
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.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">manage_new_object</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object_metafunc"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.class_manage_new_object_metafunc" title="Class manage_new_object metafunctions">Class
<code class="computeroutput"><span class="identifier">manage_new_object</span></code> metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">U</span><span class="special">*</span></code>
for some <code class="computeroutput"><span class="identifier">U</span></code>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">to_python_indirect</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h.example" title="Example">Example</a>
</h4></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">manage_new_object</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">Foo</span> <span class="special">{</span>
<span class="identifier">Foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">x</span><span class="special">(</span><span class="identifier">x</span><span class="special">){}</span>
<span class="keyword">int</span> <span class="identifier">get_x</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">Foo</span><span class="special">*</span> <span class="identifier">make_foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">new</span> <span class="identifier">Foo</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span>
<span class="comment">// Wrapper code</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"make_foo"</span><span class="special">,</span> <span class="identifier">make_foo</span><span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">manage_new_object</span><span class="special">&gt;())</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Foo</span><span class="special">&gt;(</span><span class="string">"Foo"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get_x"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Foo</span><span class="special">::</span><span class="identifier">get_x</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_module</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">make_foo</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">create</span> <span class="identifier">a</span> <span class="identifier">Foo</span> <span class="identifier">object</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">get_x</span><span class="special">()</span>
<span class="number">3</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_" title="boost/python/reference_existing_object.hpp">boost/python/reference_existing_object.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object">Class
<code class="computeroutput"><span class="identifier">reference_existing_object</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object_">Class
<code class="computeroutput"><span class="identifier">reference_existing_object</span></code>
metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object" title="Class reference_existing_object">Class
<code class="computeroutput"><span class="identifier">reference_existing_object</span></code></a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">reference_existing_object</span></code>
is a model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
which can be used to wrap C++ functions which return a reference or pointer
to a C++ object. When the wrapped function is called, the value referenced
by its return value is not copied. A new Python object is created which
contains a pointer to the referent, and no attempt is made to ensure
that the lifetime of the referent is at least as long as that of the
corresponding Python object. Thus, it can be <span class="bold"><strong>highly
dangerous</strong></span> to use <code class="computeroutput"><span class="identifier">reference_existing_object</span></code>
without additional lifetime management from such models of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
as <a class="link" href="models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_with_custodian_and_.class_with_custodian_and_ward" title="Class with_custodian_and_ward"><code class="computeroutput"><span class="identifier">with_custodian_and_ward</span></code></a>. This
class is used in the implementation of <a class="link" href="models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_internal_ref.class_template_return_internal_r" title="Class template return_internal_reference"><code class="computeroutput"><span class="identifier">return_internal_reference</span></code></a>.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">reference_existing_object</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object_"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object_" title="Class reference_existing_object metafunctions">Class
<code class="computeroutput"><span class="identifier">reference_existing_object</span></code>
metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">U</span><span class="special">&amp;</span></code>
or <code class="computeroutput"><span class="identifier">U</span><span class="special">*</span></code>
for some <code class="computeroutput"><span class="identifier">U</span></code>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">to_python_indirect</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">V</span><span class="special">&gt;</span> <span class="identifier">type</span><span class="special">;</span></code>, where V is a class whose static
execute function constructs an instance holder containing an unowned
<code class="computeroutput"><span class="identifier">U</span><span class="special">*</span></code>
pointing to the referent of the wrapped function's return value.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.example" title="Example">Example</a>
</h4></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">reference_existing_object</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">utility</span><span class="special">&gt;</span>
<span class="comment">// classes to wrap</span>
<span class="keyword">struct</span> <span class="identifier">Singleton</span>
<span class="special">{</span>
<span class="identifier">Singleton</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">x</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">int</span> <span class="identifier">exchange</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span> <span class="comment">// set x and return the old value</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">Singleton</span><span class="special">&amp;</span> <span class="identifier">get_it</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">Singleton</span> <span class="identifier">just_one</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">just_one</span><span class="special">;</span>
<span class="special">}</span>
<span class="comment">// Wrapper code</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">singleton</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"get_it"</span><span class="special">,</span> <span class="identifier">get_it</span><span class="special">,</span>
<span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">reference_existing_object</span><span class="special">&gt;());</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Singleton</span><span class="special">&gt;(</span><span class="string">"Singleton"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"exchange"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Singleton</span><span class="special">::</span><span class="identifier">exchange</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">singleton</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">s1</span> <span class="special">=</span> <span class="identifier">singleton</span><span class="special">.</span><span class="identifier">get_it</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">s2</span> <span class="special">=</span> <span class="identifier">singleton</span><span class="special">.</span><span class="identifier">get_it</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">id</span><span class="special">(</span><span class="identifier">s1</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">id</span><span class="special">(</span><span class="identifier">s2</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">s1</span> <span class="keyword">and</span> <span class="identifier">s2</span> <span class="identifier">are</span> <span class="keyword">not</span> <span class="identifier">the</span> <span class="identifier">same</span> <span class="identifier">object</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">s1</span><span class="special">.</span><span class="identifier">exchange</span><span class="special">(</span><span class="number">42</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">but</span> <span class="identifier">they</span> <span class="identifier">reference</span> <span class="identifier">the</span> <span class="identifier">same</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">Singleton</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">s2</span><span class="special">.</span><span class="identifier">exchange</span><span class="special">(</span><span class="number">99</span><span class="special">)</span>
<span class="number">42</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp" title="boost/python/return_by_value.hpp">boost/python/return_by_value.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value">Class
<code class="computeroutput"><span class="identifier">return_by_value</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value_metafuncti">Class
<code class="computeroutput"><span class="identifier">return_by_value</span></code> metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value" title="Class return_by_value">Class
<code class="computeroutput"><span class="identifier">return_by_value</span></code></a>
</h4></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">return_by_value</span></code> is a
model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
which can be used to wrap C++ functions returning any reference or value
type such that the return value is copied into a new Python object.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">return_by_value</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value_metafuncti"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.class_return_by_value_metafuncti" title="Class return_by_value metafunctions">Class
<code class="computeroutput"><span class="identifier">return_by_value</span></code> metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">to_python_value</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp.example" title="Example">Example</a>
</h4></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_by_value</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// classes to wrap</span>
<span class="keyword">struct</span> <span class="identifier">Bar</span> <span class="special">{</span> <span class="special">};</span>
<span class="identifier">Bar</span> <span class="identifier">global_bar</span><span class="special">;</span>
<span class="comment">// functions to wrap:</span>
<span class="identifier">Bar</span> <span class="identifier">b1</span><span class="special">();</span>
<span class="identifier">Bar</span><span class="special">&amp;</span> <span class="identifier">b2</span><span class="special">();</span>
<span class="identifier">Bar</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">b3</span><span class="special">();</span>
<span class="comment">// Wrapper code</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">def_void_function</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)())</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">return_by_value</span><span class="special">&gt;());</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Bar</span><span class="special">&gt;(</span><span class="string">"Bar"</span><span class="special">);</span>
<span class="identifier">def_void_function</span><span class="special">(</span><span class="string">"b1"</span><span class="special">,</span> <span class="identifier">b1</span><span class="special">);</span>
<span class="identifier">def_void_function</span><span class="special">(</span><span class="string">"b2"</span><span class="special">,</span> <span class="identifier">b2</span><span class="special">);</span>
<span class="identifier">def_void_function</span><span class="special">(</span><span class="string">"b3"</span><span class="special">,</span> <span class="identifier">b3</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_module</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">b1</span><span class="special">()</span> <span class="special">#</span> <span class="identifier">each</span> <span class="identifier">of</span> <span class="identifier">these</span> <span class="identifier">calls</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">b2</span><span class="special">()</span> <span class="special">#</span> <span class="identifier">creates</span> <span class="identifier">a</span> <span class="identifier">brand</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">b3</span><span class="special">()</span> <span class="special">#</span> <span class="keyword">new</span> <span class="identifier">Bar</span> <span class="identifier">object</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point" title="boost/python/return_opaque_pointer.hpp">boost/python/return_opaque_pointer.hpp</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaqe_pointer">Class
<code class="computeroutput"><span class="identifier">return_opaqe_pointer</span></code></a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaque_pointer_meta">Class
<code class="computeroutput"><span class="identifier">return_opaque_pointer</span></code> metafunctions</a></span></dt>
<dt><span class="section"><a href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaqe_pointer"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaqe_pointer" title="Class return_opaqe_pointer">Class
<code class="computeroutput"><span class="identifier">return_opaqe_pointer</span></code></a>
</h4></div></div></div>
<p>
return_opaque_pointer is a model of <a class="link" href="../concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept" title="ResultConverterGenerator Concept Requirements">ResultConverterGenerator</a>
which can be used to wrap C++ functions returning pointers to undefined
types such that the return value is copied into a new Python object.
</p>
<p>
In addition to specifying the <code class="computeroutput"><span class="identifier">return_opaque_pointer</span></code>
policy the <a class="link" href="../to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia" title="Macro BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(Pointee)"><code class="computeroutput"><span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span></code></a>
macro must be used to define specializations for the <a class="link" href="../utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions" title="Functions"><code class="computeroutput"><span class="identifier">type_id</span></code></a> function on the type
pointed to by returned pointer.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">return_opaque_pointer</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaque_pointer_meta"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.class_return_opaque_pointer_meta" title="Class return_opaque_pointer metafunctions">Class
<code class="computeroutput"><span class="identifier">return_opaque_pointer</span></code> metafunctions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">apply</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">detail</span><span class="special">::</span><span class="identifier">opaque_conversion_holder</span><span class="special">&lt;</span><span class="identifier">R</span><span class="special">&gt;</span>
<span class="identifier">type</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.example"></a><a class="link" href="models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point.example" title="Example">Example</a>
</h4></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor"># include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_opaque_pointer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor"># include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor"># include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor"># include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">return_value_policy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">typedef</span> <span class="keyword">struct</span> <span class="identifier">opaque_</span> <span class="special">*</span><span class="identifier">opaque</span><span class="special">;</span>
<span class="identifier">opaque</span> <span class="identifier">the_op</span> <span class="special">=</span> <span class="special">((</span><span class="identifier">opaque</span><span class="special">)</span> <span class="number">0x47110815</span><span class="special">);</span>
<span class="identifier">opaque</span> <span class="identifier">get</span> <span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">the_op</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">use</span> <span class="special">(</span><span class="identifier">opaque</span> <span class="identifier">op</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">op</span> <span class="special">!=</span> <span class="identifier">the_op</span><span class="special">)</span>
<span class="keyword">throw</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">(</span><span class="string">"failed"</span><span class="special">));</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">failuse</span> <span class="special">(</span><span class="identifier">opaque</span> <span class="identifier">op</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">op</span> <span class="special">==</span> <span class="identifier">the_op</span><span class="special">)</span>
<span class="keyword">throw</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">(</span><span class="string">"success"</span><span class="special">));</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span><span class="special">(</span><span class="identifier">opaque_</span><span class="special">)</span>
<span class="keyword">namespace</span> <span class="identifier">bpl</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">opaque_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">bpl</span><span class="special">::</span><span class="identifier">def</span> <span class="special">(</span>
<span class="string">"get"</span><span class="special">,</span> <span class="special">&amp;::</span><span class="identifier">get</span><span class="special">,</span> <span class="identifier">bpl</span><span class="special">::</span><span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">bpl</span><span class="special">::</span><span class="identifier">return_opaque_pointer</span><span class="special">&gt;());</span>
<span class="identifier">bpl</span><span class="special">::</span><span class="identifier">def</span> <span class="special">(</span><span class="string">"use"</span><span class="special">,</span> <span class="special">&amp;::</span><span class="identifier">use</span><span class="special">);</span>
<span class="identifier">bpl</span><span class="special">::</span><span class="identifier">def</span> <span class="special">(</span><span class="string">"failuse"</span><span class="special">,</span> <span class="special">&amp;::</span><span class="identifier">failuse</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="string">""</span><span class="string">"
&gt;&gt;&gt; from opaque_ext import *
&gt;&gt;&gt; #
&gt;&gt;&gt; # Check for correct conversion
&gt;&gt;&gt; use(get())
&gt;&gt;&gt; failuse(get())
Traceback (most recent call last):
...
RuntimeError: success
&gt;&gt;&gt; #
&gt;&gt;&gt; # Check that there is no conversion from integers ...
&gt;&gt;&gt; use(0)
Traceback (most recent call last):
...
TypeError: bad argument type for built-in operation
&gt;&gt;&gt; #
&gt;&gt;&gt; # ... and from strings to opaque objects
&gt;&gt;&gt; use("</span><span class="string">")
Traceback (most recent call last):
...
TypeError: bad argument type for built-in operation
"</span><span class="string">""</span>
<span class="identifier">def</span> <span class="identifier">run</span><span class="special">(</span><span class="identifier">args</span> <span class="special">=</span> <span class="identifier">None</span><span class="special">):</span>
<span class="identifier">import</span> <span class="identifier">sys</span>
<span class="identifier">import</span> <span class="identifier">doctest</span>
<span class="keyword">if</span> <span class="identifier">args</span> <span class="identifier">is</span> <span class="keyword">not</span> <span class="identifier">None</span><span class="special">:</span>
<span class="identifier">sys</span><span class="special">.</span><span class="identifier">argv</span> <span class="special">=</span> <span class="identifier">args</span>
<span class="keyword">return</span> <span class="identifier">doctest</span><span class="special">.</span><span class="identifier">testmod</span><span class="special">(</span><span class="identifier">sys</span><span class="special">.</span><span class="identifier">modules</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">__name__</span><span class="special">))</span>
<span class="keyword">if</span> <span class="identifier">__name__</span> <span class="special">==</span> <span class="char">'__main__'</span><span class="special">:</span>
<span class="identifier">print</span> <span class="string">"running..."</span>
<span class="identifier">import</span> <span class="identifier">sys</span>
<span class="identifier">sys</span><span class="special">.</span><span class="identifier">exit</span><span class="special">(</span><span class="identifier">run</span><span class="special">()[</span><span class="number">0</span><span class="special">])</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="models_of_resultconverter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../to_from_python_type_conversion.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,80 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;9.&#160;Glossary</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="topics/indexing_support.html" title="Indexing support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="topics/indexing_support.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="glossary"></a>Chapter&#160;9.&#160;Glossary</h1></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">arity <a name="arity"></a></span></dt>
<dd><p>
The number of argumnts accepted by a function or member function. Unless
otherwise specified, the hidden <code class="computeroutput"><span class="keyword">this</span></code>
argument to member functions is not counted when specifying arity.
</p></dd>
<dt><span class="term">ntbs <a name="ntbs"></a></span></dt>
<dd><p>
Null-Terminated Byte String, or 'C'-string. C++ string literals are
<span class="bold"><strong>ntbs</strong></span>es. An <span class="bold"><strong>ntbs</strong></span>
must never be null.
</p></dd>
<dt><span class="term">raise <a name="raise"></a></span></dt>
<dd><p>
Exceptions in Python are "raised", not "thrown",
as they are in C++. When this documentation says that some Python exception
is "raised" in the context of C++ code, it means that the corresponding
Python exception is set via the <a href="http://www.python.org/doc/current/api/exceptionHandling.html" target="_top">Python/'C'
API</a>, and <code class="computeroutput"><span class="identifier">throw_error_already_set</span><span class="special">()</span></code> is called.
</p></dd>
<dt><span class="term">POD <a name="pod"></a></span></dt>
<dd><p>
A technical term from the C++ standard. Short for "Plain Ol'Data":
A POD-struct is an aggregate class that has no non-static data members
of type pointer to member, non-POD-struct, non-POD-union (or array of
such types) or reference, and has no user-defined copy assign- ment operator
and no user-defined destructor. Similarly, a POD-union is an aggregate
union that has no non-static data members of type pointer to member,
non-POD-struct, non-POD-union (or array of such types) or reference,
and has no user-defined copy assignment operator and no user-defined
destructor. A POD class is a class that is either a POD-struct or a POD-union.
An aggregate is an array or a class (clause 9) with no user-declared
constructors (12.1), no private or protected non-static data members
(clause 11), no base classes (clause 10), and no virtual functions (10.3).
</p></dd>
<dt><span class="term">ODR <a name="odr"></a></span></dt>
<dd><p>
The "One Definition Rule", which says that any entity in a
C++ program must have the same definition in all translation units (object
files) which make up a program.
</p></dd>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="topics/indexing_support.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/def.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="next" href="boost_python_def_visitor_hpp.html" title="boost/python/def_visitor.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../high_level_components.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_def_visitor_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_def_hpp"></a><a class="link" href="boost_python_def_hpp.html" title="boost/python/def.hpp">boost/python/def.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_hpp.introduction"></a><a class="link" href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">def</span><span class="special">()</span></code>
is the function which can be used to expose C++ functions and callable
objects as Python functions in the <a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction" title="Introduction">current
scope</a>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_hpp.functions"></a><a class="link" href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A3</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">def</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Fn</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A3</span> <span class="keyword">const</span><span class="special">&amp;);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd>
<p>
name is an <a class="link" href="../glossary.html#ntbs">ntbs</a> which conforms to Python's
<a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
naming rules</a>.
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If <code class="computeroutput"><span class="identifier">Fn</span></code> is [derived
from] <a class="link" href="../object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object">object</a>,
it will be added to the <a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction" title="Introduction">current
scope</a> as a single overload. To be useful, <code class="computeroutput"><span class="identifier">fn</span></code> should be <a href="http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-6" target="_top">callable</a>.
</li>
<li class="listitem">
<p class="simpara">
If <code class="computeroutput"><span class="identifier">a1</span></code> is the
result of an <a class="link" href="../function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">overload-dispatch-expression</a>,
only the second form is allowed and <code class="computeroutput"><span class="identifier">fn</span></code>
must be a pointer to function or pointer to member function whose
<a class="link" href="../glossary.html#arity">arity</a> is the same as A1's <a class="link" href="../function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">maximum
arity</a>.
</p>
<p class="simpara">
<span class="bold"><strong>Effects:</strong></span> For each prefix <code class="computeroutput"><span class="identifier">P</span></code> of <code class="computeroutput"><span class="identifier">Fn</span></code>'s
sequence of argument types, beginning with the one whose length
is <code class="computeroutput"><span class="identifier">A1</span></code>'s <a class="link" href="../function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction.overload_dispatch_expressions" title="overload-dispatch-expressions">minimum
arity</a>, adds a <code class="computeroutput"><span class="identifier">name</span><span class="special">(...)</span></code> function overload to the
<a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction" title="Introduction">current
scope</a>. Each overload generated invokes a1's call-expression
with P, using a copy of a1's call policies. If the longest valid
prefix of A1 contains N types and a1 holds M keywords, an initial
sequence of the keywords are used for all but the first N - M
arguments of each overload.
</p>
</li>
<li class="listitem">
<p class="simpara">
Otherwise, fn must be a non-null function or member function
pointer, and a single function overload built around fn is added
to the current scope. If any of a1-a3 are supplied, they may
be selected in any order from the table below.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Mnemonic Name
</p>
</th>
<th>
<p>
Requirements/Type properties
</p>
</th>
<th>
<p>
Effects
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
docstring
</p>
</td>
<td>
<p>
Any <a class="link" href="../glossary.html#ntbs">ntbs</a>
</p>
</td>
<td>
<p>
Value will be bound to the <code class="computeroutput"><span class="identifier">__doc__</span></code>
attribute of the resulting method overload.
</p>
</td>
</tr>
<tr>
<td>
<p>
policies
</p>
</td>
<td>
<p>
A model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
</p>
</td>
<td>
<p>
A copy will be used as the call policies of the resulting
method overload.
</p>
</td>
</tr>
<tr>
<td>
<p>
keywords
</p>
</td>
<td>
<p>
The result of a <a class="link" href="../function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expression</a>
specifying no more arguments than the <a class="link" href="../glossary.html#arity">arity</a>
of <code class="computeroutput"><span class="identifier">fn</span></code>.
</p>
</td>
<td>
<p>
A copy will be used as the call policies of the resulting
method overload.
</p>
</td>
</tr>
</tbody>
</table></div>
</li>
</ul></div>
</dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_hpp.example"></a><a class="link" href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">args</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"foo"</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">def_test</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span> <span class="string">"y"</span><span class="special">),</span> <span class="string">"foo's docstring"</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../high_level_components.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_def_visitor_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,208 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/def_visitor.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_def_hpp.html" title="boost/python/def.hpp">
<link rel="next" href="boost_python_docstring_options_h.html" title="boost/python/docstring_options.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_docstring_options_h.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_def_visitor_hpp"></a><a class="link" href="boost_python_def_visitor_hpp.html" title="boost/python/def_visitor.hpp">boost/python/def_visitor.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor">Class
<code class="computeroutput"><span class="identifier">def_visitor</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.introduction"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/def_visitor.hpp&gt; provides a generic visitation interface
through which the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
def member functionality can be extended non-intrusively to avoid cluttering
the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
interface. It declares the <code class="computeroutput"><span class="identifier">def_visitor</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> class template, which is parameterized
on the derived type <code class="computeroutput"><span class="identifier">DerivedVisitor</span></code>,
which provides the actual <code class="computeroutput"><span class="identifier">def</span></code>
functionality through its <code class="computeroutput"><span class="identifier">visit</span></code>
member functions.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.class_def_visitor"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor" title="Class def_visitor">Class
<code class="computeroutput"><span class="identifier">def_visitor</span></code></a>
</h3></div></div></div>
<p>
The class <code class="computeroutput"><span class="identifier">def_visitor</span></code> is
a base class paramaterized by its derived class. The <code class="computeroutput"><span class="identifier">def_visitor</span></code>
class is a protocol class. Its derived class, DerivedVisitor, is expected
to have a member function <code class="computeroutput"><span class="identifier">visit</span></code>.
The <code class="computeroutput"><span class="identifier">def_visitor</span></code> class is
never instantiated directly. Instead, an instance of its subclass, DerivedVisitor,
is passed on as an argument to the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
<code class="computeroutput"><span class="identifier">def</span></code> member function.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">DerivedVisitor</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">def_visitor</span> <span class="special">{};</span>
<span class="special">}</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd>
<p>
The client supplied class DerivedVisitor template parameter is expected
to: * be privately derived from def_visitor * grant friend access
to class def_visitor_access * define either or both visit member
functions listed in the table below:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Return Type
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Effects
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">visitor</span><span class="special">.</span><span class="identifier">visit</span><span class="special">(</span><span class="identifier">cls</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">void</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">cls</span></code> is
an instance of a <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
being wrapped to Python. <code class="computeroutput"><span class="identifier">visitor</span></code>
is a <code class="computeroutput"><span class="identifier">def_visitor</span></code>
derived class.
</p>
</td>
<td>
<p>
A call to <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">)</span></code> forwards to this member
function.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">visitor</span><span class="special">.</span><span class="identifier">visit</span><span class="special">(</span><span class="identifier">cls</span><span class="special">,</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">options</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">void</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">cls</span></code> is
a <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
instance, name is a C string. <code class="computeroutput"><span class="identifier">visitor</span></code>
is a <code class="computeroutput"><span class="identifier">def_visitor</span></code>
derived class. options is a context specific optional argument.
</p>
</td>
<td>
<p>
A call to <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">visitor</span><span class="special">)</span></code> or <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">visitor</span><span class="special">,</span> <span class="identifier">options</span><span class="special">)</span></code> forwards to this member
function.
</p>
</td>
</tr>
</tbody>
</table></div>
</dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.example"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">{/*...*/};</span>
<span class="keyword">class</span> <span class="identifier">my_def_visitor</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">def_visitor</span><span class="special">&lt;</span><span class="identifier">my_def_visitor</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">friend</span> <span class="keyword">class</span> <span class="identifier">def_visitor_access</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">classT</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">visit</span><span class="special">(</span><span class="identifier">classT</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="identifier">c</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_def_visitor</span><span class="special">::</span><span class="identifier">foo</span><span class="special">);</span>
<span class="identifier">c</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_def_visitor</span><span class="special">::</span><span class="identifier">bar</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">self</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">bar</span><span class="special">(</span><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">self</span><span class="special">);</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">my_def_visitor</span><span class="special">());</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_docstring_options_h.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,363 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/docstring_options.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_def_visitor_hpp.html" title="boost/python/def_visitor.hpp">
<link rel="next" href="boost_python_enum_hpp.html" title="boost/python/enum.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_visitor_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_enum_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_docstring_options_h"></a><a class="link" href="boost_python_docstring_options_h.html" title="boost/python/docstring_options.hpp">boost/python/docstring_options.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_dostring_options_construct">Class
dostring_options constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_destruct">Class
docstring_options destructor</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_modifier">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code> modifier
functions</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.introduction"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Boost.Python supports user-defined docstrings with automatic appending
of C++ signatures. These features are enabled by default. The class docstring_options
is available to selectively suppress the user-defined docstrings, signatures,
or both.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.class_docstring_options"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options" title="Class docstring_options">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code></a>
</h3></div></div></div>
<p>
Controls the appearance of docstrings of wrapped functions and member functions
for the life-time of the instance. The instances are noncopyable to eliminate
the possibility of surprising side effects.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">docstring_options</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_all</span><span class="special">=</span><span class="keyword">true</span><span class="special">);</span>
<span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_user_defined</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_signatures</span><span class="special">);</span>
<span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_user_defined</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_py_signatures</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_cpp_signatures</span><span class="special">);</span>
<span class="special">~</span><span class="identifier">docstring_options</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_user_defined</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_user_defined</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_py_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_py_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_cpp_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_cpp_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_all</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_all</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.class_dostring_options_construct"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_dostring_options_construct" title="Class dostring_options constructors">Class
dostring_options constructors</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_all</span><span class="special">=</span><span class="keyword">true</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Constructs a docstring_options object which controls the appearance
of function and member-function docstrings defined in the code that
follows. If show_all is true, both the user-defined docstrings and
the automatically generated Python and C++ signatures are shown.
If show_all is false the <code class="computeroutput"><span class="identifier">__doc__</span></code>
attributes are <code class="computeroutput"><span class="identifier">None</span></code>.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_user_defined</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_signatures</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Constructs a <code class="computeroutput"><span class="identifier">docstring_options</span></code>
object which controls the appearance of function and member-function
docstrings defined in the code that follows. Iff <code class="computeroutput"><span class="identifier">show_user_defined</span></code>
is <code class="computeroutput"><span class="keyword">true</span></code>, the user-defined
docstrings are shown. Iff <code class="computeroutput"><span class="identifier">show_signatures</span></code>
is <code class="computeroutput"><span class="keyword">true</span></code>, Python and
C++ signatures are automatically added. If both <code class="computeroutput"><span class="identifier">show_user_defined</span></code>
and <code class="computeroutput"><span class="identifier">show_signatures</span></code>
are <code class="computeroutput"><span class="keyword">false</span></code>, the <code class="computeroutput"><span class="identifier">__doc__</span></code> attributes are <code class="computeroutput"><span class="identifier">None</span></code>.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">docstring_options</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">show_user_defined</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_py_signatures</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">show_cpp_signatures</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Constructs a <code class="computeroutput"><span class="identifier">docstring_options</span></code>
object which controls the appearance of function and member-function
docstrings defined in the code that follows. Iff <code class="computeroutput"><span class="identifier">show_user_defined</span></code>
is <code class="computeroutput"><span class="keyword">true</span></code>, the user-defined
docstrings are shown. Iff <code class="computeroutput"><span class="identifier">show_py_signatures</span></code>
is <code class="computeroutput"><span class="keyword">true</span></code>, Python signatures
are automatically added. Iff <code class="computeroutput"><span class="identifier">show_cpp_signatures</span></code>
is true, C++ signatures are automatically added. If all parameters
are <code class="computeroutput"><span class="keyword">false</span></code>, the <code class="computeroutput"><span class="identifier">__doc__</span></code> attributes are <code class="computeroutput"><span class="identifier">None</span></code>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.class_docstring_options_destruct"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_destruct" title="Class docstring_options destructor">Class
docstring_options destructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="special">~</span><span class="identifier">docstring_options</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Restores the previous state of the docstring options. In particular,
if <code class="computeroutput"><span class="identifier">docstring_options</span></code>
instances are in nested C++ scopes the settings effective in the
enclosing scope are restored. If the last <code class="computeroutput"><span class="identifier">docstring_options</span></code>
instance goes out of scope the default "all on" settings
are restored.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.class_docstring_options_modifier"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_modifier" title="Class docstring_options modifier functions">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code> modifier
functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">disable_user_defined</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_user_defined</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_py_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_py_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_cpp_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_cpp_signatures</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">disable_all</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">enable_all</span><span class="special">();</span>
</pre>
<p>
These member functions dynamically change the appearance of docstrings
in the code that follows. The <code class="computeroutput"><span class="special">*</span><span class="identifier">_user_defined</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="special">*</span><span class="identifier">_signatures</span><span class="special">()</span></code> member functions are provided for fine-grained
control. The <code class="computeroutput"><span class="special">*</span><span class="identifier">_all</span><span class="special">()</span></code> member functions are convenient shortcuts
to manipulate all settings simultaneously.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_docstring_options_h.example"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example" title="Example">Example</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.docstring_options_defined_at_com">Docstring
options defined at compile time</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.selective_suppressions">Selective
suppressions</a></span></dt>
<dt><span class="section"><a href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.wrapping_from_multiple_c_scopes">Wrapping
from multiple C++ scopes</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_docstring_options_h.example.docstring_options_defined_at_com"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.docstring_options_defined_at_com" title="Docstring options defined at compile time">Docstring
options defined at compile time</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">docstring_options</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span> <span class="special">{}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">demo</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">docstring_options</span> <span class="identifier">doc_options</span><span class="special">(</span><span class="identifier">DEMO_DOCSTRING_SHOW_ALL</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="string">"foo doc"</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
If compiled with <code class="computeroutput"><span class="special">-</span><span class="identifier">DDEMO_DOCSTRING_SHOW_ALL</span><span class="special">=</span><span class="keyword">true</span></code>:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">demo</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo</span><span class="special">()</span> <span class="special">-&gt;</span> <span class="identifier">None</span> <span class="special">:</span> <span class="identifier">foo</span> <span class="identifier">doc</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="identifier">foo</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">void</span>
</pre>
<p>
If compiled with <code class="computeroutput"><span class="special">-</span><span class="identifier">DDEMO_DOCSTRING_SHOW_ALL</span><span class="special">=</span><span class="keyword">false</span></code>:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">demo</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">None</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_docstring_options_h.example.selective_suppressions"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.selective_suppressions" title="Selective suppressions">Selective
suppressions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">args</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">docstring_options</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">foo1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">foo2</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">l</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">l</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">foo3</span><span class="special">(</span><span class="keyword">float</span> <span class="identifier">f</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">f</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">foo4</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">d</span><span class="special">);</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">demo</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">docstring_options</span> <span class="identifier">doc_options</span><span class="special">;</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo1"</span><span class="special">,</span> <span class="identifier">foo1</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"i"</span><span class="special">),</span> <span class="string">"foo1 doc"</span><span class="special">);</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">disable_user_defined</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo2"</span><span class="special">,</span> <span class="identifier">foo2</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"l"</span><span class="special">),</span> <span class="string">"foo2 doc"</span><span class="special">);</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">disable_signatures</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo3"</span><span class="special">,</span> <span class="identifier">foo3</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"f"</span><span class="special">),</span> <span class="string">"foo3 doc"</span><span class="special">);</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">enable_user_defined</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo4"</span><span class="special">,</span> <span class="identifier">foo4</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"d"</span><span class="special">),</span> <span class="string">"foo4 doc"</span><span class="special">);</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">enable_py_signatures</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo5"</span><span class="special">,</span> <span class="identifier">foo4</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"d"</span><span class="special">),</span> <span class="string">"foo5 doc"</span><span class="special">);</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">disable_py_signatures</span><span class="special">();</span>
<span class="identifier">doc_options</span><span class="special">.</span><span class="identifier">enable_cpp_signatures</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo6"</span><span class="special">,</span> <span class="identifier">foo4</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"d"</span><span class="special">),</span> <span class="string">"foo6 doc"</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">demo</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo1</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo1</span><span class="special">(</span> <span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="identifier">i</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span> <span class="special">:</span> <span class="identifier">foo1</span> <span class="identifier">doc</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="identifier">foo1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo2</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo2</span><span class="special">(</span> <span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="identifier">l</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span> <span class="special">:</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="identifier">foo2</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">l</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo3</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">None</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo4</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo4</span> <span class="identifier">doc</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo5</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo5</span><span class="special">(</span> <span class="special">(</span><span class="keyword">float</span><span class="special">)</span><span class="identifier">d</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span> <span class="special">:</span> <span class="identifier">foo5</span> <span class="identifier">doc</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo6</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">foo6</span> <span class="identifier">doc</span>
<span class="identifier">C</span><span class="special">++</span> <span class="identifier">signature</span><span class="special">:</span>
<span class="identifier">foo6</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">int</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_docstring_options_h.example.wrapping_from_multiple_c_scopes"></a><a class="link" href="boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example.wrapping_from_multiple_c_scopes" title="Wrapping from multiple C++ scopes">Wrapping
from multiple C++ scopes</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">args</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">docstring_options</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">foo1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">foo2</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">l</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">l</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">bar1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">bar2</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">l</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">l</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">namespace</span> <span class="special">{</span>
<span class="keyword">void</span> <span class="identifier">wrap_foos</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// no docstring_options here</span>
<span class="comment">// -&gt; settings from outer C++ scope are in effect</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo1"</span><span class="special">,</span> <span class="identifier">foo1</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"i"</span><span class="special">),</span> <span class="string">"foo1 doc"</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo2"</span><span class="special">,</span> <span class="identifier">foo2</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"l"</span><span class="special">),</span> <span class="string">"foo2 doc"</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">wrap_bars</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">show_user_defined</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">show_signatures</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
<span class="identifier">docstring_options</span> <span class="identifier">doc_options</span><span class="special">(</span><span class="identifier">show_user_defined</span><span class="special">,</span> <span class="identifier">show_signatures</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"bar1"</span><span class="special">,</span> <span class="identifier">bar1</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"i"</span><span class="special">),</span> <span class="string">"bar1 doc"</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"bar2"</span><span class="special">,</span> <span class="identifier">bar2</span><span class="special">,</span> <span class="identifier">arg</span><span class="special">(</span><span class="string">"l"</span><span class="special">),</span> <span class="string">"bar2 doc"</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">demo</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">docstring_options</span> <span class="identifier">doc_options</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
<span class="identifier">wrap_foos</span><span class="special">();</span>
<span class="identifier">wrap_bars</span><span class="special">();</span>
<span class="special">}</span>
</pre>
<p>
Python code:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">demo</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo1</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">None</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">foo2</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">None</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">bar1</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">bar1</span> <span class="identifier">doc</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">print</span> <span class="identifier">demo</span><span class="special">.</span><span class="identifier">bar2</span><span class="special">.</span><span class="identifier">__doc__</span>
<span class="identifier">bar2</span> <span class="identifier">doc</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_visitor_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_enum_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,217 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/enum.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_docstring_options_h.html" title="boost/python/docstring_options.hpp">
<link rel="next" href="boost_python_errors_hpp.html" title="boost/python/errors.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_docstring_options_h.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_errors_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_enum_hpp"></a><a class="link" href="boost_python_enum_hpp.html" title="boost/python/enum.hpp">boost/python/enum.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_constructors">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_modifier_fun">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> modifier functions</a></span></dt>
<dt><span class="section"><a href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_enum_hpp.introduction"></a><a class="link" href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/enum.hpp&gt; defines the interface through which users
expose their C++ enumeration types to Python. It declares the <code class="computeroutput"><span class="identifier">enum_</span></code> class template, which is parameterized
on the enumeration type being exposed.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_enum_hpp.class_template_enum"></a><a class="link" href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum" title="Class template enum_">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code></a>
</h3></div></div></div>
<p>
Creates a Python class derived from Python's <code class="computeroutput"><span class="keyword">int</span></code>
type which is associated with the C++ type passed as its first parameter.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">enum_</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="identifier">enum_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">value</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span><span class="special">);</span>
<span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">export_values</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_enum_hpp.class_template_enum_constructors"></a><a class="link" href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_constructors" title="Class template enum_ constructors">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> constructors</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">enum_</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">=</span><span class="number">0</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
name is an <a class="link" href="../glossary.html#ntbs">ntbs</a> which conforms to Python's
<a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
naming rules</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Constructs an <code class="computeroutput"><span class="identifier">enum_</span></code>
object holding a Python extension type derived from <code class="computeroutput"><span class="keyword">int</span></code> which is named <code class="computeroutput"><span class="identifier">name</span></code>.
The named attribute of the <a class="link" href="boost_python_scope_hpp.html" title="boost/python/scope.hpp">current
scope</a> is bound to the new extension type.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_enum_hpp.class_template_enum_modifier_fun"></a><a class="link" href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_modifier_fun" title="Class template enum_ modifier functions">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> modifier functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">value</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
name is an <a class="link" href="../glossary.html#ntbs">ntbs</a> which conforms to Python's
<a href="http://www.python.org/doc/current/ref/identifiers.html" target="_top">identifier
naming rules</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
adds an instance of the wrapped enumeration type with value x to
the type's dictionary as the named attribute.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">export_values</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
sets attributes in the <a class="link" href="boost_python_scope_hpp.html" title="boost/python/scope.hpp">current
scope</a> with the same names and values as all enumeration values
exposed so far by calling value().
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_enum_hpp.example"></a><a class="link" href="boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
C++ module definition
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">enum</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">enum</span> <span class="identifier">color</span> <span class="special">{</span> <span class="identifier">red</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">green</span> <span class="special">=</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">blue</span> <span class="special">=</span> <span class="number">4</span> <span class="special">};</span>
<span class="identifier">color</span> <span class="identifier">identity_</span><span class="special">(</span><span class="identifier">color</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">enums</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">color</span><span class="special">&gt;(</span><span class="string">"color"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"red"</span><span class="special">,</span> <span class="identifier">red</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"green"</span><span class="special">,</span> <span class="identifier">green</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">export_values</span><span class="special">()</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"blue"</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">)</span>
<span class="special">;</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"identity"</span><span class="special">,</span> <span class="identifier">identity_</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
Interactive Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">enums</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">red</span><span class="special">)</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">red</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">red</span><span class="special">)</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">red</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">green</span><span class="special">)</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">green</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">green</span><span class="special">)</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">green</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">blue</span><span class="special">)</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">"&lt;stdin&gt;"</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">?</span>
<span class="identifier">NameError</span><span class="special">:</span> <span class="identifier">name</span> <span class="char">'blue'</span> <span class="identifier">is</span> <span class="keyword">not</span> <span class="identifier">defined</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">blue</span><span class="special">)</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">blue</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">(</span><span class="number">1</span><span class="special">))</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">red</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">(</span><span class="number">2</span><span class="special">))</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">green</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">(</span><span class="number">3</span><span class="special">))</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">(</span><span class="number">3</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">color</span><span class="special">(</span><span class="number">4</span><span class="special">))</span>
<span class="identifier">enums</span><span class="special">.</span><span class="identifier">color</span><span class="special">.</span><span class="identifier">blue</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">identity</span><span class="special">(</span><span class="number">1</span><span class="special">)</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">"&lt;stdin&gt;"</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">?</span>
<span class="identifier">TypeError</span><span class="special">:</span> <span class="identifier">bad</span> <span class="identifier">argument</span> <span class="identifier">type</span> <span class="keyword">for</span> <span class="identifier">built</span><span class="special">-</span><span class="identifier">in</span> <span class="identifier">operation</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_docstring_options_h.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_errors_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,278 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/errors.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_enum_hpp.html" title="boost/python/enum.hpp">
<link rel="next" href="boost_python_exception_translato.html" title="boost/python/exception_translator.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_enum_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_exception_translato.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_errors_hpp"></a><a class="link" href="boost_python_errors_hpp.html" title="boost/python/errors.hpp">boost/python/errors.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set">Class
<code class="computeroutput"><span class="identifier">error_already_set</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_errors_hpp.introduction"></a><a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/errors.hpp&gt; provides types and functions for managing
and translating between Python and C++ exceptions. This is relatively low-level
functionality that is mostly used internally by Boost.Python. Users should
seldom need it.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_errors_hpp.class_error_already_set"></a><a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set" title="Class error_already_set">Class
<code class="computeroutput"><span class="identifier">error_already_set</span></code></a>
</h3></div></div></div>
<p>
error_already_set is an exception type which can be thrown to indicate
that a Python error has occurred. If thrown, the precondition is that
<a href="http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71" target="_top">PyErr_Occurred()</a>
returns a value convertible to <code class="computeroutput"><span class="keyword">true</span></code>.
Portable code shouldn't throw this exception type directly, but should
instead use <a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions" title="Functions">throw_error_already_set()</a>,
below.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">error_already_set</span> <span class="special">{};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_errors_hpp.functions"></a><a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">bool</span> <span class="identifier">handle_exception</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">f</span><span class="special">)</span> <span class="keyword">throw</span><span class="special">();</span>
<span class="keyword">void</span> <span class="identifier">handle_exception</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The first form requires that the expression function0&lt;void&gt;(f)
is valid. The second form requires that a C++ exception is currently
being handled (see section 15.1 in the C++ standard).
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
The first form calls f() inside a try block which first attempts
to use all registered <a class="link" href="boost_python_exception_translato.html" title="boost/python/exception_translator.hpp">exception
translators</a>. If none of those translates the exception, the
catch clauses then set an appropriate Python exception for the C++
exception caught, returning true if an exception was thrown, false
otherwise. The second form passes a function which rethrows the exception
currently being handled to the first form.
</p></dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
No exception is being handled
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
At inter-language boundaries it is important to ensure that no C++
exceptions escape, since the calling language usually doesn't have
the equipment necessary to properly unwind the stack. Use handle_exception
to manage exception translation whenever your C++ code is called
directly from the Python API. This is done for you automatically
by the usual function wrapping facilities: <a class="link" href="../function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions" title="Functions">make_function()</a>,
<a class="link" href="../function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions" title="Functions">make_constructor()</a>,
<a class="link" href="boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.functions" title="Functions">def()</a>
and <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel.class_template_class_modifier_fu" title="Class template class_ modifier functions">class_::def()</a>.
The second form can be more convenient to use (see the example below),
but various compilers have problems when exceptions are rethrown
from within an enclosing try block.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">expect_non_null</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">x</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
x
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
error_already_set() iff x == 0.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Simplifies error-handling when calling functions in the Python/C
API which return 0 on error.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">throw_error_already_set</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
throw error_already_set();
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Simplifies error-handling when calling functions in the Python/C
API which return 0 on error.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">throw_error_already_set</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
throw error_already_set();
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Many platforms and compilers are not able to consistently catch exceptions
thrown across shared library boundaries. Using this function from
the Boost.Python library ensures that the appropriate catch block
in handle_exception() can catch the exception.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_errors_hpp.example"></a><a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">errors</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">object</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">handle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// Returns a std::string which has the same value as obj's "__name__"</span>
<span class="comment">// attribute.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">get_name</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">obj</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// throws if there's no __name__ attribute</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">expect_non_null</span><span class="special">(</span>
<span class="identifier">PyObject_GetAttrString</span><span class="special">(</span><span class="identifier">obj</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">(),</span> <span class="string">"__name__"</span><span class="special">));</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">s</span> <span class="special">=</span> <span class="identifier">PyString_AsString</span><span class="special">(</span><span class="identifier">p</span><span class="special">);</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">s</span> <span class="special">!=</span> <span class="number">0</span><span class="special">)</span>
<span class="identifier">Py_DECREF</span><span class="special">(</span><span class="identifier">p</span><span class="special">);</span>
<span class="comment">// throws if it's not a Python string</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">result</span><span class="special">(</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">expect_non_null</span><span class="special">(</span>
<span class="identifier">PyString_AsString</span><span class="special">(</span><span class="identifier">p</span><span class="special">)));</span>
<span class="identifier">Py_DECREF</span><span class="special">(</span><span class="identifier">p</span><span class="special">);</span> <span class="comment">// Done with p</span>
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
<span class="special">}</span>
<span class="comment">//</span>
<span class="comment">// Demonstrate form 1 of handle_exception</span>
<span class="comment">//</span>
<span class="comment">// Place into result a Python Int object whose value is 1 if a and b have</span>
<span class="comment">// identical "__name__" attributes, 0 otherwise.</span>
<span class="keyword">void</span> <span class="identifier">same_name_impl</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*&amp;</span> <span class="identifier">result</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">result</span> <span class="special">=</span> <span class="identifier">PyInt_FromLong</span><span class="special">(</span>
<span class="identifier">get_name</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">get_name</span><span class="special">(</span><span class="identifier">a2</span><span class="special">));</span>
<span class="special">}</span>
<span class="identifier">object</span> <span class="identifier">borrowed_object</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span><span class="special">(</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">a1</span><span class="special">)));</span>
<span class="special">}</span>
<span class="comment">// This is an example Python 'C' API interface function</span>
<span class="keyword">extern</span> <span class="string">"C"</span> <span class="identifier">PyObject</span><span class="special">*</span>
<span class="identifier">same_name</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">keywords</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">a1</span><span class="special">;</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">a2</span><span class="special">;</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">PyArg_ParseTuple</span><span class="special">(</span><span class="identifier">args</span><span class="special">,</span> <span class="keyword">const_cast</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">*&gt;(</span><span class="string">"OO"</span><span class="special">),</span> <span class="special">&amp;</span><span class="identifier">a1</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">a2</span><span class="special">))</span>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="comment">// Use boost::bind to make an object compatible with</span>
<span class="comment">// boost::Function0&lt;void&gt;</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle_exception</span><span class="special">(</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(</span><span class="identifier">same_name_impl</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">result</span><span class="special">),</span> <span class="identifier">borrowed_object</span><span class="special">(</span><span class="identifier">a1</span><span class="special">),</span> <span class="identifier">borrowed_object</span><span class="special">(</span><span class="identifier">a2</span><span class="special">))))</span>
<span class="special">{</span>
<span class="comment">// an exception was thrown; the Python error was set by</span>
<span class="comment">// handle_exception()</span>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
<span class="special">}</span>
<span class="comment">//</span>
<span class="comment">// Demonstrate form 2 of handle_exception. Not well-supported by all</span>
<span class="comment">// compilers.</span>
<span class="comment">//</span>
<span class="keyword">extern</span> <span class="string">"C"</span> <span class="identifier">PyObject</span><span class="special">*</span>
<span class="identifier">same_name2</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">keywords</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">a1</span><span class="special">;</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">a2</span><span class="special">;</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">PyArg_ParseTuple</span><span class="special">(</span><span class="identifier">args</span><span class="special">,</span> <span class="keyword">const_cast</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">*&gt;(</span><span class="string">"OO"</span><span class="special">),</span> <span class="special">&amp;</span><span class="identifier">a1</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">a2</span><span class="special">))</span>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">try</span> <span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">PyInt_FromLong</span><span class="special">(</span>
<span class="identifier">get_name</span><span class="special">(</span><span class="identifier">borrowed_object</span><span class="special">(</span><span class="identifier">a1</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">get_name</span><span class="special">(</span><span class="identifier">borrowed_object</span><span class="special">(</span><span class="identifier">a2</span><span class="special">)));</span>
<span class="special">}</span>
<span class="keyword">catch</span><span class="special">(...)</span>
<span class="special">{</span>
<span class="comment">// If an exception was thrown, translate it to Python</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle_exception</span><span class="special">();</span>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_enum_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_exception_translato.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,130 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/exception_translator.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_errors_hpp.html" title="boost/python/errors.hpp">
<link rel="next" href="boost_python_init_hpp.html" title="boost/python/init.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_errors_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_init_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_exception_translato"></a><a class="link" href="boost_python_exception_translato.html" title="boost/python/exception_translator.hpp">boost/python/exception_translator.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.function_register_exception_tran">Function
<code class="computeroutput"><span class="identifier">register_exception_translator</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_exception_translato.introduction"></a><a class="link" href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
As described <a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.introduction" title="Introduction">here</a>,
it is important to make sure that exceptions thrown by C++ code do not
pass into the Python interpreter core. By default, Boost.Python translates
all C++ exceptions thrown by wrapped functions and module init functions
into Python, but the default translators are extremely limited: most C++
exceptions will appear in Python as a <a href="http://www.python.org/doc/current/lib/module-exceptions.html" target="_top">RuntimeError</a>
exception whose representation is 'Unidentifiable C++ Exception'. To produce
better error messages, users can register additional exception translators
as described below.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_exception_translato.function_register_exception_tran"></a><a class="link" href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.function_register_exception_tran" title="Function register_exception_translator">Function
<code class="computeroutput"><span class="identifier">register_exception_translator</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">ExceptionType</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Translate</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">register_exception_translator</span><span class="special">(</span><span class="identifier">Translate</span> <span class="identifier">translate</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd>
<p>
Translate is CopyConstructible, and the following code must be well-formed:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">ExceptionType</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">translate</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span></pre>
<p>
. The expression <code class="computeroutput"><span class="identifier">translate</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> must either throw a C++ exception,
or a subsequent call to <code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span></code> must return 1.
</p>
</dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Adds a copy of translate to the sequence of exception translators
tried when Boost.Python catches an exception that is about to pass
into Python's core interpreter. The new translator will get "first
shot" at translating all exceptions matching the catch clause
shown above. Any subsequently-registered translators will be allowed
to translate the exception earlier. A translator which cannot translate
a given C++ exception can re-throw it, and it will be handled by
a translator which was registered earlier (or by the default translator).
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_exception_translato.example"></a><a class="link" href="boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">exception_translator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">exception</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">my_exception</span> <span class="special">:</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span>
<span class="special">{</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">what</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"One of my exceptions"</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
<span class="keyword">void</span> <span class="identifier">translate</span><span class="special">(</span><span class="identifier">my_exception</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// Use the Python 'C' API to set up an exception object</span>
<span class="identifier">PyErr_SetString</span><span class="special">(</span><span class="identifier">PyExc_RuntimeError</span><span class="special">,</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">());</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">something_which_throws</span><span class="special">()</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="keyword">throw</span> <span class="identifier">my_exception</span><span class="special">();</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">exception_translator_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">register_exception_translator</span><span class="special">&lt;</span><span class="identifier">my_exception</span><span class="special">&gt;(&amp;</span><span class="identifier">translate</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"something_which_throws"</span><span class="special">,</span> <span class="identifier">something_which_throws</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_errors_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_init_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,233 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/init.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_exception_translato.html" title="boost/python/exception_translator.hpp">
<link rel="next" href="boost_python_iterator_hpp.html" title="boost/python/iterator.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_exception_translato.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_iterator_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_init_hpp"></a><a class="link" href="boost_python_init_hpp.html" title="boost/python/init.hpp">boost/python/init.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init">Class
template <code class="computeroutput"><span class="identifier">init</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_optional">Class
template <code class="computeroutput"><span class="identifier">optional</span></code> </a></span></dt>
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_init_hpp.introduction"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions">init-expressions</a></span></dt></dl></div>
<p>
&lt;boost/python/init.hpp&gt; defines the interface for exposing C++ constructors
to Python as extension class <code class="computeroutput"><span class="identifier">__init__</span></code>
functions.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_init_hpp.introduction.init_expressions"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">init-expressions</a>
</h4></div></div></div>
<p>
An init-expression is used to describe a family of <code class="computeroutput"><span class="identifier">__init__</span></code>
methods to be generated for an extension class, and the result has the
following properties:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">docstring</span></dt>
<dd><p>
An <a class="link" href="../glossary.html#ntbs">ntbs</a> whose value will bound to the
method's <code class="computeroutput"><span class="identifier">__doc__</span></code>
attribute
</p></dd>
<dt><span class="term">keywords</span></dt>
<dd><p>
A <a class="link" href="../function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions" title="keyword-expressions">keyword-expression</a>
which will be used to name (a trailing subsequence of) the arguments
to the generated <code class="computeroutput"><span class="identifier">__init__</span></code>
function(s).
</p></dd>
<dt><span class="term">call_policies</span></dt>
<dd><p>
An instance of a model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>.
</p></dd>
<dt><span class="term">argument_types</span></dt>
<dd><p>
An MPL sequence of C++ argument types which will be used to construct
the wrapped C++ object. An init expression has one or more valid
prefixes which are given by a sequence of prefixes of its argument
types.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_init_hpp.class_template_init"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init" title="Class template init">Class
template <code class="computeroutput"><span class="identifier">init</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init.class_template_init_constructors">Class
template <code class="computeroutput"><span class="identifier">init</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init.class_template_init_observer_fun">Class
template <code class="computeroutput"><span class="identifier">init</span></code> observer
functions</a></span></dt>
</dl></div>
<p>
A MPL sequence which can be used to specify a family of one or more __init__
functions. Only the last Ti supplied may be an instantiation of optional&lt;...&gt;.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">T1</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">,...</span><span class="identifier">Tn</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">init</span>
<span class="special">{</span>
<span class="identifier">init</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">&gt;</span> <span class="identifier">init</span><span class="special">(</span><span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">&gt;</span> <span class="identifier">init</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">,</span> <span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">CallPolicies</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">CallPolicies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">)</span> <span class="keyword">const</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_init_hpp.class_template_init.class_template_init_constructors"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init.class_template_init_constructors" title="Class template init constructors">Class
template <code class="computeroutput"><span class="identifier">init</span></code> constructors</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">init</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">&gt;</span> <span class="identifier">init</span><span class="special">(</span><span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Keywords</span><span class="special">&gt;</span> <span class="identifier">init</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">doc</span><span class="special">,</span> <span class="identifier">Keywords</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">kw</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
If supplied, doc is an <a class="link" href="../glossary.html#ntbs">ntbs</a>. If supplied,
kw is the result of a
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<p>
The result is an init-expression whose docstring is doc and whose
keywords are a reference to kw. If the first form is used, the
resulting expression's keywords are empty. The expression's call
policies are an instance of <a class="link" href="../function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_default_call_polici" title="boost/python/default_call_policies.hpp">default_call_policies</a>.
If Tn is <a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_optional" title="Class template optional">optional&lt;U1,
U2,... Um&gt;</a>, the expression's valid prefixes are given
by:
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,...</span><span class="identifier">Tn</span><span class="special">-</span><span class="number">1</span><span class="special">),</span> <span class="special">(</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,...</span><span class="identifier">Tn</span><span class="special">-</span><span class="number">1</span> <span class="special">,</span> <span class="identifier">U1</span><span class="special">),</span> <span class="special">(</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,...</span><span class="identifier">Tn</span><span class="special">-</span><span class="number">1</span> <span class="special">,</span> <span class="identifier">U1</span><span class="special">,</span> <span class="identifier">U2</span><span class="special">),</span> <span class="special">...(</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,...</span><span class="identifier">Tn</span><span class="special">-</span><span class="number">1</span> <span class="special">,</span> <span class="identifier">U1</span><span class="special">,</span> <span class="identifier">U2</span><span class="special">,...</span><span class="identifier">Um</span><span class="special">)</span></pre>
<p>
. Otherwise, the expression has one valid prefix given by the template
arguments the user specified.
</p>
</dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="high_level_components.boost_python_init_hpp.class_template_init.class_template_init_observer_fun"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init.class_template_init_observer_fun" title="Class template init observer functions">Class
template <code class="computeroutput"><span class="identifier">init</span></code> observer
functions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">policies</span><span class="special">)</span> <span class="keyword">const</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
Policies is a model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Returns a new <a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction.init_expressions" title="init-expressions">init-expression</a>
with all the same properties as the init object except that its
call policies are replaced by a reference to policies.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_init_hpp.class_template_optional"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_optional" title="Class template optional">Class
template <code class="computeroutput"><span class="identifier">optional</span></code> </a>
</h3></div></div></div>
<p>
A MPL sequence which can be used to specify the optional arguments to an
__init__ function.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">T1</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">,...</span><span class="identifier">Tn</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">optional</span> <span class="special">{};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_init_hpp.example"></a><a class="link" href="boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
Given the C++ declarations:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">;</span>
<span class="keyword">class</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">Y</span><span class="special">*</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_y</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">double</span><span class="special">);</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">Y</span><span class="special">*</span> <span class="identifier">m_y</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
A corresponing Boost.Python extension class can be created with:
</p>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="string">"This is X's docstring."</span><span class="special">,</span>
<span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">args</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span><span class="string">"y"</span><span class="special">),</span> <span class="string">"X.__init__'s docstring"</span><span class="special">)[</span>
<span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;()]</span>
<span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;())</span>
<span class="special">;</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_exception_translato.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_iterator_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,398 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/iterator.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_init_hpp.html" title="boost/python/init.hpp">
<link rel="next" href="boost_python_module_hpp.html" title="boost/python/module.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_init_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_module_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_iterator_hpp"></a><a class="link" href="boost_python_iterator_hpp.html" title="boost/python/iterator.hpp">boost/python/iterator.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator">Class
template <code class="computeroutput"><span class="identifier">iterator</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator_construc">Class
template iterator constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators">Class
template <code class="computeroutput"><span class="identifier">iterators</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_nested_">Class
template iterators nested types</a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_static_">Class
template iterators static functions</a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.introduction"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/iterator.hpp&gt; provides types and functions for creating
<a href="http://www.python.org/doc/current/lib/typeiter.html" target="_top">Python
iterators</a> from C++ Containers and Iterators. Note that if your
<code class="computeroutput"><span class="identifier">class_</span></code> supports random-access
iterators, implementing <a href="http://www.python.org/doc/current/ref/sequence-types.html#l2h-128" target="_top">__getitem__</a>
(also known as the Sequence Protocol) may serve you better than using this
facility: Python will automatically create an iterator type for you (see
<a href="http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-35" target="_top"><code class="computeroutput"><span class="identifier">iter</span><span class="special">()</span></code></a>),
and each access can be range-checked, leaving no possiblity of accessing
through an invalidated C++ iterator.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.class_template_iterator"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator" title="Class template iterator">Class
template <code class="computeroutput"><span class="identifier">iterator</span></code></a>
</h3></div></div></div>
<p>
Instances of <code class="computeroutput"><span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">C</span><span class="special">,</span><span class="identifier">P</span><span class="special">&gt;</span></code> hold a reference to a callable Python
object which, when invoked from Python, expects a single argument c convertible
to C and creates a Python iterator that traverses <code class="computeroutput"><span class="special">[</span><span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span><span class="special">())</span></code>. The optional <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
<code class="computeroutput"><span class="identifier">P</span></code> can be used to control
how elements are returned during iteration.
</p>
<p>
In the table below, c is an instance of Container.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Template Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
<th>
<p>
Default
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Container
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[</span><span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span><span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span></code>) is a valid Iterator range.
</p>
</td>
<td>
<p>
The result will convert its argument to c and call c.begin()
and c.end() to acquire iterators. To invoke Container's const
<code class="computeroutput"><span class="identifier">begin</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">end</span><span class="special">()</span></code>
functions, make it const.
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
NextPolicies
</p>
</td>
<td>
<p>
A default-constructible model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>.
</p>
</td>
<td>
<p>
Applied to the resulting iterators' <code class="computeroutput"><span class="identifier">next</span><span class="special">()</span></code> method.
</p>
</td>
<td>
<p>
An unspecified model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
which always makes a copy of the result of deferencing the underlying
C++ iterator
</p>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">NextPolicies</span> <span class="special">=</span> <span class="identifier">unspecified</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">iterator</span> <span class="special">:</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="identifier">iterator</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.class_template_iterator_construc"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator_construc" title="Class template iterator constructors">Class
template iterator constructors</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">iterator</span><span class="special">()</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd>
<p>
Initializes its base class with the result of:
</p>
<pre class="programlisting"><span class="identifier">range</span><span class="special">&lt;</span><span class="identifier">NextPolicies</span><span class="special">&gt;(&amp;</span><span class="identifier">iterators</span><span class="special">&lt;</span><span class="identifier">Container</span><span class="special">&gt;::</span><span class="identifier">begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">iterators</span><span class="special">&lt;</span><span class="identifier">Container</span><span class="special">&gt;::</span><span class="identifier">end</span><span class="special">)</span></pre>
</dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get</span><span class="special">()</span></code>
points to a Python callable object which creates a Python iterator
as described above.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Provides an easy way to create iterators for the common case where
a C++ class being wrapped provides <code class="computeroutput"><span class="identifier">begin</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">end</span><span class="special">()</span></code>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.class_template_iterators"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators" title="Class template iterators">Class
template <code class="computeroutput"><span class="identifier">iterators</span></code></a>
</h3></div></div></div>
<p>
A utility class template which provides a way to reliably call its argument's
<code class="computeroutput"><span class="identifier">begin</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">end</span><span class="special">()</span></code>
member functions. Note that there is no portable way to take the address
of a member function of a C++ standard library container, so <code class="computeroutput"><span class="identifier">iterators</span><span class="special">&lt;&gt;</span></code>
can be particularly helpful when wrapping them.
</p>
<p>
In the table below, x is an instance of C.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Required Valid Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
x.begin()
</p>
</td>
<td>
<p>
Convertible to C::const_iterator if C is a const type; convertible
to C::iterator otherwise.
</p>
</td>
</tr>
<tr>
<td>
<p>
x.end()
</p>
</td>
<td>
<p>
Convertible to C::const_iterator if C is a const type; convertible
to C::iterator otherwise.
</p>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">iterators</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">C</span><span class="special">::</span><span class="identifier">const_iterator</span> <span class="identifier">iterator</span><span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">C</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">C</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.class_template_iterators_nested_"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_nested_" title="Class template iterators nested types">Class
template iterators nested types</a>
</h3></div></div></div>
<p>
If C is a const type,
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">C</span><span class="special">::</span><span class="identifier">const_iterator</span> <span class="identifier">iterator</span><span class="special">;</span></pre>
<p>
Otherwise:
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">C</span><span class="special">::</span><span class="identifier">iterator</span> <span class="identifier">iterator</span><span class="special">;</span></pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.class_template_iterators_static_"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_static_" title="Class template iterators static functions">Class
template iterators static functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">C</span><span class="special">&amp;);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">C</span><span class="special">&amp;);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.functions"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">NextPolicies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Target</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Accessor1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Accessor2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">range</span><span class="special">(</span><span class="identifier">Accessor1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Accessor2</span> <span class="identifier">finish</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">NextPolicies</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Accessor1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Accessor2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">range</span><span class="special">(</span><span class="identifier">Accessor1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Accessor2</span> <span class="identifier">finish</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Accessor1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Accessor2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">range</span><span class="special">(</span><span class="identifier">Accessor1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Accessor2</span> <span class="identifier">finish</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
NextPolicies is a default-constructible model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd>
<p>
The first form creates a Python callable object which, when invoked,
converts its argument to a Target object x, and creates a Python
iterator which traverses <code class="computeroutput"><span class="special">[</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">start</span><span class="special">,</span><span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">),</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">finish</span><span class="special">,</span><span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">))</span></code>,
applying NextPolicies to the iterator's <code class="computeroutput"><span class="identifier">next</span><span class="special">()</span></code> function. The second form is identical
to the first, except that Target is deduced from Accessor1 as follows:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
If Accessor1 is a function type, Target is the type of its first
argument.
</li>
<li class="listitem">
If Accessor1 is a data member pointer of the form <code class="computeroutput"><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*)</span></code>,
Target is identical to <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<li class="listitem">
If Accessor1 is a member function pointer of the form <code class="computeroutput"><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*)(</span><span class="identifier">arguments</span><span class="special">...)</span>
<span class="identifier">cv</span><span class="special">-</span><span class="identifier">opt</span></code>, where cv-opt is an optional
cv-qualifier, Target is identical to <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
</ol></div>
<p>
The third form is identical to the second, except that NextPolicies
is an unspecified model of <a class="link" href="../concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
which always makes a copy of the result of deferencing the underlying
C++ iterator
</p>
</dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
The use of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">()</span></code> allows C++ iterators to be accessed
through functions, member functions or data member pointers. Customization
of NextPolicies (e.g. using <a class="link" href="../function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_internal_ref.class_template_return_internal_r" title="Class template return_internal_reference">return_internal_reference</a>)
is useful when it is expensive to copy sequence elements of a wrapped
class type. Customization of Target is useful when Accessor1 is a
function object, or when a base class of the intended target type
would otherwise be deduced.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_iterator_hpp.example"></a><a class="link" href="boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">demo</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"dvec"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"__iter__"</span><span class="special">,</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_init_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_module_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,111 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/module.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_iterator_hpp.html" title="boost/python/iterator.hpp">
<link rel="next" href="boost_python_operators_hpp.html" title="boost/python/operators.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_iterator_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_operators_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_module_hpp"></a><a class="link" href="boost_python_module_hpp.html" title="boost/python/module.hpp">boost/python/module.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_module_hpp.introduction"></a><a class="link" href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
This header provides the basic facilities needed to create a Boost.Python
extension module.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_module_hpp.macros"></a><a class="link" href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.macros" title="Macros">Macros</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span></code>
is used to declare Python <a href="http://www.python.org/doc/2.2/ext/methodTable.html#SECTION003400000000000000000" target="_top">module
initialization functions</a>. The name argument must exactly match
the name of the module to be initialized, and must conform to Python's
<a href="http://www.python.org/doc/2.2/ref/identifiers.html" target="_top">identifier
naming rules</a>. Where you would normally write
</p>
<pre class="programlisting"><span class="keyword">extern</span> <span class="string">"C"</span> <span class="keyword">void</span> <span class="identifier">initname</span><span class="special">()</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
Boost.Python modules should be initialized with
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
This macro generates two functions in the scope where it is used: <code class="computeroutput"><span class="keyword">extern</span> <span class="string">"C"</span>
<span class="keyword">void</span> <span class="identifier">initname</span><span class="special">()</span></code>, and <code class="computeroutput"><span class="keyword">void</span>
<span class="identifier">init_module_name</span><span class="special">()</span></code>,
whose body must follow the macro invocation. <code class="computeroutput"><span class="identifier">init_name</span></code>
passes <code class="computeroutput"><span class="identifier">init_module_name</span></code>
to <a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions" title="Functions">handle_exception()</a>
so that any C++ exceptions generated are safely processeed. During the
body of <code class="computeroutput"><span class="identifier">init_name</span></code>, the
<a class="link" href="boost_python_scope_hpp.html" title="boost/python/scope.hpp">current scope</a>
refers to the module being initialized.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_module_hpp.examples"></a><a class="link" href="boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
C++ module definition:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">xxx</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">throw</span> <span class="string">"something bad happened"</span>
<span class="special">}</span>
</pre>
<p>
Interactive Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">xxx</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">""</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">?</span>
<span class="identifier">RuntimeError</span><span class="special">:</span> <span class="identifier">Unidentifiable</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">Exception</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_iterator_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_operators_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,160 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/scope.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_operators_hpp.html" title="boost/python/operators.hpp">
<link rel="next" href="boost_python_stl_iterator_hpp.html" title="boost/python/stl_iterator.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_operators_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_stl_iterator_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_scope_hpp"></a><a class="link" href="boost_python_scope_hpp.html" title="boost/python/scope.hpp">boost/python/scope.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope">Class
<code class="computeroutput"><span class="identifier">scope</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope_constructors_and_des">Class
scope constructors and destructor</a></span></dt>
<dt><span class="section"><a href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_scope_hpp.introduction"></a><a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Defines facilities for querying and controlling the Python scope (namespace)
which will contain new wrapped classes and functions.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_scope_hpp.class_scope"></a><a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope" title="Class scope">Class
<code class="computeroutput"><span class="identifier">scope</span></code></a>
</h3></div></div></div>
<p>
The scope class has an associated global Python object which controls the
Python namespace in which new extension classes and wrapped functions will
be defined as attributes. Default-constructing a new scope object binds
it to the associated global Python object. Constructing a scope object
with an argument changes the associated global Python object to the one
held by the argument, until the lifetime of the scope object ends, at which
time the associated global Python object reverts to what it was before
the scope object was constructed.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">scope</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">scope</span><span class="special">(</span><span class="identifier">scope</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="identifier">scope</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="identifier">scope</span><span class="special">();</span>
<span class="special">~</span><span class="identifier">scope</span><span class="special">()</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">scope</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_scope_hpp.class_scope_constructors_and_des"></a><a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope_constructors_and_des" title="Class scope constructors and destructor">Class
scope constructors and destructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">scope</span><span class="special">(</span><span class="identifier">scope</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">explicit</span> <span class="identifier">scope</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
</pre>
<p>
Stores a reference to the current associated scope object, and sets the
associated scope object to the one referred to by x.ptr(). The object base
class is initialized with x.
</p>
<pre class="programlisting"><span class="identifier">scope</span><span class="special">();</span></pre>
<p>
Stores a reference to the current associated scope object. The object base
class is initialized with the current associated scope object. Outside
any module initialization function, the current associated Python object
is None.
</p>
<pre class="programlisting"><span class="special">~</span><span class="identifier">scope</span><span class="special">()</span></pre>
<p>
Sets the current associated Python object to the stored object.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_scope_hpp.example"></a><a class="link" href="boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
The following example shows how scope setting can be used to define nested
classes.
</p>
<p>
C++ Module definition:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">scope</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{}</span>
<span class="keyword">struct</span> <span class="identifier">Y</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">g</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">42</span><span class="special">;</span> <span class="special">}</span> <span class="special">};</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">nested</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// add some constants to the current (module) scope</span>
<span class="identifier">scope</span><span class="special">().</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"yes"</span><span class="special">)</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
<span class="identifier">scope</span><span class="special">().</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"no"</span><span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="comment">// Change the current scope </span>
<span class="identifier">scope</span> <span class="identifier">outer</span>
<span class="special">=</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">)</span>
<span class="special">;</span>
<span class="comment">// Define a class Y in the current scope, X</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">Y</span><span class="special">&gt;(</span><span class="string">"Y"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"g"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">Y</span><span class="special">::</span><span class="identifier">g</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Interactive Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">nested</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">nested</span><span class="special">.</span><span class="identifier">yes</span>
<span class="number">1</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">nested</span><span class="special">.</span><span class="identifier">X</span><span class="special">.</span><span class="identifier">Y</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">g</span><span class="special">()</span>
<span class="number">42</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_operators_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_stl_iterator_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,311 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/stl_iterator.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_scope_hpp.html" title="boost/python/scope.hpp">
<link rel="next" href="boost_python_wrapper_hpp.html" title="boost/python/wrapper.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_scope_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_wrapper_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_stl_iterator_hpp"></a><a class="link" href="boost_python_stl_iterator_hpp.html" title="boost/python/stl_iterator.hpp">boost/python/stl_iterator.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterato">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat0">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat1">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
modifiers</a></span></dt>
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat2">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
observers</a></span></dt>
<dt><span class="section"><a href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.introduction"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/stl_iterator.hpp&gt; provides types for creating C++ Iterators
from <a href="http://www.python.org/doc/current/lib/typeiter.html" target="_top">Python
iterables</a>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterato"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterato" title="Class template stl_input_iterator">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code></a>
</h3></div></div></div>
<p>
Instances of <code class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> hold a Python iterator and adapt it
for use with STL algorithms. <code class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> satisfies the requirements for an Input
Iterator.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Template Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
<th>
<p>
Default
</p>
</th>
</tr></thead>
<tbody><tr>
<td>
<p>
ValueType
</p>
</td>
<td>
<p>
ValueType must be CopyConstructible.
</p>
</td>
<td>
<p>
Dereferencing an instance of <code class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;</span><span class="identifier">ValueType</span><span class="special">&gt;</span></code> will return an rvalue of
type ValueType.
</p>
</td>
<td>
<p>
None
</p>
</td>
</tr></tbody>
</table></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">ValueType</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">stl_input_iterator</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ptrdiff_t</span> <span class="identifier">difference_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">ValueType</span> <span class="identifier">value_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">ValueType</span><span class="special">*</span> <span class="identifier">pointer</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">ValueType</span> <span class="identifier">reference</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">input_iterator_tag</span> <span class="identifier">iterator_category</span><span class="special">;</span>
<span class="identifier">stl_input_iterator</span><span class="special">();</span>
<span class="identifier">stl_input_iterator</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ob</span><span class="special">);</span>
<span class="identifier">stl_input_iterator</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">++();</span>
<span class="identifier">stl_input_iterator</span> <span class="keyword">operator</span><span class="special">++(</span><span class="keyword">int</span><span class="special">);</span>
<span class="identifier">ValueType</span> <span class="keyword">operator</span><span class="special">*()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">);</span>
<span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">);</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">object</span> <span class="identifier">it</span><span class="special">;</span> <span class="comment">// For exposition only</span>
<span class="identifier">object</span> <span class="identifier">ob</span><span class="special">;</span> <span class="comment">// For exposition only</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat0"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat0" title="Class template stl_input_iterator constructors">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
constructors</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">stl_input_iterator</span><span class="special">()</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Creates a past-the-end input iterator, useful for signifying the
end of a sequence.
</p></dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">this</span></code> is past-the-end
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
Nothing.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">stl_input_iterator</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ob</span><span class="special">)</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Calls ob.attr("__iter__")() and stores the resulting Python
iterator object in this-&gt;it. Then, calls this-&gt;it.attr("next")()
and stores the result in this-&gt;ob. If the sequence is exhausted,
sets this-&gt;ob to object().
</p></dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
this is a dereferenceable or past-the-end.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat1"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat1" title="Class template stl_input_iterator modifiers">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
modifiers</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">stl_input_iterator</span> <span class="special">&amp;</span><span class="keyword">operator</span><span class="special">++()</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Calls this-&gt;it.attr("next")() and stores the result
in this-&gt;ob. If the sequence is exhausted, sets this-&gt;ob to
object().
</p></dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
this is a dereferenceable or past-the-end.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">stl_input_iterator</span> <span class="special">&amp;</span><span class="keyword">operator</span><span class="special">++(</span><span class="keyword">int</span><span class="special">)</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">stl_input_iterator</span> <span class="identifier">tmp</span> <span class="special">=</span>
<span class="special">*</span><span class="keyword">this</span><span class="special">;</span> <span class="special">++*</span><span class="keyword">this</span><span class="special">;</span> <span class="keyword">return</span> <span class="identifier">tmp</span><span class="special">;</span></code>
</p></dd>
<dt><span class="term">Postconditions</span></dt>
<dd><p>
this is a dereferenceable or past-the-end.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat2"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat2" title="Class template stl_input_iterator observers">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
observers</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">ValueType</span> <span class="keyword">operator</span><span class="special">*()</span> <span class="keyword">const</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Returns the current element in the sequence.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">ValueType</span><span class="special">&gt;(</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">ob</span><span class="special">);</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Returns true if both iterators are dereferenceable or if both iterators
are past-the-end, false otherwise.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">(</span><span class="identifier">lhs</span><span class="special">.</span><span class="identifier">ob</span> <span class="special">==</span> <span class="identifier">object</span><span class="special">())</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">rhs</span><span class="special">.</span><span class="identifier">ob</span> <span class="special">==</span> <span class="identifier">object</span><span class="special">())</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">stl_input_iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Returns false if both iterators are dereferenceable or if both iterators
are past-the-end, true otherwise.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">!(</span><span class="identifier">lhs</span>
<span class="special">==</span> <span class="identifier">rhs</span><span class="special">)</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_stl_iterator_hpp.example"></a><a class="link" href="boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">object</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">stl_iterator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">sequence_to_int_list</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ob</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">stl_input_iterator</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">ob</span><span class="special">),</span> <span class="identifier">end</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">begin</span><span class="special">,</span> <span class="identifier">end</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_scope_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_wrapper_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,222 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/wrapper.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter&#160;2.&#160;High Level Components">
<link rel="prev" href="boost_python_stl_iterator_hpp.html" title="boost/python/stl_iterator.hpp">
<link rel="next" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_stl_iterator_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../object_wrappers.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_wrapper_hpp"></a><a class="link" href="boost_python_wrapper_hpp.html" title="boost/python/wrapper.hpp">boost/python/wrapper.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override">Class
<code class="computeroutput"><span class="identifier">override</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override_observer_function">Class
<code class="computeroutput"><span class="identifier">override</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper_observer_">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code> observer
functions</a></span></dt>
<dt><span class="section"><a href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.introduction"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
To wrap a class T such that its virtual functions can be "overridden
in Python"&#8212;so that the corresponding method of a Python derived
class will be called when the virtual function is invoked from C++&#8212;you
must create a C++ wrapper class derived from <code class="computeroutput"><span class="identifier">T</span></code>
that overrides those virtual functions so that they call into Python. This
header contains classes that can be used to make that job easier.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.class_override"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override" title="Class override">Class
<code class="computeroutput"><span class="identifier">override</span></code></a>
</h3></div></div></div>
<p>
Encapsulates a Python override of a C++ virtual function. An override object
either holds a callable Python object or <code class="computeroutput"><span class="identifier">None</span></code>.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">override</span> <span class="special">:</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">...</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="special">...</span><span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="special">...</span><span class="identifier">An</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">};</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.class_override_observer_function"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override_observer_function" title="Class override observer functions">Class
<code class="computeroutput"><span class="identifier">override</span></code> observer functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">...</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="special">...</span><span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">unspecified</span> <span class="keyword">operator</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="special">...</span><span class="identifier">An</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
If *this holds a callable Python object, it is invoked with the specified
arguments in the manner specified here. Otherwise, throws <a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set" title="Class error_already_set">error_already_set</a>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An object of unspecified type that holds the Python result of the
invocation and, when converted to a C++ type R, attempts to convert
that result object to R. If that conversion fails, throws <a class="link" href="boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set" title="Class error_already_set">error_already_set</a>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.class_template_wrapper"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper" title="Class template wrapper">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code></a>
</h3></div></div></div>
<p>
Deriving your wrapper class from both <code class="computeroutput"><span class="identifier">T</span></code>
and <code class="computeroutput"><span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
makes writing that derived class easier.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">wrapper</span>
<span class="special">{</span>
<span class="keyword">protected</span><span class="special">:</span>
<span class="identifier">override</span> <span class="identifier">get_override</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">};</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.class_template_wrapper_observer_"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper_observer_" title="Class template wrapper observer functions">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code> observer
functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">override</span> <span class="identifier">get_override</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
name is a <a class="link" href="../glossary.html#ntbs">ntbs</a>.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
is the C++ base class subobject of a Python derived class instance
that overrides the named function, returns an override object that
delegates to the Python override. Otherwise, returns an override
object that holds <code class="computeroutput"><span class="identifier">None</span></code>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_wrapper_hpp.example"></a><a class="link" href="boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">wrapper</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">call</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// Class with one pure virtual function</span>
<span class="keyword">struct</span> <span class="identifier">P</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">P</span><span class="special">(){}</span>
<span class="keyword">virtual</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">g</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"P::g()"</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">PCallback</span> <span class="special">:</span> <span class="identifier">P</span><span class="special">,</span> <span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">P</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">)();</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="comment">// Class with one non-pure virtual function</span>
<span class="keyword">struct</span> <span class="identifier">A</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">A</span><span class="special">(){}</span>
<span class="keyword">virtual</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="string">"A::f()"</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">ACallback</span> <span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">override</span> <span class="identifier">f</span> <span class="special">=</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">))</span>
<span class="keyword">return</span> <span class="identifier">f</span><span class="special">();</span>
<span class="keyword">return</span> <span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">();</span>
<span class="special">}</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">default_f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">();</span> <span class="special">}</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE_INIT</span><span class="special">(</span><span class="identifier">polymorphism</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">PCallback</span><span class="special">,</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"P"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">pure_virtual</span><span class="special">(&amp;</span><span class="identifier">P</span><span class="special">::</span><span class="identifier">f</span><span class="special">))</span>
<span class="special">;</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">ACallback</span><span class="special">,</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"A"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">ACallback</span><span class="special">::</span><span class="identifier">default_f</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_stl_iterator_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../object_wrappers.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,628 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Boost.Python Reference Manual</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="next" href="concepts.html" title="Chapter&#160;1.&#160;Concepts">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="concepts.html"><img src="../images/next.png" alt="Next"></a></div>
<div class="book">
<div class="titlepage">
<div>
<div><h1 class="title">
<a name="reference"></a>Boost.Python Reference Manual</h1></div>
<div><div class="authorgroup">
<div class="author"><h3 class="author">
<span class="firstname">David</span> <span class="surname">Abrahams</span>
</h3></div>
<div class="author"><h3 class="author">
<span class="firstname">Stefan</span> <span class="surname">Seefeld</span>
</h3></div>
</div></div>
<div><p class="copyright">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld</p></div>
<div><div class="legalnotice">
<a name="reference.legal"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></div>
</div>
<hr>
</div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="concepts.html">1. Concepts</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies">CallPolicies</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.callpolicies_composition">CallPolicies
Composition</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/dereferenceable.html">Dereferenceable</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/extractor.html">Extractor</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.concept_requirements">Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.notes">Notes</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/holdergenerator.html">HolderGenerator</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/resultconverter.html">ResultConverter</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconverter_concept_requirem">ResultConverter
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept">ResultConverterGenerator
Concept Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/objectwrapper.html">ObjectWrapper</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen">ObjectWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements">TypeWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.caveat">Caveat</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="high_level_components.html">2. High Level Components</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp">boost/python/class.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel">Class
template <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Bases</span><span class="special">,</span> <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">NonCopyable</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_bases_t1_t2_tn">Class
template bases&lt;T1, T2, ...TN&gt;</a></span></dt>
<dt><span class="section"><a href="high_level_components.html#high_level_components.boost_python_class_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html">boost/python/def.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_hpp.html#high_level_components.boost_python_def_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html">boost/python/def_visitor.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor">Class
<code class="computeroutput"><span class="identifier">def_visitor</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html">boost/python/docstring_options.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_dostring_options_construct">Class
dostring_options constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_destruct">Class
docstring_options destructor</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.class_docstring_options_modifier">Class
<code class="computeroutput"><span class="identifier">docstring_options</span></code> modifier
functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_docstring_options_h.html#high_level_components.boost_python_docstring_options_h.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html">boost/python/enum.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_constructors">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.class_template_enum_modifier_fun">Class
template <code class="computeroutput"><span class="identifier">enum_</span></code> modifier functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_enum_hpp.html#high_level_components.boost_python_enum_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html">boost/python/errors.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set">Class
<code class="computeroutput"><span class="identifier">error_already_set</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html">boost/python/exception_translator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.function_register_exception_tran">Function
<code class="computeroutput"><span class="identifier">register_exception_translator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_exception_translato.html#high_level_components.boost_python_exception_translato.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html">boost/python/init.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_init">Class
template <code class="computeroutput"><span class="identifier">init</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.class_template_optional">Class
template <code class="computeroutput"><span class="identifier">optional</span></code> </a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_init_hpp.html#high_level_components.boost_python_init_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html">boost/python/iterator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator">Class
template <code class="computeroutput"><span class="identifier">iterator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterator_construc">Class
template iterator constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators">Class
template <code class="computeroutput"><span class="identifier">iterators</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_nested_">Class
template iterators nested types</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.class_template_iterators_static_">Class
template iterators static functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_iterator_hpp.html#high_level_components.boost_python_iterator_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html">boost/python/module.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_module_hpp.html#high_level_components.boost_python_module_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html">boost/python/operators.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_self_ns_self_t">Class
<code class="computeroutput"><span class="identifier">self_ns</span><span class="special">::</span><span class="identifier">self_t</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_template_other">Class
template <code class="computeroutput"><span class="identifier">other</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.class_template_detail_operator">Class
template <code class="computeroutput"><span class="identifier">detail</span><span class="special">::</span><span class="identifier">operator_</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.object_self">Object
<code class="computeroutput"><span class="identifier">self</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_operators_hpp.html#high_level_components.boost_python_operators_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html">boost/python/scope.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope">Class
<code class="computeroutput"><span class="identifier">scope</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.class_scope_constructors_and_des">Class
scope constructors and destructor</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_scope_hpp.html#high_level_components.boost_python_scope_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html">boost/python/stl_iterator.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterato">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat0">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
constructors</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat1">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
modifiers</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.class_template_stl_input_iterat2">Class
template <code class="computeroutput"><span class="identifier">stl_input_iterator</span></code>
observers</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_stl_iterator_hpp.html#high_level_components.boost_python_stl_iterator_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html">boost/python/wrapper.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override">Class
<code class="computeroutput"><span class="identifier">override</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_override_observer_function">Class
<code class="computeroutput"><span class="identifier">override</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.class_template_wrapper_observer_">Class
template <code class="computeroutput"><span class="identifier">wrapper</span></code> observer
functions</a></span></dt>
<dt><span class="section"><a href="high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.example">Example</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="object_wrappers.html">3. Object Wrappers</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp">boost/python/dict.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict">Class
<code class="computeroutput"><span class="identifier">dict</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html">boost_python_list.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list">Class
<code class="computeroutput"><span class="identifier">list</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html">boost/python/long.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long">Class
<code class="computeroutput"><span class="identifier">long_</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html">boost/python/object.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_nil">Class
<code class="computeroutput"><span class="identifier">slice_nil</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_attribute_policies">Class
<code class="computeroutput"><span class="identifier">const_attribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_attribute_policies_s">Class
<code class="computeroutput"><span class="identifier">const_attribute_policies</span></code>
static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_attribute_policies">Class
<code class="computeroutput"><span class="identifier">attribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_attribute_policies_static_">Class
<code class="computeroutput"><span class="identifier">attribute_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_objattribute_policie">Class
<code class="computeroutput"><span class="identifier">const_objattribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_objattribute_polici0">Class
<code class="computeroutput"><span class="identifier">const_objattribute_policies</span></code>
static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_objattribute_policies">Class
<code class="computeroutput"><span class="identifier">objattribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_objattribute_policies_stat">Class
<code class="computeroutput"><span class="identifier">objattribute_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_item_policies">Class
<code class="computeroutput"><span class="identifier">const_item_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_item_policies_static">Class
<code class="computeroutput"><span class="identifier">const_item_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_item_policies">Class
<code class="computeroutput"><span class="identifier">item_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_item_policies_static_funct">Class
<code class="computeroutput"><span class="identifier">item_policies</span></code> static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_slice_policies">Class
<code class="computeroutput"><span class="identifier">const_slice_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_slice_policies_stati">Class
<code class="computeroutput"><span class="identifier">const_slice_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_policies">Class
<code class="computeroutput"><span class="identifier">slice_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_policies_static_func">Class
<code class="computeroutput"><span class="identifier">slice_policies</span></code> static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_object_operators">Class
template <code class="computeroutput"><span class="identifier">object_operators</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_object_operators_">Class
template <code class="computeroutput"><span class="identifier">object_operators</span></code>
observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object">Class
<code class="computeroutput"><span class="identifier">object</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object_constructors_and_de">Class
<code class="computeroutput"><span class="identifier">object</span></code> constructors and destructor</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object_modifiers">Class
<code class="computeroutput"><span class="identifier">object</span></code> modifiers</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy_observer_fu">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy_modifier_fu">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code> modifier functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html">boost/python/str.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.class_str">Class
<code class="computeroutput"><span class="identifier">str</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html">boost/python/slice.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice">Class
<code class="computeroutput"><span class="identifier">slice</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_constructors">Class
<code class="computeroutput"><span class="identifier">slice</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_observer_functions">Class
<code class="computeroutput"><span class="identifier">slice</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html">boost/python/tuple.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple">Class
<code class="computeroutput"><span class="identifier">tuple</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.function_make_tuple">Function
<code class="computeroutput"><span class="identifier">make_tuple</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.example">Example</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="function_invocation_and_creation.html">4. Function Invocation and Creation</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp">boost/python/args.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg">Class
<code class="computeroutput"><span class="identifier">arg</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_constructor">Class
<code class="computeroutput"><span class="identifier">arg</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.class_arg_operator">Class
<code class="computeroutput"><span class="identifier">arg</span></code> operator=</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.keyword_expression_operator">Keyword-expression
operator,</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation.html#function_invocation_and_creation.boost_python_args_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html">boost/python/call.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call">Function
<code class="computeroutput"><span class="identifier">call</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html">boost/python/call_method.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.function_call_method">Function
<code class="computeroutput"><span class="identifier">call_method</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html">boost/python/data_members.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_data_members_hpp.html#function_invocation_and_creation.boost_python_data_members_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html">boost/python/make_function.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_make_function_hpp.html#function_invocation_and_creation.boost_python_make_function_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html">boost/python/overloads.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.overloaddispatcher_concept">OverloadDispatcher
Concept</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.macros">Macros</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_overloads_hpp.html#function_invocation_and_creation.boost_python_overloads_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html">boost/python/ptr.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_t">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
types</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_c">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
constructors and destructor</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.class_template_pointer_wrapper_o">Class
template <code class="computeroutput"><span class="identifier">pointer_wrapper</span></code>
observer functions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.metafunctions">Metafunctions</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html">boost/python/raw_function.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function">Function
<code class="computeroutput"><span class="identifier">raw_function</span></code></a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html">Function
documentation</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_function_doc_signat">boost/python/function_doc_signature.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp">boost/python/pytype_function.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html">Models
of CallPolicies</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_default_call_polici">boost/python/default_call_policies.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_arg_hpp">boost/python/return_arg.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_internal_ref">boost/python/return_internal_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_return_value_policy">boost/python/return_value_policy.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_callpolicies.html#function_invocation_and_creation.models_of_callpolicies.boost_python_with_custodian_and_">boost/python/with_custodian_and_ward.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html">Models
of ResultConverter</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_indirect_">boost/python/to_python_indirect.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconverter.html#function_invocation_and_creation.models_of_resultconverter.boost_python_to_python_value_hpp">boost/python/to_python_value.hpp</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html">Models
of ResultConverterGenerator</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_const_referenc">boost/python/copy_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_copy_non_const_refe">boost/python/copy_non_const_reference.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_manage_new_object_h">boost/python/manage_new_object.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_">boost/python/reference_existing_object.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_by_value_hpp">boost/python/return_by_value.hpp</a></span></dt>
<dt><span class="section"><a href="function_invocation_and_creation/models_of_resultconvertergenerat.html#function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_return_opaque_point">boost/python/return_opaque_pointer.hpp</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="to_from_python_type_conversion.html">5. To/From Python Type Conversion</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp">boost/python/extract.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract">Class
template <code class="computeroutput"><span class="identifier">extract</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_construct">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> constructors
and destructor</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_observer_">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> observer
functions</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html">boost/python/implicit.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.function_template_implicit_conve">Function
template <code class="computeroutput"><span class="identifier">implicit_convertible</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html">boost/python/lvalue_from_pytype.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html">boost/python/opaque_pointer_converter.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.class_template_opaque_constructo">Class
template <code class="computeroutput"><span class="identifier">opaque</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia">Macro
<code class="computeroutput"><span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span><span class="special">(</span><span class="identifier">Pointee</span><span class="special">)</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html">boost/python/to_python_converter.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html">boost/python/register_ptr_to_python.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.function_register_ptr_to_python">Function
<code class="computeroutput"><span class="identifier">register_ptr_to_python</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.example">Example</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="embedding.html">6. Embedding</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp">boost/python/exec.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_eval">Function
<code class="computeroutput"><span class="identifier">eval</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec">Function
<code class="computeroutput"><span class="identifier">exec</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.function_exec_file">Function
<code class="computeroutput"><span class="identifier">exec_file</span></code></a></span></dt>
<dt><span class="section"><a href="embedding.html#embedding.boost_python_exec_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html">boost/python/import.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.function_import">Function
<code class="computeroutput"><span class="identifier">import</span></code></a></span></dt>
<dt><span class="section"><a href="embedding/boost_python_import_hpp.html#embedding.boost_python_import_hpp.examples">Examples</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="utility_and_infrastructure.html">7. Utility and Infrastructure</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_">boost/python/has_back_reference.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc">Class
template <code class="computeroutput"><span class="identifier">has_back_reference</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html">boost/python/instance_holder.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder">Class
template <code class="computeroutput"><span class="identifier">instance_holder</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html">boost/python/pointee.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee">Class
template <code class="computeroutput"><span class="identifier">pointee</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html">boost/python/handle.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle">Class
template <code class="computeroutput"><span class="identifier">handle</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_borrowed">Function
<code class="computeroutput"><span class="identifier">borrowed</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_allow_null">Function
<code class="computeroutput"><span class="identifier">allow_null</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html">boost/python/type_id.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html">boost/python/ssize_t.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.typedefs">Typedefs</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.constants">Constants</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="topics.html">8. Topics</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met">Calling Python
Functions and Methods</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.argument_handling">Argument
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.result_handling">Result
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.rationale">Rationale</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="topics/pickle_support.html">Pickle support</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.the_pickle_interface">The Pickle
Interface</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.example">Example</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.pitfall_and_safety_guard">Pitfall
and Safety Guard</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.practical_advice">Practical Advice</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.light_weight_alternative_pickle_">Light-weight
alternative: pickle support implemented in Python</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="topics/indexing_support.html">Indexing support</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.the_indexing_interface">The
Indexing Interface</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.index_suite_sub_classes">index_suite
sub-classes</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.indexing_suite_class"><code class="computeroutput"><span class="identifier">indexing_suite</span></code> class</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.class_vector_indexing_suite">class
<code class="computeroutput"><span class="identifier">vector_indexing_suite</span></code></a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.class_map_indexing_suite">class
<code class="computeroutput"><span class="identifier">map_indexing_suite</span></code></a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="chapter"><a href="glossary.html">9. Glossary</a></span></dt>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: December 14, 2017 at 00:12:23 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="concepts.html"><img src="../images/next.png" alt="Next"></a></div>
</body>
</html>

View File

@@ -0,0 +1,249 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;3.&#160;Object Wrappers</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="high_level_components/boost_python_wrapper_hpp.html" title="boost/python/wrapper.hpp">
<link rel="next" href="object_wrappers/boost_python_list_hpp.html" title="boost_python_list.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="high_level_components/boost_python_wrapper_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="object_wrappers/boost_python_list_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="object_wrappers"></a>Chapter&#160;3.&#160;Object Wrappers</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp">boost/python/dict.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict">Class
<code class="computeroutput"><span class="identifier">dict</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html">boost_python_list.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list">Class
<code class="computeroutput"><span class="identifier">list</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html">boost/python/long.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long">Class
<code class="computeroutput"><span class="identifier">long_</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html">boost/python/object.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_nil">Class
<code class="computeroutput"><span class="identifier">slice_nil</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_attribute_policies">Class
<code class="computeroutput"><span class="identifier">const_attribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_attribute_policies_s">Class
<code class="computeroutput"><span class="identifier">const_attribute_policies</span></code>
static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_attribute_policies">Class
<code class="computeroutput"><span class="identifier">attribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_attribute_policies_static_">Class
<code class="computeroutput"><span class="identifier">attribute_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_objattribute_policie">Class
<code class="computeroutput"><span class="identifier">const_objattribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_objattribute_polici0">Class
<code class="computeroutput"><span class="identifier">const_objattribute_policies</span></code>
static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_objattribute_policies">Class
<code class="computeroutput"><span class="identifier">objattribute_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_objattribute_policies_stat">Class
<code class="computeroutput"><span class="identifier">objattribute_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_item_policies">Class
<code class="computeroutput"><span class="identifier">const_item_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_item_policies_static">Class
<code class="computeroutput"><span class="identifier">const_item_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_item_policies">Class
<code class="computeroutput"><span class="identifier">item_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_item_policies_static_funct">Class
<code class="computeroutput"><span class="identifier">item_policies</span></code> static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_slice_policies">Class
<code class="computeroutput"><span class="identifier">const_slice_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_const_slice_policies_stati">Class
<code class="computeroutput"><span class="identifier">const_slice_policies</span></code> static
functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_policies">Class
<code class="computeroutput"><span class="identifier">slice_policies</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_slice_policies_static_func">Class
<code class="computeroutput"><span class="identifier">slice_policies</span></code> static functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_object_operators">Class
template <code class="computeroutput"><span class="identifier">object_operators</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_object_operators_">Class
template <code class="computeroutput"><span class="identifier">object_operators</span></code>
observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object">Class
<code class="computeroutput"><span class="identifier">object</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object_constructors_and_de">Class
<code class="computeroutput"><span class="identifier">object</span></code> constructors and destructor</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object_modifiers">Class
<code class="computeroutput"><span class="identifier">object</span></code> modifiers</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy_observer_fu">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_template_proxy_modifier_fu">Class
template <code class="computeroutput"><span class="identifier">proxy</span></code> modifier functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html">boost/python/str.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.class_str">Class
<code class="computeroutput"><span class="identifier">str</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html">boost/python/slice.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice">Class
<code class="computeroutput"><span class="identifier">slice</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_constructors">Class
<code class="computeroutput"><span class="identifier">slice</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_observer_functions">Class
<code class="computeroutput"><span class="identifier">slice</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html">boost/python/tuple.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple">Class
<code class="computeroutput"><span class="identifier">tuple</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.function_make_tuple">Function
<code class="computeroutput"><span class="identifier">make_tuple</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.example">Example</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_dict_hpp"></a><a class="link" href="object_wrappers.html#object_wrappers.boost_python_dict_hpp" title="boost/python/dict.hpp">boost/python/dict.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict">Class
<code class="computeroutput"><span class="identifier">dict</span></code></a></span></dt>
<dt><span class="section"><a href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_dict_hpp.introduction"></a><a class="link" href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/dev/doc/devel/lib/typesmapping.html" target="_top"><code class="computeroutput"><span class="identifier">dict</span></code></a> type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_dict_hpp.class_dict"></a><a class="link" href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict" title="Class dict">Class
<code class="computeroutput"><span class="identifier">dict</span></code></a>
</h3></div></div></div>
<p>
Exposes the <a href="http://www.python.org/dev/doc/devel/lib/typesmapping.html" target="_top">mapping
protocol</a> of Python's built-in <code class="computeroutput"><span class="identifier">dict</span></code>
type. The semantics of the constructors and member functions defined below
can be fully understood by reading the <a class="link" href="concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since <code class="computeroutput"><span class="identifier">dict</span></code>
is publicly derived from <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">dict</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">dict</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="identifier">dict</span><span class="special">();</span>
<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="identifier">dict</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">data</span><span class="special">);</span>
<span class="comment">// modifiers</span>
<span class="keyword">void</span> <span class="identifier">clear</span><span class="special">();</span>
<span class="identifier">dict</span> <span class="identifier">copy</span><span class="special">();</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">tuple</span> <span class="identifier">popitem</span><span class="special">();</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">setdefault</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">k</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">setdefault</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">d</span><span class="special">);</span>
<span class="keyword">void</span> <span class="identifier">update</span><span class="special">(</span><span class="identifier">object_cref</span> <span class="identifier">E</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">update</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">E</span><span class="special">);</span>
<span class="comment">// observers</span>
<span class="identifier">list</span> <span class="identifier">values</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">get</span><span class="special">(</span><span class="identifier">object_cref</span> <span class="identifier">k</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">get</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">k</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">get</span><span class="special">(</span><span class="identifier">object_cref</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">object_cref</span> <span class="identifier">d</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">get</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">d</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">has_key</span><span class="special">(</span><span class="identifier">object_cref</span> <span class="identifier">k</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">has_key</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">k</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">list</span> <span class="identifier">items</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">iteritems</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">iterkeys</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">itervalues</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">list</span> <span class="identifier">keys</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_dict_hpp.example"></a><a class="link" href="object_wrappers.html#object_wrappers.boost_python_dict_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">dict</span> <span class="identifier">swap_object_dict</span><span class="special">(</span><span class="identifier">object</span> <span class="identifier">target</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">d</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">dict</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">dict</span><span class="special">&gt;(</span><span class="identifier">target</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span>
<span class="identifier">target</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">d</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="high_level_components/boost_python_wrapper_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="object_wrappers/boost_python_list_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,120 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost_python_list.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="prev" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="next" href="boost_python_long_hpp.html" title="boost/python/long.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../object_wrappers.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_long_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_list_hpp"></a><a class="link" href="boost_python_list_hpp.html" title="boost_python_list.hpp">boost_python_list.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list">Class
<code class="computeroutput"><span class="identifier">list</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_list_hpp.introduction"></a><a class="link" href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/doc/current/lib/typesseq-mutable.html" target="_top">list</a>
type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_list_hpp.class_list"></a><a class="link" href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.class_list" title="Class list">Class
<code class="computeroutput"><span class="identifier">list</span></code></a>
</h3></div></div></div>
<p>
Exposes the <a href="http://www.python.org/doc/current/lib/typesseq-mutable.html" target="_top">mapping
protocol</a> of Python's built-in <code class="computeroutput"><span class="identifier">list</span></code>
type. The semantics of the constructors and member functions defined below
can be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since <code class="computeroutput"><span class="identifier">list</span></code>
is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">list</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">list</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">list</span><span class="special">();</span> <span class="comment">// new list</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">list</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sequence</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">append</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">count</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">extend</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">index</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">insert</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">index</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">);</span> <span class="comment">// insert object before index</span>
<span class="identifier">object</span> <span class="identifier">pop</span><span class="special">();</span> <span class="comment">// remove and return item at index (default last)</span>
<span class="identifier">object</span> <span class="identifier">pop</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">index</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">pop</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">index</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">remove</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">);</span>
<span class="keyword">void</span> <span class="identifier">reverse</span><span class="special">();</span> <span class="comment">// reverse *IN PLACE*</span>
<span class="keyword">void</span> <span class="identifier">sort</span><span class="special">();</span> <span class="comment">// sort *IN PLACE*; if given, cmpfunc(x, y) -&gt; -1, 0, 1</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">sort</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_list_hpp.example"></a><a class="link" href="boost_python_list_hpp.html#object_wrappers.boost_python_list_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// Return the number of zeroes in the list</span>
<span class="keyword">long</span> <span class="identifier">zeroes</span><span class="special">(</span><span class="identifier">list</span> <span class="identifier">l</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">l</span><span class="special">.</span><span class="identifier">count</span><span class="special">(</span><span class="number">0</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../object_wrappers.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_long_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,97 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/long.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="prev" href="boost_python_list_hpp.html" title="boost_python_list.hpp">
<link rel="next" href="boost_python_object_hpp.html" title="boost/python/object.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_object_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_long_hpp"></a><a class="link" href="boost_python_long_hpp.html" title="boost/python/long.hpp">boost/python/long.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long">Class
<code class="computeroutput"><span class="identifier">long_</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.introduction"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">long</a>
integer type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.class_long"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long" title="Class long_">Class
<code class="computeroutput"><span class="identifier">long_</span></code></a>
</h3></div></div></div>
<p>
Exposes the <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">numeric
type protocol</a> of Python's built-in <code class="computeroutput"><span class="keyword">long</span></code>
type. The semantics of the constructors and member functions defined below
can be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since <code class="computeroutput"><span class="identifier">long_</span></code>
is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">long_</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">long_</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">long_</span><span class="special">();</span> <span class="comment">// new long_</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
<span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">,</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">base</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.example"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// compute a factorial without overflowing</span>
<span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span> <span class="identifier">fact</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span>
<span class="keyword">return</span> <span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
<span class="keyword">else</span>
<span class="keyword">return</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">fact</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_object_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,297 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/slice.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="prev" href="boost_python_str_hpp.html" title="boost/python/str.hpp">
<link rel="next" href="boost_python_tuple_hpp.html" title="boost/python/tuple.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_str_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_tuple_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_slice_hpp"></a><a class="link" href="boost_python_slice_hpp.html" title="boost/python/slice.hpp">boost/python/slice.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice">Class
<code class="computeroutput"><span class="identifier">slice</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_constructors">Class
<code class="computeroutput"><span class="identifier">slice</span></code> constructors</a></span></dt>
<dt><span class="section"><a href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_observer_functions">Class
<code class="computeroutput"><span class="identifier">slice</span></code> observer functions</a></span></dt>
<dt><span class="section"><a href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_slice_hpp.introduction"></a><a class="link" href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/doc/2.3.3/api/slice-objects.html" target="_top"><code class="computeroutput"><span class="identifier">slice</span></code></a> type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_slice_hpp.class_slice"></a><a class="link" href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice" title="Class slice">Class
<code class="computeroutput"><span class="identifier">slice</span></code></a>
</h3></div></div></div>
<p>
Exposes the extended slicing protocol by wrapping the built-in slice type.
The semantics of the constructors and member functions defined below can
be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since <code class="computeroutput"><span class="identifier">slice</span></code>
is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">slice</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">slice</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">slice</span><span class="special">();</span> <span class="comment">// create an empty slice, equivalent to [::]</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Int1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int2</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">(</span><span class="identifier">Int1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Int2</span> <span class="identifier">stop</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Int1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int3</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">(</span><span class="identifier">Int1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Int2</span> <span class="identifier">stop</span><span class="special">,</span> <span class="identifier">Int3</span> <span class="identifier">step</span><span class="special">);</span>
<span class="comment">// Access the parameters this slice was created with.</span>
<span class="identifier">object</span> <span class="identifier">start</span><span class="special">();</span>
<span class="identifier">object</span> <span class="identifier">stop</span><span class="special">();</span>
<span class="identifier">object</span> <span class="identifier">step</span><span class="special">();</span>
<span class="comment">// The return type of slice::get_indices()</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">RandomAccessIterator</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">range</span>
<span class="special">{</span>
<span class="identifier">RandomAccessIterator</span> <span class="identifier">start</span><span class="special">;</span>
<span class="identifier">RandomAccessIterator</span> <span class="identifier">stop</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">step</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">RandomAccessIterator</span><span class="special">&gt;</span>
<span class="identifier">range</span><span class="special">&lt;</span><span class="identifier">RandomAccessIterator</span><span class="special">&gt;</span>
<span class="identifier">get_indices</span><span class="special">(</span>
<span class="identifier">RandomAccessIterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">begin</span><span class="special">,</span>
<span class="identifier">RandomAccessIterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_slice_hpp.class_slice_constructors"></a><a class="link" href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_constructors" title="Class slice constructors">Class
<code class="computeroutput"><span class="identifier">slice</span></code> constructors</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">slice</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
constructs a slice with default stop, start, and step values. Equivalent
to the slice object created as part of the Python expression <code class="computeroutput"><span class="identifier">base</span><span class="special">[::]</span></code>.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Int1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int2</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">(</span><span class="identifier">Int1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Int2</span> <span class="identifier">stop</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">start</span></code>, <code class="computeroutput"><span class="identifier">stop</span></code>, and <code class="computeroutput"><span class="identifier">step</span></code>
are of type <code class="computeroutput"><span class="identifier">slice_nil</span></code>
or convertible to type <code class="computeroutput"><span class="identifier">object</span></code>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
constructs a new slice with default step value and the provided start
and stop values. Equivalent to the slice object created by the built-in
Python function <code class="computeroutput"><span class="identifier">slice</span><span class="special">(</span><span class="identifier">start</span><span class="special">,</span><span class="identifier">stop</span><span class="special">)</span></code>, or as part of the Python expression
<code class="computeroutput"><span class="identifier">base</span><span class="special">[</span><span class="identifier">start</span><span class="special">:</span><span class="identifier">stop</span><span class="special">]</span></code>.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">error_already_set</span></code>
and sets a Python TypeError exception if no conversion is possible
from the arguments to type object.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Int1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Int3</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">(</span><span class="identifier">Int1</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">Int2</span> <span class="identifier">stop</span><span class="special">,</span> <span class="identifier">Int3</span> <span class="identifier">step</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">start</span></code>, <code class="computeroutput"><span class="identifier">stop</span></code>, and <code class="computeroutput"><span class="identifier">step</span></code>
are <code class="computeroutput"><span class="identifier">slice_nil</span></code> or
convertible to type <code class="computeroutput"><span class="identifier">object</span></code>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
constructs a new slice with start stop and step values. Equivalent
to the slice object created by the built-in Python function <code class="computeroutput"><span class="identifier">slice</span><span class="special">(</span><span class="identifier">start</span><span class="special">,</span><span class="identifier">stop</span><span class="special">,</span><span class="identifier">step</span><span class="special">)</span></code>,
or as part of the Python expression <code class="computeroutput"><span class="identifier">base</span><span class="special">[</span><span class="identifier">start</span><span class="special">:</span><span class="identifier">stop</span><span class="special">:</span><span class="identifier">step</span><span class="special">]</span></code>.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">error_already_set</span></code>
and sets a Python TypeError exception if no conversion is possible
from the arguments to type object.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_slice_hpp.class_slice_observer_functions"></a><a class="link" href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.class_slice_observer_functions" title="Class slice observer functions">Class
<code class="computeroutput"><span class="identifier">slice</span></code> observer functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">slice</span><span class="special">::</span><span class="identifier">start</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">slice</span><span class="special">::</span><span class="identifier">stop</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">slice</span><span class="special">::</span><span class="identifier">step</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
None
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
the parameter that the slice was created with. If the parameter was
omitted or <code class="computeroutput"><span class="identifier">slice_nil</span></code>
was used when the slice was created, than that parameter will be
a reference to <code class="computeroutput"><span class="identifier">PyNone</span></code>
and compare equal to a default-constructed object. In principal,
any object may be used when creating a slice object, but in practice
they are usually integers.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">RandomAccessIterator</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">::</span><span class="identifier">range</span><span class="special">&lt;</span><span class="identifier">RandomAccessIterator</span><span class="special">&gt;</span>
<span class="identifier">slice</span><span class="special">::</span><span class="identifier">get_indices</span><span class="special">(</span>
<span class="identifier">RandomAccessIterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">begin</span><span class="special">,</span>
<span class="identifier">RandomAccessIterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Arguments</span></dt>
<dd><p>
A pair of STL-conforming Random Access Iterators that form a half-open
range.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Create a RandomAccessIterator pair that defines a fully-closed range
within the <code class="computeroutput"><span class="special">[</span><span class="identifier">begin</span><span class="special">,</span><span class="identifier">end</span><span class="special">)</span></code> range of its arguments. This function
translates this slice's indices while accounting for the effects
of any PyNone or negative indices, and non-singular step sizes.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
a <code class="computeroutput"><span class="identifier">slice</span><span class="special">::</span><span class="identifier">range</span></code> that has been initialized
with a non-zero value of step and a pair of RandomAccessIterators
that point within the range of this functions arguments and define
a closed interval.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
Raises a Python TypeError exception if any of this slice's arguments
are neither references to PyNone nor convertible to int. Throws
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span></code> if the resulting
range would be empty. You should always wrap calls to <code class="computeroutput"><span class="identifier">slice</span><span class="special">::</span><span class="identifier">get_indices</span><span class="special">()</span></code>
within <code class="computeroutput"><span class="keyword">try</span> <span class="special">{</span>
<span class="special">...;</span> <span class="special">}</span>
<span class="keyword">catch</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span><span class="special">)</span>
<span class="special">{}</span></code> to handle this case and
take appropriate action.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
closed-interval: If an open interval were used, then for step size
other than 1, the required state for the end iterator would point
beyond the one-past-the-end position or before the beginning of the
specified range. exceptions on empty slice: It is impossible to define
a closed interval over an empty range, so some other form of error
checking would have to be used to prevent undefined behavior. In
the case where the exception is not caught, it will simply be translated
to Python by the default exception handling mechanisms.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_slice_hpp.example"></a><a class="link" href="boost_python_slice_hpp.html#object_wrappers.boost_python_slice_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="comment">// Perform an extended slice of a Python list.</span>
<span class="comment">// Warning: extended slicing was not supported for built-in types prior </span>
<span class="comment">// to Python 2.3</span>
<span class="identifier">list</span> <span class="identifier">odd_elements</span><span class="special">(</span><span class="identifier">list</span> <span class="identifier">l</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">l</span><span class="special">[</span><span class="identifier">slice</span><span class="special">(</span><span class="identifier">_</span><span class="special">,</span><span class="identifier">_</span><span class="special">,</span><span class="number">2</span><span class="special">)];</span>
<span class="special">}</span>
<span class="comment">// Perform a summation over a slice of a std::vector.</span>
<span class="keyword">double</span> <span class="identifier">partial_sum</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">Foo</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">slice</span> <span class="identifier">index</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">slice</span><span class="special">::</span><span class="identifier">range</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span><span class="special">&gt;</span> <span class="identifier">bounds</span><span class="special">;</span>
<span class="keyword">try</span> <span class="special">{</span>
<span class="identifier">bounds</span> <span class="special">=</span> <span class="identifier">index</span><span class="special">.</span><span class="identifier">get_indices</span><span class="special">&lt;&gt;(</span><span class="identifier">Foo</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">Foo</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
<span class="special">}</span>
<span class="keyword">catch</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">return</span> <span class="number">0.0</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">double</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">;</span>
<span class="keyword">while</span> <span class="special">(</span><span class="identifier">bounds</span><span class="special">.</span><span class="identifier">start</span> <span class="special">!=</span> <span class="identifier">bounds</span><span class="special">.</span><span class="identifier">stop</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="special">*</span><span class="identifier">bounds</span><span class="special">.</span><span class="identifier">start</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">advance</span><span class="special">(</span> <span class="identifier">bounds</span><span class="special">.</span><span class="identifier">start</span><span class="special">,</span> <span class="identifier">bounds</span><span class="special">.</span><span class="identifier">step</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="special">*</span><span class="identifier">bounds</span><span class="special">.</span><span class="identifier">start</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">sum</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_str_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_tuple_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,211 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/str.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="prev" href="boost_python_object_hpp.html" title="boost/python/object.hpp">
<link rel="next" href="boost_python_slice_hpp.html" title="boost/python/slice.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_object_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_slice_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_str_hpp"></a><a class="link" href="boost_python_str_hpp.html" title="boost/python/str.hpp">boost/python/str.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.class_str">Class
<code class="computeroutput"><span class="identifier">str</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_str_hpp.introduction"></a><a class="link" href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/dev/doc/devel/lib/string-methods.html" target="_top"><code class="computeroutput"><span class="identifier">str</span></code></a> type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_str_hpp.class_str"></a><a class="link" href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.class_str" title="Class str">Class
<code class="computeroutput"><span class="identifier">str</span></code></a>
</h3></div></div></div>
<p>
Exposes the <a href="http://www.python.org/dev/doc/devel/lib/string-methods.html" target="_top">string
methods</a> of Python's built-in <code class="computeroutput"><span class="identifier">str</span></code>
type. The semantics of the constructors and member functions defined below,
except for the two-argument constructors which construct str objects from
a range of characters, can be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since str is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">str</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">str</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">str</span><span class="special">();</span> <span class="comment">// new str</span>
<span class="identifier">str</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">s</span><span class="special">);</span> <span class="comment">// new str</span>
<span class="identifier">str</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">start</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">finish</span><span class="special">);</span> <span class="comment">// new str</span>
<span class="identifier">str</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">length</span><span class="special">);</span> <span class="comment">// new str</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">str</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">);</span>
<span class="identifier">str</span> <span class="identifier">capitalize</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">center</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">width</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">count</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">count</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span><span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">count</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span><span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">decode</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">decode</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">encoding</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">decode</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">encoding</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">errors</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">object</span> <span class="identifier">encode</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">encode</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">encoding</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">object</span> <span class="identifier">encode</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">encoding</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">errors</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">endswith</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">suffix</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">endswith</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">suffix</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">endswith</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">suffix</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">expandtabs</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">expandtabs</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">tabsize</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">find</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">find</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">find</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">index</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">index</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">index</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">isalnum</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">isalpha</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">isdigit</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">islower</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">isspace</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">istitle</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">isupper</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">join</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sequence</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">ljust</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">width</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">lower</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">lstrip</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">replace</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">old</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">new_</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">replace</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">old</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">new_</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">maxsplit</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rfind</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rfind</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rfind</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rindex</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rindex</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">long</span> <span class="identifier">rindex</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sub</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">rjust</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">width</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">rstrip</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">list</span> <span class="identifier">split</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">list</span> <span class="identifier">split</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sep</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">list</span> <span class="identifier">split</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sep</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">maxsplit</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">list</span> <span class="identifier">splitlines</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">list</span> <span class="identifier">splitlines</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">keepends</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">startswith</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">prefix</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">startswidth</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">prefix</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">startswidth</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">prefix</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">T3</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">end</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">strip</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">swapcase</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">title</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">translate</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">table</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="identifier">str</span> <span class="identifier">translate</span><span class="special">(</span><span class="identifier">T1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">table</span><span class="special">,</span> <span class="identifier">T2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">deletechars</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">upper</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_str_hpp.example"></a><a class="link" href="boost_python_str_hpp.html#object_wrappers.boost_python_str_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">str</span> <span class="identifier">remove_angle_brackets</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">strip</span><span class="special">(</span><span class="char">'&lt;'</span><span class="special">).</span><span class="identifier">strip</span><span class="special">(</span><span class="char">'&gt;'</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_object_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_slice_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,119 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/tuple.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter&#160;3.&#160;Object Wrappers">
<link rel="prev" href="boost_python_slice_hpp.html" title="boost/python/slice.hpp">
<link rel="next" href="../function_invocation_and_creation.html" title="Chapter&#160;4.&#160;Function Invocation and Creation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_slice_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../function_invocation_and_creation.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_tuple_hpp"></a><a class="link" href="boost_python_tuple_hpp.html" title="boost/python/tuple.hpp">boost/python/tuple.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple">Class
<code class="computeroutput"><span class="identifier">tuple</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.function_make_tuple">Function
<code class="computeroutput"><span class="identifier">make_tuple</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_tuple_hpp.introduction"></a><a class="link" href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
for the Python <a href="http://www.python.org/doc/current/tut/node7.html#SECTION007300000000000000000%60tuple%60" target="_top">http://www.python.org/doc/current/tut/node7.html#SECTION007300000000000000000%60tuple%60</a>
type.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_tuple_hpp.class_tuple"></a><a class="link" href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple" title="Class tuple">Class
<code class="computeroutput"><span class="identifier">tuple</span></code></a>
</h3></div></div></div>
<p>
Exposes the interface of Python's built-in tuple type. The semantics of
the constructors and member functions defined below can be fully understood
by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
concept definition. Since tuple is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">tuple</span></code> instances as well.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">tuple</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
<span class="special">{</span>
<span class="comment">// tuple() -&gt; an empty tuple</span>
<span class="identifier">tuple</span><span class="special">();</span>
<span class="comment">// tuple(sequence) -&gt; tuple initialized from sequence's items</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">tuple</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">sequence</span><span class="special">)</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_tuple_hpp.function_make_tuple"></a><a class="link" href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.function_make_tuple" title="Function make_tuple">Function
<code class="computeroutput"><span class="identifier">make_tuple</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="identifier">tuple</span> <span class="identifier">make_tuple</span><span class="special">();</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">&gt;</span>
<span class="identifier">tuple</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="identifier">tuple</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">);</span>
<span class="special">...</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,...</span><span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">tuple</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">,...</span><span class="identifier">An</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">an</span><span class="special">);</span>
<span class="special">}}</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effect</span></dt>
<dd><p>
Constructs a new tuple object composed of <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">a0</span><span class="special">),</span> <span class="identifier">object</span><span class="special">(</span><span class="identifier">a0</span><span class="special">),...</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">an</span><span class="special">)</span></code>.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_tuple_hpp.example"></a><a class="link" href="boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">tuple</span> <span class="identifier">head_and_tail</span><span class="special">(</span><span class="identifier">object</span> <span class="identifier">sequence</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">sequence</span><span class="special">[</span><span class="number">0</span><span class="special">],</span><span class="identifier">sequence</span><span class="special">[-</span><span class="number">1</span><span class="special">]);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_slice_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../function_invocation_and_creation.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,58 @@
index.html
concepts.html
concepts/dereferenceable.html
concepts/extractor.html
concepts/holdergenerator.html
concepts/resultconverter.html
concepts/objectwrapper.html
high_level_components.html
high_level_components/boost_python_def_hpp.html
high_level_components/boost_python_def_visitor_hpp.html
high_level_components/boost_python_docstring_options_h.html
high_level_components/boost_python_enum_hpp.html
high_level_components/boost_python_errors_hpp.html
high_level_components/boost_python_exception_translato.html
high_level_components/boost_python_init_hpp.html
high_level_components/boost_python_iterator_hpp.html
high_level_components/boost_python_module_hpp.html
high_level_components/boost_python_operators_hpp.html
high_level_components/boost_python_scope_hpp.html
high_level_components/boost_python_stl_iterator_hpp.html
high_level_components/boost_python_wrapper_hpp.html
object_wrappers.html
object_wrappers/boost_python_list_hpp.html
object_wrappers/boost_python_long_hpp.html
object_wrappers/boost_python_object_hpp.html
object_wrappers/boost_python_str_hpp.html
object_wrappers/boost_python_slice_hpp.html
object_wrappers/boost_python_tuple_hpp.html
function_invocation_and_creation.html
function_invocation_and_creation/boost_python_call_hpp.html
function_invocation_and_creation/boost_python_call_method_hpp.html
function_invocation_and_creation/boost_python_data_members_hpp.html
function_invocation_and_creation/boost_python_make_function_hpp.html
function_invocation_and_creation/boost_python_overloads_hpp.html
function_invocation_and_creation/boost_python_ptr_hpp.html
function_invocation_and_creation/boost_python_raw_function_hpp.html
function_invocation_and_creation/function_documentation.html
function_invocation_and_creation/models_of_callpolicies.html
function_invocation_and_creation/models_of_resultconverter.html
function_invocation_and_creation/models_of_resultconvertergenerat.html
to_from_python_type_conversion.html
to_from_python_type_conversion/boost_python_implicit_hpp.html
to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html
to_from_python_type_conversion/boost_python_opaque_pointer_conv.html
to_from_python_type_conversion/boost_python_to_python_converter.html
to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html
embedding.html
embedding/boost_python_import_hpp.html
utility_and_infrastructure.html
utility_and_infrastructure/boost_python_instance_holder_hpp.html
utility_and_infrastructure/boost_python_pointee_hpp.html
utility_and_infrastructure/boost_python_handle_hpp.html
utility_and_infrastructure/boost_python_type_id_hpp.html
utility_and_infrastructure/boost_python_ssize_t_hpp.html
topics.html
topics/pickle_support.html
topics/indexing_support.html
glossary.html

View File

@@ -0,0 +1,287 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;5.&#160;To/From Python Type Conversion</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="function_invocation_and_creation/models_of_resultconvertergenerat.html" title="Models of ResultConverterGenerator">
<link rel="next" href="to_from_python_type_conversion/boost_python_implicit_hpp.html" title="boost/python/implicit.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="function_invocation_and_creation/models_of_resultconvertergenerat.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="to_from_python_type_conversion/boost_python_implicit_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="to_from_python_type_conversion"></a>Chapter&#160;5.&#160;To/From Python Type Conversion</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp">boost/python/extract.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract">Class
template <code class="computeroutput"><span class="identifier">extract</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_construct">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> constructors
and destructor</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_observer_">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> observer
functions</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html">boost/python/implicit.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.function_template_implicit_conve">Function
template <code class="computeroutput"><span class="identifier">implicit_convertible</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html">boost/python/lvalue_from_pytype.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html">boost/python/opaque_pointer_converter.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.class_template_opaque_constructo">Class
template <code class="computeroutput"><span class="identifier">opaque</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia">Macro
<code class="computeroutput"><span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span><span class="special">(</span><span class="identifier">Pointee</span><span class="special">)</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html">boost/python/to_python_converter.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html">boost/python/register_ptr_to_python.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.function_register_ptr_to_python">Function
<code class="computeroutput"><span class="identifier">register_ptr_to_python</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.example">Example</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_extract_hpp"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp" title="boost/python/extract.hpp">boost/python/extract.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract">Class
template <code class="computeroutput"><span class="identifier">extract</span></code></a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_construct">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> constructors
and destructor</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_observer_">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> observer
functions</a></span></dt>
<dt><span class="section"><a href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_extract_hpp.introduction"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Exposes a mechanism for extracting C++ object values from generalized Python
objects. Note that <code class="computeroutput"><span class="identifier">extract</span><span class="special">&lt;...&gt;</span></code> can also be used to "downcast"
an <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a> to some specific <a class="link" href="concepts/objectwrapper.html" title="ObjectWrapper">ObjectWrapper</a>. Because invoking
a mutable python type with an argument of the same type (e.g. <code class="computeroutput"><span class="identifier">list</span><span class="special">([</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">]</span></code>) typically makes a copy of the argument
object, this may be the only way to access the <a class="link" href="concepts/objectwrapper.html" title="ObjectWrapper">ObjectWrapper</a>'s
interface on the original object.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract" title="Class template extract">Class
template <code class="computeroutput"><span class="identifier">extract</span></code></a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
can be used to extract a value of an arbitrary C++ type from an instance
of <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object">object</a>.
Two usages are supported:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="computeroutput"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">o</span><span class="special">)</span></code>
is a temporary object which is implicitly convertible to <code class="computeroutput"><span class="identifier">T</span></code> (explicit conversion is also available
through the object's function-call operator). However, if no conversion
is available which can convert o to an object of type <code class="computeroutput"><span class="identifier">T</span></code>, a Python TypeError exception will
be raised.
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">x</span><span class="special">(</span><span class="identifier">o</span><span class="special">);</span></code>
constructs an extractor whose <code class="computeroutput"><span class="identifier">check</span><span class="special">()</span></code> member function can be used to ask
whether a conversion is available without causing an exception to be
thrown.
</li>
</ol></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">extract</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">unspecified</span> <span class="identifier">result_type</span><span class="special">;</span>
<span class="identifier">extract</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*);</span>
<span class="identifier">extract</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;);</span>
<span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">operator</span> <span class="identifier">result_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">check</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_construct"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_construct" title="Class template extract constructors and destructor">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> constructors
and destructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">extract</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="identifier">extract</span><span class="special">(</span><span class="identifier">object</span> <span class="keyword">const</span><span class="special">&amp;);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The first form requires that p is non-null.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Stores a pointer to the Python object managed by its constructor
argument. In particular, the reference count of the object is not
incremented. The onus is on the user to be sure it is not destroyed
before the extractor's conversion function is called.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_observer_"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract_observer_" title="Class template extract observer functions">Class
template <code class="computeroutput"><span class="identifier">extract</span></code> observer
functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">operator</span> <span class="identifier">result_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Converts the stored pointer to result_type, which is either T or
T const&amp;.
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
An object of result_type corresponding to the one referenced by the
stored pointer.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
<a class="link" href="high_level_components/boost_python_errors_hpp.html#high_level_components.boost_python_errors_hpp.class_error_already_set" title="Class error_already_set"><code class="computeroutput"><span class="identifier">error_already_set</span></code></a> and sets
a <code class="computeroutput"><span class="identifier">TypeError</span></code> if no
such conversion is available. May also emit other unspecified exceptions
thrown by the converter which is actually used.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">check</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Postconditions</span></dt>
<dd><p>
None. In particular, note that a return value of true does not preclude
an exception being thrown from operator result_type() or operator()().
</p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
false only if no conversion from the stored pointer to T is available.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_extract_hpp.example"></a><a class="link" href="to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstdio</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">Print</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">s</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// extract a C string from the Python string object</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">c_str</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">s</span><span class="special">);</span>
<span class="comment">// Print it using printf</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span><span class="special">(</span><span class="string">"%s\n"</span><span class="special">,</span> <span class="identifier">c_str</span><span class="special">);</span>
<span class="comment">// Get the Python string's length and convert it to an int</span>
<span class="keyword">return</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__len__"</span><span class="special">)())</span>
<span class="special">}</span>
</pre>
<p>
The following example shows how extract can be used along with <a class="link" href="high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;"><code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;...&gt;</span></code></a>
to create and access an instance of a wrapped C++ class.
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">v</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">int</span> <span class="identifier">value</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">v</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="keyword">int</span> <span class="identifier">v</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">extract_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">object</span> <span class="identifier">x_class</span><span class="special">(</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"value"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">value</span><span class="special">))</span>
<span class="special">;</span>
<span class="comment">// Instantiate an X object through the Python interface. </span>
<span class="comment">// Its lifetime is now managed by x_obj.</span>
<span class="identifier">object</span> <span class="identifier">x_obj</span> <span class="special">=</span> <span class="identifier">x_class</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
<span class="comment">// Get a reference to the C++ object out of the Python object</span>
<span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&amp;&gt;(</span><span class="identifier">x_obj</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">==</span> <span class="number">3</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="function_invocation_and_creation/models_of_resultconvertergenerat.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="to_from_python_type_conversion/boost_python_implicit_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,181 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/implicit.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="prev" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="next" href="boost_python_lvalue_from_pytype_.html" title="boost/python/lvalue_from_pytype.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../to_from_python_type_conversion.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_lvalue_from_pytype_.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_implicit_hpp"></a><a class="link" href="boost_python_implicit_hpp.html" title="boost/python/implicit.hpp">boost/python/implicit.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.function_template_implicit_conve">Function
template <code class="computeroutput"><span class="identifier">implicit_convertible</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_implicit_hpp.introduction"></a><a class="link" href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">implicitly_convertible</span></code>
allows Boost.Python to implicitly take advantage of a C++ implicit or explicit
conversion when matching Python objects to C++ argument types.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_implicit_hpp.function_template_implicit_conve"></a><a class="link" href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.function_template_implicit_conve" title="Function template implicit_convertible">Function
template <code class="computeroutput"><span class="identifier">implicit_convertible</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Source</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Target</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">implicitly_convertible</span><span class="special">();</span>
</pre>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Parameter
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Source
</p>
</td>
<td>
<p>
The source type of the implicit conversion
</p>
</td>
</tr>
<tr>
<td>
<p>
Target
</p>
</td>
<td>
<p>
The target type of the implicit conversion
</p>
</td>
</tr>
</tbody>
</table></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
The declaration <code class="computeroutput"><span class="identifier">Target</span>
<span class="identifier">t</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span></code>,
where s is of type Source, is valid.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
registers an rvalue <code class="computeroutput"><span class="identifier">from_python</span></code>
converter to Target which can succeed for any <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">p</span></code>
iff there exists any registered converter which can produce Source
rvalues
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
C++ users expect to be able to take advantage of the same sort of
interoperability in Python as they do in C++.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_implicit_hpp.example"></a><a class="link" href="boost_python_implicit_hpp.html#to_from_python_type_conversion.boost_python_implicit_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">implicit</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">v</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">operator</span> <span class="keyword">int</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">v</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">v</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">int</span> <span class="identifier">x_value</span><span class="special">(</span><span class="identifier">X</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">X</span> <span class="identifier">make_x</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">X</span><span class="special">(</span><span class="identifier">n</span><span class="special">);</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">implicit_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"x_value"</span><span class="special">,</span> <span class="identifier">x_value</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"make_x"</span><span class="special">,</span> <span class="identifier">make_x</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span>
<span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">;</span>
<span class="identifier">implicitly_convertible</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">,</span><span class="keyword">int</span><span class="special">&gt;();</span>
<span class="identifier">implicitly_convertible</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">X</span><span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
<p>
In Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">implicit_ext</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x_value</span><span class="special">(</span><span class="identifier">X</span><span class="special">(</span><span class="number">42</span><span class="special">))</span>
<span class="number">42</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x_value</span><span class="special">(</span><span class="number">42</span><span class="special">)</span>
<span class="number">42</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">make_x</span><span class="special">(</span><span class="identifier">X</span><span class="special">(</span><span class="number">42</span><span class="special">))</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x_value</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span>
<span class="number">42</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../to_from_python_type_conversion.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_lvalue_from_pytype_.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,305 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/lvalue_from_pytype.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="prev" href="boost_python_implicit_hpp.html" title="boost/python/implicit.hpp">
<link rel="next" href="boost_python_opaque_pointer_conv.html" title="boost/python/opaque_pointer_converter.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_implicit_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_opaque_pointer_conv.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_"></a><a class="link" href="boost_python_lvalue_from_pytype_.html" title="boost/python/lvalue_from_pytype.hpp">boost/python/lvalue_from_pytype.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.introduction"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/lvalue_from_pytype.hpp&gt; supplies a facility for extracting
C++ objects from within Python instances of a given type. This is typically
useful for dealing with "traditional" Python extension types.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp" title="Class template lvalue_from_pytype">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp.class_template_lvalue_from_pytyp">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code>
constructor</a></span></dt></dl></div>
<p>
Class template lvalue_from_pytype will register from_python converters
which, given an object of the given Python type, can extract references
and pointers to a particular C++ type. Its template arguments are:
</p>
<pre class="programlisting"><span class="identifier">In</span> <span class="identifier">the</span> <span class="identifier">table</span> <span class="identifier">below</span><span class="special">,</span> <span class="identifier">x</span> <span class="identifier">denotes</span> <span class="identifier">an</span> <span class="identifier">object</span> <span class="identifier">of</span> <span class="identifier">type</span> <span class="identifier">PythonObject</span><span class="special">&amp;</span>
</pre>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Extractor
</p>
</td>
<td>
<p>
a model of <a class="link" href="../concepts/extractor.html" title="Extractor"><code class="computeroutput"><span class="identifier">Extractor</span></code></a>
whose execute function returns a reference type.
</p>
</td>
<td>
<p>
Extracts the lvalue from the Python object once its type has
been confirmed
</p>
</td>
</tr>
<tr>
<td>
<p>
python_type
</p>
</td>
<td>
<p>
A compile-time constant <a href="http://www.python.org/doc/2.2/ext/dnt-type-methods.html" target="_top"><code class="computeroutput"><span class="identifier">PyTypeObject</span><span class="special">*</span></code></a>
</p>
</td>
<td>
<p>
The Python type of instances convertible by this converter. Python
subtypes are also convertible.
</p>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Extractor</span><span class="special">,</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">python_type</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">lvalue_from_pytype</span>
<span class="special">{</span>
<span class="identifier">lvalue_from_pytype</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp.class_template_lvalue_from_pytyp"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp.class_template_lvalue_from_pytyp" title="Class template lvalue_from_pytype constructor">Class
template <code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code>
constructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">lvalue_from_pytype</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Registers converters which can convert Python objects of the given
type to lvalues of the type returned by Extractor::execute.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity" title="Class template extract_identity">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity.class_template_extract_identity_">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code>
static functions</a></span></dt></dl></div>
<p>
extract_identity is a model of <a class="link" href="../concepts/extractor.html" title="Extractor"><code class="computeroutput"><span class="identifier">Extractor</span></code></a> which can be used in
the common case where the C++ type to be extracted is the same as the Python
object type.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">InstanceType</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">extract_identity</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">execute</span><span class="special">(</span><span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity.class_template_extract_identity_"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_identity.class_template_extract_identity_" title="Class template extract_identity static functions">Class
template <code class="computeroutput"><span class="identifier">extract_identity</span></code>
static functions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">execute</span><span class="special">(</span><span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
c
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member" title="Class template extract_member">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member.class_template_extract_member_st">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code>
static functions</a></span></dt></dl></div>
<p>
<code class="computeroutput"><span class="identifier">extract_member</span></code> is a model
of <a class="link" href="../concepts/extractor.html" title="Extractor"><code class="computeroutput"><span class="identifier">Extractor</span></code></a>
which can be used in the common case in the common case where the C++ type
to be extracted is a member of the Python object.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">InstanceType</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">MemberType</span><span class="special">,</span> <span class="identifier">MemberType</span> <span class="special">(</span><span class="identifier">InstanceType</span><span class="special">::*</span><span class="identifier">member</span><span class="special">)&gt;</span>
<span class="keyword">struct</span> <span class="identifier">extract_member</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">MemberType</span><span class="special">&amp;</span> <span class="identifier">execute</span><span class="special">(</span><span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member.class_template_extract_member_st"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_extract_member.class_template_extract_member_st" title="Class template extract_member static functions">Class
template <code class="computeroutput"><span class="identifier">extract_member</span></code>
static functions</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">MemberType</span><span class="special">&amp;</span> <span class="identifier">execute</span><span class="special">(</span><span class="identifier">InstanceType</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">c</span><span class="special">.*</span><span class="identifier">member</span></code>
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_lvalue_from_pytype_.example"></a><a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.example" title="Example">Example</a>
</h3></div></div></div>
<p>
This example presumes that someone has implemented the standard noddy example
module from the Python documentation, and we want to build a module which
manipulates Noddys. Since noddy_NoddyObject is so simple that it carries
no interesting information, the example is a bit contrived: it assumes
you want to keep track of one particular object for some reason. This module
would have to be dynamically linked to the module which defines noddy_NoddyType.
</p>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">handle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">borrowed</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">lvalue_from_pytype</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// definition lifted from the Python docs</span>
<span class="keyword">typedef</span> <span class="keyword">struct</span> <span class="special">{</span>
<span class="identifier">PyObject_HEAD</span>
<span class="special">}</span> <span class="identifier">noddy_NoddyObject</span><span class="special">;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">noddy_NoddyObject</span><span class="special">&gt;</span> <span class="identifier">cache</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="identifier">is_cached</span><span class="special">(</span><span class="identifier">noddy_NoddyObject</span><span class="special">*</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span> <span class="special">==</span> <span class="identifier">cache</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">set_cache</span><span class="special">(</span><span class="identifier">noddy_NoddyObject</span><span class="special">*</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">cache</span> <span class="special">=</span> <span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">noddy_NoddyObject</span><span class="special">&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">x</span><span class="special">));</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">noddy_cache</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"is_cached"</span><span class="special">,</span> <span class="identifier">is_cached</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"set_cache"</span><span class="special">,</span> <span class="identifier">set_cache</span><span class="special">);</span>
<span class="comment">// register Noddy lvalue converter</span>
<span class="identifier">lvalue_from_pytype</span><span class="special">&lt;</span><span class="identifier">extract_identity</span><span class="special">&lt;</span><span class="identifier">noddy_NoddyObject</span><span class="special">&gt;,&amp;</span><span class="identifier">noddy_NoddyType</span><span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
<p>
In Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">noddy</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">n</span> <span class="special">=</span> <span class="identifier">noddy</span><span class="special">.</span><span class="identifier">new_noddy</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">noddy_cache</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">noddy_cache</span><span class="special">.</span><span class="identifier">is_cached</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">noddy_cache</span><span class="special">.</span><span class="identifier">set_cache</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">noddy_cache</span><span class="special">.</span><span class="identifier">is_cached</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span>
<span class="number">1</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">noddy_cache</span><span class="special">.</span><span class="identifier">is_cached</span><span class="special">(</span><span class="identifier">noddy</span><span class="special">.</span><span class="identifier">new_noddy</span><span class="special">())</span>
<span class="number">0</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_implicit_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_opaque_pointer_conv.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,118 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/opaque_pointer_converter.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="prev" href="boost_python_lvalue_from_pytype_.html" title="boost/python/lvalue_from_pytype.hpp">
<link rel="next" href="boost_python_to_python_converter.html" title="boost/python/to_python_converter.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_lvalue_from_pytype_.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_to_python_converter.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_opaque_pointer_conv"></a><a class="link" href="boost_python_opaque_pointer_conv.html" title="boost/python/opaque_pointer_converter.hpp">boost/python/opaque_pointer_converter.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.class_template_opaque_constructo">Class
template <code class="computeroutput"><span class="identifier">opaque</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia">Macro
<code class="computeroutput"><span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span><span class="special">(</span><span class="identifier">Pointee</span><span class="special">)</span></code></a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_opaque_pointer_conv.introduction"></a><a class="link" href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">opaque</span><span class="special">&lt;&gt;</span></code>
registers itself as a converter from Python objects to pointers to undefined
types and vice versa.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Pointee</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">opaque</span>
<span class="special">{</span>
<span class="identifier">opaque</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_opaque_pointer_conv.class_template_opaque_constructo"></a><a class="link" href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.class_template_opaque_constructo" title="Class template opaque constructor">Class
template <code class="computeroutput"><span class="identifier">opaque</span></code> constructor</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">opaque</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Registers the instance as a <a class="link" href="boost_python_lvalue_from_pytype_.html#to_from_python_type_conversion.boost_python_lvalue_from_pytype_.class_template_lvalue_from_pytyp" title="Class template lvalue_from_pytype"><code class="computeroutput"><span class="identifier">lvalue_from_pytype</span></code></a> converter
from Python objects into opaque pointers. The Python Objects
created are named after the type pointed to by the opaque pointer
being wrapped.
</li>
<li class="listitem">
Registers the instance as a <a class="link" href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert" title="Class template to_python_converter"><code class="computeroutput"><span class="identifier">to_python_converter</span></code></a>
from opaque pointers to Python objects.
</li>
</ul></div></dd>
</dl>
</div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
If there is already an instance registered by another module, this instance
doesn't try to register again in order to avoid warnings about multiple
registrations.
</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia"></a><a class="link" href="boost_python_opaque_pointer_conv.html#to_from_python_type_conversion.boost_python_opaque_pointer_conv.macro_boost_python_opaque_specia" title="Macro BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(Pointee)">Macro
<code class="computeroutput"><span class="identifier">BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</span><span class="special">(</span><span class="identifier">Pointee</span><span class="special">)</span></code></a>
</h3></div></div></div>
<p>
This macro must be used to define specializations of the <a class="link" href="../utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions" title="Functions"><code class="computeroutput"><span class="identifier">type_id</span></code></a> function which can't be
instantiated for incomplete types.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The macro must be invoked in every translation unit which uses the opaque
converter.
</p></td></tr>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_lvalue_from_pytype_.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_to_python_converter.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,166 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/register_ptr_to_python.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="prev" href="boost_python_to_python_converter.html" title="boost/python/to_python_converter.hpp">
<link rel="next" href="../embedding.html" title="Chapter&#160;6.&#160;Embedding">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_to_python_converter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../embedding.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_register_ptr_to_pyt"></a><a class="link" href="boost_python_register_ptr_to_pyt.html" title="boost/python/register_ptr_to_python.hpp">boost/python/register_ptr_to_python.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.function_register_ptr_to_python">Function
<code class="computeroutput"><span class="identifier">register_ptr_to_python</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_register_ptr_to_pyt.introduction"></a><a class="link" href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/register_ptr_to_python.hpp&gt; supplies <code class="computeroutput"><span class="identifier">register_ptr_to_python</span></code>, a function template
which registers a conversion for smart pointers to Python. The resulting
Python object holds a copy of the converted smart pointer, but behaves
as though it were a wrapped copy of the pointee. If the pointee type has
virtual functions and the class representing its dynamic (most-derived)
type has been wrapped, the Python object will be an instance of the wrapper
for the most-derived type. More than one smart pointer type for a pointee's
class can be registered.
</p>
<p>
Note that in order to convert a Python <code class="computeroutput"><span class="identifier">X</span></code>
object to a <code class="computeroutput"><span class="identifier">smart_ptr</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;&amp;</span></code>
(non-const reference), the embedded C++ object must be held by <code class="computeroutput"><span class="identifier">smart_ptr</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span></code>,
and that when wrapped objects are created by calling the constructor from
Python, how they are held is determined by the HeldType parameter to <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;...&gt;</span></code>
instances.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_register_ptr_to_pyt.function_register_ptr_to_python"></a><a class="link" href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.function_register_ptr_to_python" title="Function register_ptr_to_python">Function
<code class="computeroutput"><span class="identifier">register_ptr_to_python</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">P</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">register_ptr_to_python</span><span class="special">()</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">P</span></code> is <a class="link" href="../concepts/dereferenceable.html" title="Dereferenceable">Dereferenceable</a>.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
Allows conversions to-python of P instances.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_register_ptr_to_pyt.example"></a><a class="link" href="boost_python_register_ptr_to_pyt.html#to_from_python_type_conversion.boost_python_register_ptr_to_pyt.example" title="Example">Example</a>
</h3></div></div></div>
<p>
Here is an example of a module that contains a class A with virtual functions
and some functions that work with boost::shared_ptr&lt;A&gt;.
</p>
<p>
In C++:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">A</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
<span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="identifier">New</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;(</span> <span class="keyword">new</span> <span class="identifier">A</span><span class="special">()</span> <span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">Ok</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;&amp;</span> <span class="identifier">a</span> <span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">a</span><span class="special">-&gt;</span><span class="identifier">f</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">Fail</span><span class="special">(</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;&amp;</span> <span class="identifier">a</span> <span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">a</span><span class="special">-&gt;</span><span class="identifier">f</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">struct</span> <span class="identifier">A_Wrapper</span><span class="special">:</span> <span class="identifier">A</span>
<span class="special">{</span>
<span class="identifier">A_Wrapper</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self_</span><span class="special">):</span> <span class="identifier">self</span><span class="special">(</span><span class="identifier">self_</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">call_method</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">self</span><span class="special">,</span> <span class="string">"f"</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">default_f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">();</span> <span class="special">}</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">register_ptr</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">A_Wrapper</span><span class="special">&gt;(</span><span class="string">"A"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">A_Wrapper</span><span class="special">::</span><span class="identifier">default_f</span><span class="special">)</span>
<span class="special">;</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"New"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">New</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"Ok"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Call</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"Fail"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Fail</span><span class="special">);</span>
<span class="identifier">register_ptr_to_python</span><span class="special">&lt;</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
<p>
In Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">register_ptr</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">a</span> <span class="special">=</span> <span class="identifier">A</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">Ok</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">ok</span><span class="special">,</span> <span class="identifier">passed</span> <span class="identifier">as</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">Fail</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">passed</span> <span class="identifier">as</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;&amp;,</span> <span class="keyword">and</span> <span class="identifier">was</span> <span class="identifier">created</span> <span class="identifier">in</span> <span class="identifier">Python</span><span class="special">!</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">"&lt;stdin&gt;"</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">?</span>
<span class="identifier">TypeError</span><span class="special">:</span> <span class="identifier">bad</span> <span class="identifier">argument</span> <span class="identifier">type</span> <span class="keyword">for</span> <span class="identifier">built</span><span class="special">-</span><span class="identifier">in</span> <span class="identifier">operation</span>
<span class="special">&gt;&gt;&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">na</span> <span class="special">=</span> <span class="identifier">New</span><span class="special">()</span> <span class="special">#</span> <span class="identifier">now</span> <span class="string">"na"</span> <span class="identifier">is</span> <span class="identifier">actually</span> <span class="identifier">a</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">Ok</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">Fail</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span>
</pre>
<p>
If shared_ptr&lt;A&gt; is registered as follows:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">A_Wrapper</span><span class="special">,</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"A"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">A</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">A_Wrapper</span><span class="special">::</span><span class="identifier">default_f</span><span class="special">)</span>
<span class="special">;</span>
</pre>
<p>
There will be an error when trying to convert shared_ptr&lt;A&gt; to shared_ptr&lt;A_Wrapper&gt;:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">a</span> <span class="special">=</span> <span class="identifier">New</span><span class="special">()</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">"&lt;stdin&gt;"</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">?</span>
<span class="identifier">TypeError</span><span class="special">:</span> <span class="identifier">No</span> <span class="identifier">to_python</span> <span class="special">(</span><span class="identifier">by</span><span class="special">-</span><span class="identifier">value</span><span class="special">)</span> <span class="identifier">converter</span> <span class="identifier">found</span> <span class="keyword">for</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">type</span><span class="special">:</span> <span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="keyword">struct</span> <span class="identifier">A</span><span class="special">&gt;</span>
<span class="special">&gt;&gt;&gt;</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_to_python_converter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../embedding.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,252 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/to_python_converter.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../to_from_python_type_conversion.html" title="Chapter&#160;5.&#160;To/From Python Type Conversion">
<link rel="prev" href="boost_python_opaque_pointer_conv.html" title="boost/python/opaque_pointer_converter.hpp">
<link rel="next" href="boost_python_register_ptr_to_pyt.html" title="boost/python/register_ptr_to_python.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_opaque_pointer_conv.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_register_ptr_to_pyt.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="to_from_python_type_conversion.boost_python_to_python_converter"></a><a class="link" href="boost_python_to_python_converter.html" title="boost/python/to_python_converter.hpp">boost/python/to_python_converter.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_to_python_converter.introduction"></a><a class="link" href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">to_python_converter</span></code> registers
a conversion from objects of a given C++ type into a Python object.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert"></a><a class="link" href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert" title="Class template to_python_converter">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert.class_template_to_python_convert">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code>
constructor</a></span></dt></dl></div>
<p>
<code class="computeroutput"><span class="identifier">to_python_converter</span></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.
</p>
<p>
In the table below, x denotes an object of type T
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
T
</p>
</td>
<td>
</td>
<td>
<p>
The C++ type of the source object in the conversion
</p>
</td>
</tr>
<tr>
<td>
<p>
Conversion
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span>
<span class="identifier">p</span> <span class="special">=</span>
<span class="identifier">Conversion</span><span class="special">::</span><span class="identifier">convert</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>,
<code class="computeroutput"><span class="keyword">if</span> <span class="identifier">p</span>
<span class="special">==</span> <span class="number">0</span></code>,
<code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span> <span class="special">!=</span>
<span class="number">0</span></code>.
</p>
</td>
<td>
<p>
A class type whose static member function convert does the real
work of the conversion.
</p>
</td>
</tr>
<tr>
<td>
<p>
bool has_get_pytype=false
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">PyTypeObject</span> <span class="keyword">const</span> <span class="special">*</span>
<span class="identifier">p</span> <span class="special">=</span>
<span class="identifier">Conversion</span><span class="special">::</span><span class="identifier">get_pytype</span><span class="special">()</span></code>
</p>
</td>
<td>
<p>
Optional member - if Conversion has <code class="computeroutput"><span class="identifier">get_pytype</span></code>
member supply <code class="computeroutput"><span class="keyword">true</span></code>
for this parameters. If present <code class="computeroutput"><span class="identifier">get_pytype</span></code>
is used to document the return type of functions using this conversion.
The <code class="computeroutput"><span class="identifier">get_pytype</span></code>
may be implemented using the classes and functions from pytype_function.hpp
NOTE : For backward compatibility this parameter may be passed
after checking if BOOST_PYTHON_SUPPORTS_PY_SIGNATURES is defined
(see <a class="link" href="../function_invocation_and_creation/function_documentation.html#function_invocation_and_creation.function_documentation.boost_python_pytype_function_hpp.example" title="Example">here</a>).
</p>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Conversion</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">convertion_has_get_pytype_member</span><span class="special">=</span><span class="keyword">false</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">to_python_converter</span>
<span class="special">{</span>
<span class="identifier">to_python_converter</span><span class="special">();</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert.class_template_to_python_convert"></a><a class="link" href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.class_template_to_python_convert.class_template_to_python_convert" title="Class template to_python_converter constructor">Class
template <code class="computeroutput"><span class="identifier">to_python_converter</span></code>
constructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">to_python_converter</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Registers a <code class="computeroutput"><span class="identifier">to_python</span></code>
converter which uses <code class="computeroutput"><span class="identifier">Conversion</span><span class="special">::</span><span class="identifier">convert</span><span class="special">()</span></code> to do its work.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="to_from_python_type_conversion.boost_python_to_python_converter.example"></a><a class="link" href="boost_python_to_python_converter.html#to_from_python_type_conversion.boost_python_to_python_converter.example" title="Example">Example</a>
</h3></div></div></div>
<p>
This example presumes that someone has implemented the standard noddy example
module from the Python documentation, and placed the corresponding declarations
in "noddy.h". Because noddy_NoddyObject is the ultimate trivial
extension type, the example is a bit contrived: it wraps a function for
which all information is contained in the type of its return value.
</p>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="string">"noddy.h"</span>
<span class="keyword">struct</span> <span class="identifier">tag</span> <span class="special">{};</span>
<span class="identifier">tag</span> <span class="identifier">make_tag</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">tag</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">tag_to_noddy</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">tag</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">PyObject_New</span><span class="special">(</span><span class="identifier">noddy_NoddyObject</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">noddy_NoddyType</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="identifier">PyTypeObject</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">get_pytype</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="special">&amp;</span><span class="identifier">noddy_NoddyType</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">to_python_converter</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"make_tag"</span><span class="special">,</span> <span class="identifier">make_tag</span><span class="special">);</span>
<span class="identifier">to_python_converter</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">,</span> <span class="identifier">tag_to_noddy</span><span class="special">,</span> <span class="keyword">true</span><span class="special">&gt;();</span> <span class="comment">//"true" because tag_to_noddy has member get_pytype</span>
<span class="special">}</span>
</pre>
<p>
In Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">import</span> <span class="identifier">to_python_converter</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">def</span> <span class="identifier">always_none</span><span class="special">():</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="identifier">None</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">def</span> <span class="identifier">choose_function</span><span class="special">(</span><span class="identifier">x</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">x</span> <span class="special">%</span> <span class="number">2</span> <span class="special">!=</span> <span class="number">0</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="identifier">to_python_converter</span><span class="special">.</span><span class="identifier">make_tag</span>
<span class="special">...</span> <span class="keyword">else</span><span class="special">:</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="identifier">always_none</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">a</span> <span class="special">=</span> <span class="special">[</span> <span class="identifier">choose_function</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="keyword">for</span> <span class="identifier">x</span> <span class="identifier">in</span> <span class="identifier">range</span><span class="special">(</span><span class="number">5</span><span class="special">)</span> <span class="special">]</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">b</span> <span class="special">=</span> <span class="special">[</span> <span class="identifier">f</span><span class="special">()</span> <span class="keyword">for</span> <span class="identifier">f</span> <span class="identifier">in</span> <span class="identifier">a</span> <span class="special">]</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">type</span><span class="special">(</span><span class="identifier">b</span><span class="special">[</span><span class="number">0</span><span class="special">])</span>
<span class="special">&lt;</span><span class="identifier">type</span> <span class="char">'NoneType'</span><span class="special">&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">type</span><span class="special">(</span><span class="identifier">b</span><span class="special">[</span><span class="number">1</span><span class="special">])</span>
<span class="special">&lt;</span><span class="identifier">type</span> <span class="char">'Noddy'</span><span class="special">&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">type</span><span class="special">(</span><span class="identifier">b</span><span class="special">[</span><span class="number">2</span><span class="special">])</span>
<span class="special">&lt;</span><span class="identifier">type</span> <span class="char">'NoneType'</span><span class="special">&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">type</span><span class="special">(</span><span class="identifier">b</span><span class="special">[</span><span class="number">3</span><span class="special">])</span>
<span class="special">&lt;</span><span class="identifier">type</span> <span class="char">'Noddy'</span><span class="special">&gt;</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_opaque_pointer_conv.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../to_from_python_type_conversion.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_register_ptr_to_pyt.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,332 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;8.&#160;Topics</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="utility_and_infrastructure/boost_python_ssize_t_hpp.html" title="boost/python/ssize_t.hpp">
<link rel="next" href="topics/pickle_support.html" title="Pickle support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="utility_and_infrastructure/boost_python_ssize_t_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="topics/pickle_support.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="topics"></a>Chapter&#160;8.&#160;Topics</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met">Calling Python
Functions and Methods</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.argument_handling">Argument
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.result_handling">Result
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.rationale">Rationale</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="topics/pickle_support.html">Pickle support</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.the_pickle_interface">The Pickle
Interface</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.example">Example</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.pitfall_and_safety_guard">Pitfall
and Safety Guard</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.practical_advice">Practical Advice</a></span></dt>
<dt><span class="section"><a href="topics/pickle_support.html#topics.pickle_support.light_weight_alternative_pickle_">Light-weight
alternative: pickle support implemented in Python</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="topics/indexing_support.html">Indexing support</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.the_indexing_interface">The
Indexing Interface</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.index_suite_sub_classes">index_suite
sub-classes</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.indexing_suite_class"><code class="computeroutput"><span class="identifier">indexing_suite</span></code> class</a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.class_vector_indexing_suite">class
<code class="computeroutput"><span class="identifier">vector_indexing_suite</span></code></a></span></dt>
<dt><span class="section"><a href="topics/indexing_support.html#topics.indexing_support.class_map_indexing_suite">class
<code class="computeroutput"><span class="identifier">map_indexing_suite</span></code></a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="topics.calling_python_functions_and_met"></a><a class="link" href="topics.html#topics.calling_python_functions_and_met" title="Calling Python Functions and Methods">Calling Python
Functions and Methods</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.argument_handling">Argument
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.result_handling">Result
Handling</a></span></dt>
<dt><span class="section"><a href="topics.html#topics.calling_python_functions_and_met.rationale">Rationale</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.calling_python_functions_and_met.introduction"></a><a class="link" href="topics.html#topics.calling_python_functions_and_met.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
The simplest way to call a Python function from C++, given an <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a> instance f holding the
function, is simply to invoke its function call operator.
</p>
<pre class="programlisting"><span class="identifier">f</span><span class="special">(</span><span class="string">"tea"</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="comment">// In Python: f('tea', 4, 2)</span></pre>
<p>
And of course, a method of an <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a> instance <code class="computeroutput"><span class="identifier">x</span></code> can be invoked by using the function-call
operator of the corresponding attribute:
</p>
<pre class="programlisting"><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"tea"</span><span class="special">)(</span><span class="number">4</span><span class="special">,</span> <span class="number">2</span><span class="special">);</span> <span class="comment">// In Python: x.tea(4, 2)</span></pre>
<p>
If you don't have an <a class="link" href="object_wrappers/boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a> instance, <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code> provides two families of function
templates, <a class="link" href="function_invocation_and_creation/boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call" title="Function call"><code class="computeroutput"><span class="identifier">call</span></code></a> and <a class="link" href="function_invocation_and_creation/boost_python_call_method_hpp.html#function_invocation_and_creation.boost_python_call_method_hpp.function_call_method" title="Function call_method"><code class="computeroutput"><span class="identifier">call_method</span></code></a>, for invoking Python
functions and methods respectively on <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>s. The interface for calling a Python function
object (or any Python callable object) looks like:
</p>
<pre class="programlisting"><span class="identifier">call</span><span class="special">&lt;</span><span class="identifier">ResultType</span><span class="special">&gt;(</span><span class="identifier">callable_object</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">...</span> <span class="identifier">aN</span><span class="special">);</span></pre>
<p>
Calling a method of a Python object is similarly easy:
</p>
<pre class="programlisting"><span class="identifier">call_method</span><span class="special">&lt;</span><span class="identifier">ResultType</span><span class="special">&gt;(</span><span class="identifier">self_object</span><span class="special">,</span> <span class="string">"method-name"</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">...</span> <span class="identifier">aN</span><span class="special">);</span></pre>
<p>
This comparitively low-level interface is the one you'll use when implementing
C++ virtual functions that can be overridden in Python.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.calling_python_functions_and_met.argument_handling"></a><a class="link" href="topics.html#topics.calling_python_functions_and_met.argument_handling" title="Argument Handling">Argument
Handling</a>
</h3></div></div></div>
<p>
Arguments are converted to Python according to their type. By default,
the arguments <code class="computeroutput"><span class="identifier">a1</span><span class="special">...</span><span class="identifier">aN</span></code> are copied into new Python objects,
but this behavior can be overridden by the use of <a class="link" href="function_invocation_and_creation/boost_python_ptr_hpp.html#function_invocation_and_creation.boost_python_ptr_hpp.functions" title="Functions"><code class="computeroutput"><span class="identifier">ptr</span><span class="special">()</span></code></a>
and <code class="computeroutput"><span class="identifier">ref</span><span class="special">()</span></code>:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">};</span>
<span class="keyword">void</span> <span class="identifier">apply</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">callable</span><span class="special">,</span> <span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// Invoke callable, passing a Python object which holds a reference to x</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(</span><span class="identifier">callable</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">x</span><span class="special">));</span>
<span class="special">}</span>
</pre>
<p>
In the table below, x denotes the actual argument object and cv denotes
an optional cv-qualification: "const", "volatile",
or "const volatile".
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Argument Type
</p>
</th>
<th>
<p>
Behavior
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">T</span> <span class="identifier">cv</span>
<span class="special">&amp;</span></code> <code class="computeroutput"><span class="identifier">T</span>
<span class="identifier">cv</span></code>
</p>
</td>
<td>
<p>
The Python argument is created by the same means used for the
return value of a wrapped C++ function returning T. When T is
a class type, that normally means *x is copy-constructed into
the new Python object.
</p>
</td>
</tr>
<tr>
<td>
<p>
T*
</p>
</td>
<td>
<p>
If x == 0, the Python argument will be None. Otherwise, the Python
argument is created by the same means used for the return value
of a wrapped C++ function returning T. When T is a class type,
that normally means *x is copy-constructed into the new Python
object.
</p>
</td>
</tr>
<tr>
<td>
<p>
boost::reference_wrapper&lt;T&gt;
</p>
</td>
<td>
<p>
The Python argument contains a pointer to, rather than a copy
of, x.get(). Note: failure to ensure that no Python code holds
a reference to the resulting object beyond the lifetime of *x.get()
may result in a crash!
</p>
</td>
</tr>
<tr>
<td>
<p>
pointer_wrapper&lt;T&gt;
</p>
</td>
<td>
<p>
If x.get() == 0, the Python argument will be None. Otherwise,
the Python argument contains a pointer to, rather than a copy
of, *x.get(). Note: failure to ensure that no Python code holds
a reference to the resulting object beyond the lifetime of *x.get()
may result in a crash!
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.calling_python_functions_and_met.result_handling"></a><a class="link" href="topics.html#topics.calling_python_functions_and_met.result_handling" title="Result Handling">Result
Handling</a>
</h3></div></div></div>
<p>
In general, <code class="computeroutput"><span class="identifier">call</span><span class="special">&lt;</span><span class="identifier">ResultType</span><span class="special">&gt;()</span></code>
and call_method&lt;ResultType&gt;() return ResultType by exploiting all
lvalue and rvalue from_python converters registered for ResultType and
returning a copy of the result. However, when ResultType is a pointer or
reference type, Boost.Python searches only for lvalue converters. To prevent
dangling pointers and references, an exception will be thrown if the Python
result object has only a single reference count.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.calling_python_functions_and_met.rationale"></a><a class="link" href="topics.html#topics.calling_python_functions_and_met.rationale" title="Rationale">Rationale</a>
</h3></div></div></div>
<p>
In general, to get Python arguments corresponding to a1...aN, a new Python
object must be created for each one; should the C++ object be copied into
that Python object, or should the Python object simply hold a reference/pointer
to the C++ object? In general, the latter approach is unsafe, since the
called function may store a reference to the Python object somewhere. If
the Python object is used after the C++ object is destroyed, we'll crash
Python.
</p>
<p>
In keeping with the philosophy that users on the Python side shouldn't
have to worry about crashing the interpreter, the default behavior is to
copy the C++ object, and to allow a non-copying behavior only if the user
writes boost::ref(a1) instead of a1 directly. At least this way, the user
doesn't get dangerous behavior "by accident". It's also worth
noting that the non-copying ("by-reference") behavior is in general
only available for class types, and will fail at runtime with a Python
exception if used otherwise[1].
</p>
<p>
However, pointer types present a problem: one approach is to refuse to
compile if any aN has pointer type: after all, a user can always pass *aN
to pass "by-value" or ref(*aN) to indicate a pass-by-reference
behavior. However, this creates a problem for the expected null pointer
to None conversion: it's illegal to dereference a null pointer value.
</p>
<p>
The compromise I've settled on is this:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
The default behavior is pass-by-value. If you pass a non-null pointer,
the pointee is copied into a new Python object; otherwise the corresponding
Python argument will be None.
</li>
<li class="listitem">
if you want by-reference behavior, use ptr(aN) if aN is a pointer and
ref(aN) otherwise. If a null pointer is passed to ptr(aN), the corresponding
Python argument will be None.
</li>
</ol></div>
<p>
As for results, we have a similar problem: if ResultType is allowed to
be a pointer or reference type, the lifetime of the object it refers to
is probably being managed by a Python object. When that Python object is
destroyed, our pointer dangles. The problem is particularly bad when the
ResultType is char const* - the corresponding Python String object is typically
uniquely-referenced, meaning that the pointer dangles as soon as call&lt;char
const*&gt;(...) returns.
</p>
<p>
The old Boost.Python v1 deals with this issue by refusing to compile any
uses of call&lt;char const*&gt;(), but this goes both too far and not far
enough. It goes too far because there are cases where the owning Python
string object survives beyond the call (just for instance, when it's the
name of a Python class), and it goes not far enough because we might just
as well have the same problem with a returned pointer or reference of any
other type.
</p>
<p>
In Boost.Python this is dealt with by:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
lifting the compile-time restriction on <code class="computeroutput"><span class="keyword">char</span>
<span class="keyword">const</span> <span class="special">*</span></code>
callback returns
</li>
<li class="listitem">
detecting the case when the reference count on the result Python object
is 1 and throwing an exception inside of <code class="computeroutput"><span class="identifier">call</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;(...)</span></code> when <code class="computeroutput"><span class="identifier">U</span></code>
is a pointer or reference type.
</li>
</ol></div>
<p>
This should be acceptably safe because users have to explicitly specify
a pointer/reference for <code class="computeroutput"><span class="identifier">U</span></code>
in <code class="computeroutput"><span class="identifier">call</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;</span></code>,
and they will be protected against dangles at runtime, at least long enough
to get out of the <code class="computeroutput"><span class="identifier">call</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;(...)</span></code> invocation.
</p>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="utility_and_infrastructure/boost_python_ssize_t_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="topics/pickle_support.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,832 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Indexing support</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../topics.html" title="Chapter&#160;8.&#160;Topics">
<link rel="prev" href="pickle_support.html" title="Pickle support">
<link rel="next" href="../glossary.html" title="Chapter&#160;9.&#160;Glossary">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="pickle_support.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../topics.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../glossary.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="topics.indexing_support"></a><a class="link" href="indexing_support.html" title="Indexing support">Indexing support</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.the_indexing_interface">The
Indexing Interface</a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.index_suite_sub_classes">index_suite
sub-classes</a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.indexing_suite_class"><code class="computeroutput"><span class="identifier">indexing_suite</span></code> class</a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.class_vector_indexing_suite">class
<code class="computeroutput"><span class="identifier">vector_indexing_suite</span></code></a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.class_map_indexing_suite">class
<code class="computeroutput"><span class="identifier">map_indexing_suite</span></code></a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.introduction"></a><a class="link" href="indexing_support.html#topics.indexing_support.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Indexing is a <code class="computeroutput"><span class="identifier">Boost</span> <span class="identifier">Python</span></code>
facility for easy exportation of indexable C++ containers to Python. Indexable
containers are containers that allow random access through the <code class="computeroutput"><span class="keyword">operator</span><span class="special">[]</span></code>
(e.g. <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>).
</p>
<p>
While <code class="computeroutput"><span class="identifier">Boost</span> <span class="identifier">Python</span></code>
has all the facilities needed to expose indexable C++ containers such as
the ubiquitous std::vector to Python, the procedure is not as straightforward
as we'd like it to be. Python containers do not map easily to C++ containers.
Emulating Python containers in C++ (see Python Reference Manual, <a href="http://www.python.org/doc/current/ref/sequence-types.html" target="_top">Emulating
container types</a>) using <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code>
is non trivial. There are a lot of issues to consider before we can map
a C++ container to Python. These involve implementing wrapper functions
for the methods <code class="computeroutput"><span class="identifier">__len__</span></code>,
<code class="computeroutput"><span class="identifier">__getitem__</span></code>, <code class="computeroutput"><span class="identifier">__setitem__</span></code>, <code class="computeroutput"><span class="identifier">__delitem__</span></code>,
<code class="computeroutput"><span class="identifier">__iter__</span></code> and <code class="computeroutput"><span class="identifier">__contains__</span></code>.
</p>
<p>
The goals:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Make indexable C++ containers behave exactly as one would expect a
Python container to behave.
</li>
<li class="listitem">
<p class="simpara">
Provide default reference semantics for container element indexing
(<code class="computeroutput"><span class="identifier">__getitem__</span></code>) such
that c[i] can be mutable. Require:
</p>
<pre class="programlisting"><span class="identifier">val</span> <span class="special">=</span> <span class="identifier">c</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span>
<span class="identifier">c</span><span class="special">[</span><span class="identifier">i</span><span class="special">].</span><span class="identifier">m</span><span class="special">()</span>
<span class="identifier">val</span> <span class="special">==</span> <span class="identifier">c</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span>
</pre>
<p class="simpara">
where m is a non-const (mutating) member function (method).
</p>
</li>
<li class="listitem">
Return safe references from <code class="computeroutput"><span class="identifier">__getitem__</span></code>
such that subsequent adds and deletes to and from the container will
not result in dangling references (will not crash Python).
</li>
<li class="listitem">
Support slice indexes.
</li>
<li class="listitem">
Accept Python container arguments (e.g. <code class="computeroutput"><span class="identifier">lists</span></code>,
<code class="computeroutput"><span class="identifier">tuples</span></code>) wherever appropriate.
</li>
<li class="listitem">
Allow for extensibility through re-definable policy classes.
</li>
<li class="listitem">
Provide predefined support for the most common STL and STL-like indexable
containers.
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.the_indexing_interface"></a><a class="link" href="indexing_support.html#topics.indexing_support.the_indexing_interface" title="The Indexing Interface">The
Indexing Interface</a>
</h3></div></div></div>
<p>
The <code class="computeroutput"><span class="identifier">indexing_suite</span></code> class
is the base class for the management of C++ containers intended to be integrated
to Python. The objective is make a C++ container look and feel and behave
exactly as we'd expect a Python container. The class automatically wraps
these special Python methods (taken from the Python reference: Emulating
container types):
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">__len__(self)</span></dt>
<dd><p>
Called to implement the built-in function <code class="computeroutput"><span class="identifier">len</span><span class="special">()</span></code>. Should return the length of the
object, an integer <code class="computeroutput"><span class="special">&gt;=</span> <span class="number">0</span></code>. Also, an object that doesn't define
a <code class="computeroutput"><span class="identifier">__nonzero__</span><span class="special">()</span></code>
method and whose <code class="computeroutput"><span class="identifier">__len__</span><span class="special">()</span></code> method returns zero is considered
to be false in a Boolean context.
</p></dd>
<dt><span class="term">__getitem__(self, key)</span></dt>
<dd><p>
Called to implement evaluation of <code class="computeroutput"><span class="identifier">self</span><span class="special">[</span><span class="identifier">key</span><span class="special">]</span></code>. For sequence types, the accepted
keys should be integers and slice objects. Note that the special
interpretation of negative indexes (if the class wishes to emulate
a sequence type) is up to the <code class="computeroutput"><span class="identifier">__getitem__</span><span class="special">()</span></code> method. If key is of an inappropriate
type, <code class="computeroutput"><span class="identifier">TypeError</span></code> may
be raised; if of a value outside the set of indexes for the sequence
(after any special interpretation of negative values), IndexError
should be raised. [Note: for loops expect that an IndexError will
be raised for illegal indexes to allow proper detection of the end
of the sequence.]
</p></dd>
<dt><span class="term">__setitem__(self, key, value)</span></dt>
<dd><p>
Called to implement assignment to self[key]. Same note as for __getitem__().
This should only be implemented for mappings if the objects support
changes to the values for keys, or if new keys can be added, or for
sequences if elements can be replaced. The same exceptions should
be raised for improper key values as for the __getitem__() method.
</p></dd>
<dt><span class="term">__delitem__(self, key)</span></dt>
<dd><p>
Called to implement deletion of self[key]. Same note as for __getitem__().
This should only be implemented for mappings if the objects support
removal of keys, or for sequences if elements can be removed from
the sequence. The same exceptions should be raised for improper key
values as for the __getitem__() method.
</p></dd>
<dt><span class="term">__iter__(self)</span></dt>
<dd>
<p>
This method is called when an iterator is required for a container.
This method should return a new iterator object that can iterate
over all the objects in the container. For mappings, it should iterate
over the keys of the container, and should also be made available
as the method iterkeys().
</p>
<p>
Iterator objects also need to implement this method; they are required
to return themselves. For more information on iterator objects, see
<a href="https://docs.python.org/3/library/stdtypes.html#iterator-types" target="_top">Iterator
Types</a> in the <a href="https://docs.python.org/3/library/index.html" target="_top">Python
Library Reference</a>.
</p>
</dd>
<dt><span class="term">__contains__(self, item)</span></dt>
<dd><p>
Called to implement membership test operators. Should return true
if item is in self, false otherwise. For mapping objects, this should
consider the keys of the mapping rather than the values or the key-item
pairs.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.index_suite_sub_classes"></a><a class="link" href="indexing_support.html#topics.indexing_support.index_suite_sub_classes" title="index_suite sub-classes">index_suite
sub-classes</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.index_suite_sub_classes.vector_index_suite">vector_index_suite</a></span></dt>
<dt><span class="section"><a href="indexing_support.html#topics.indexing_support.index_suite_sub_classes.map_index_suite">map_index_suite</a></span></dt>
</dl></div>
<p>
The <code class="computeroutput"><span class="identifier">indexing_suite</span></code> is not
meant to be used as is. A couple of policy functions must be supplied by
subclasses of <code class="computeroutput"><span class="identifier">indexing_suite</span></code>.
However, a set of indexing_suite subclasses for the standard indexable
STL containers will be provided, In most cases, we can simply use the available
predefined suites. In some cases, we can refine the predefined suites to
suit our needs.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.indexing_support.index_suite_sub_classes.vector_index_suite"></a><a class="link" href="indexing_support.html#topics.indexing_support.index_suite_sub_classes.vector_index_suite" title="vector_index_suite">vector_index_suite</a>
</h4></div></div></div>
<p>
The <code class="computeroutput"><span class="identifier">vector_indexing_suite</span></code>
class is a predefined <code class="computeroutput"><span class="identifier">indexing_suite</span></code>
derived class designed to wrap <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>
(and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>-like [i.e. a class with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code> interface]) classes. It provides
all the policies required by the <code class="computeroutput"><span class="identifier">indexing_suite</span></code>.
</p>
<p>
Example usage:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">{...};</span>
<span class="special">...</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"XVec"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">vector_indexing_suite</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
<span class="special">;</span>
</pre>
<p>
XVec is now a full-fledged Python container (see the example in full,
along with its python test).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.indexing_support.index_suite_sub_classes.map_index_suite"></a><a class="link" href="indexing_support.html#topics.indexing_support.index_suite_sub_classes.map_index_suite" title="map_index_suite">map_index_suite</a>
</h4></div></div></div>
<p>
The <code class="computeroutput"><span class="identifier">map_indexing_suite</span></code>
class is a predefined <code class="computeroutput"><span class="identifier">indexing_suite</span></code>
derived class designed to wrap <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span></code>
(and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span></code>-like [i.e. a class with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span></code> interface]) classes. It provides
all the policies required by the <code class="computeroutput"><span class="identifier">indexing_suite</span></code>.
</p>
<p>
Example usage:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">{...};</span>
<span class="special">...</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"XMap"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">map_indexing_suite</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
<span class="special">;</span>
</pre>
<p>
By default indexed elements are returned by proxy. This can be disabled
by supplying <code class="computeroutput"><span class="keyword">true</span></code> in the
<code class="computeroutput"><span class="identifier">NoProxy</span></code> template parameter.
XMap is now a full-fledged Python container (see the example in full,
along with its python test).
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.indexing_suite_class"></a><a class="link" href="indexing_support.html#topics.indexing_support.indexing_suite_class" title="indexing_suite class"><code class="computeroutput"><span class="identifier">indexing_suite</span></code> class</a>
</h3></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="indexing_support.html#topics.indexing_support.indexing_suite_class.derivedpolicies">DerivedPolicies</a></span></dt></dl></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Template Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
<th>
<p>
Default
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Container
</p>
</td>
<td>
<p>
A class type
</p>
</td>
<td>
<p>
The container type to be wrapped to Python.
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
DerivedPolicies
</p>
</td>
<td>
<p>
A subclass of indexing_suite
</p>
</td>
<td>
<p>
Derived classes provide the policy hooks. See DerivedPolicies
below.
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
NoProxy
</p>
</td>
<td>
<p>
A boolean
</p>
</td>
<td>
<p>
By default indexed elements have Python reference semantics and
are returned by proxy. This can be disabled by supplying true
in the NoProxy template parameter.
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
NoSlice
</p>
</td>
<td>
<p>
A boolean
</p>
</td>
<td>
<p>
Do not allow slicing.
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
Data
</p>
</td>
<td>
</td>
<td>
<p>
The container's data type.
</p>
</td>
<td>
<p>
Container::value_type
</p>
</td>
</tr>
<tr>
<td>
<p>
Index
</p>
</td>
<td>
</td>
<td>
<p>
The container's index type.
</p>
</td>
<td>
<p>
Container::size_type
</p>
</td>
</tr>
<tr>
<td>
<p>
Key
</p>
</td>
<td>
</td>
<td>
<p>
The container's key type.
</p>
</td>
<td>
<p>
Container::value_type
</p>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">DerivedPolicies</span><span class="special">,</span>
<span class="keyword">bool</span> <span class="identifier">NoProxy</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">,</span>
<span class="keyword">bool</span> <span class="identifier">NoSlice</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">Data</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">Index</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">size_type</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">Key</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">indexing_suite</span> <span class="special">:</span> <span class="identifier">unspecified</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">indexing_suite</span><span class="special">();</span> <span class="comment">// default constructor</span>
<span class="special">}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.indexing_support.indexing_suite_class.derivedpolicies"></a><a class="link" href="indexing_support.html#topics.indexing_support.indexing_suite_class.derivedpolicies" title="DerivedPolicies">DerivedPolicies</a>
</h4></div></div></div>
<p>
Derived classes provide the hooks needed by the indexing_suite:
</p>
<pre class="programlisting"><span class="identifier">data_type</span><span class="special">&amp;</span>
<span class="identifier">get_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">object</span>
<span class="identifier">get_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">data_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_slice</span><span class="special">(</span>
<span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">data_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span>
<span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span>
<span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">delete_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">delete_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">size_t</span>
<span class="identifier">size</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="keyword">bool</span>
<span class="identifier">contains</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">val</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">index_type</span>
<span class="identifier">convert_index</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">index_type</span>
<span class="identifier">adjust_index</span><span class="special">(</span><span class="identifier">index_type</span> <span class="identifier">current</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">len</span><span class="special">);</span>
</pre>
<p>
Most of these policies are self explanatory. However, convert_index and
adjust_index deserve some explanation.
</p>
<p>
convert_index converts a Python index into a C++ index that the container
can handle. For instance, negative indexes in Python, by convention,
start counting from the right(e.g. C<span class="strikethrough">1</span>
indexes the rightmost element in C). convert_index should handle the
necessary conversion for the C++ container (e.g. convert -1 to C.size()-1).
convert_index should also be able to convert the type of the index (A
dynamic Python type) to the actual type that the C++ container expects.
</p>
<p>
When a container expands or contracts, held indexes to its elements must
be adjusted to follow the movement of data. For instance, if we erase
3 elements, starting from index 0 from a 5 element vector, what used
to be at index 4 will now be at index 1:
</p>
<pre class="programlisting"><span class="special">[</span><span class="identifier">a</span><span class="special">][</span><span class="identifier">b</span><span class="special">][</span><span class="identifier">c</span><span class="special">][</span><span class="identifier">d</span><span class="special">][</span><span class="identifier">e</span><span class="special">]</span> <span class="special">---&gt;</span> <span class="special">[</span><span class="identifier">d</span><span class="special">][</span><span class="identifier">e</span><span class="special">]</span>
<span class="special">^</span> <span class="special">^</span>
<span class="number">4</span> <span class="number">1</span>
</pre>
<p>
adjust_index takes care of the adjustment. Given a current index, the
function should return the adjusted index when data in the container
at index from..to is replaced by len elements.
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.class_vector_indexing_suite"></a><a class="link" href="indexing_support.html#topics.indexing_support.class_vector_indexing_suite" title="class vector_indexing_suite">class
<code class="computeroutput"><span class="identifier">vector_indexing_suite</span></code></a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Template Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
<th>
<p>
Default
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Container
</p>
</td>
<td>
<p>
A class type
</p>
</td>
<td>
<p>
The container type to be wrapped to Python.
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
NoProxy
</p>
</td>
<td>
<p>
A boolean
</p>
</td>
<td>
<p>
By default indexed elements have Python reference semantics and
are returned by proxy. This can be disabled by supplying true
in the NoProxy template parameter.
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
DerivedPolicies
</p>
</td>
<td>
<p>
A subclass of indexing_suite
</p>
</td>
<td>
<p>
The vector_indexing_suite may still be derived to further tweak
any of the predefined policies. Static polymorphism through CRTP
(James Coplien. "Curiously Recurring Template Pattern".
C++ Report, Feb. 1995) enables the base indexing_suite class
to call policy function of the most derived class
</p>
</td>
<td>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span>
<span class="keyword">bool</span> <span class="identifier">NoProxy</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">DerivedPolicies</span> <span class="special">=</span> <span class="identifier">unspecified_default</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">vector_indexing_suite</span> <span class="special">:</span> <span class="identifier">unspecified_base</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">data_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">key_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">size_type</span> <span class="identifier">index_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span>
<span class="identifier">data_type</span><span class="special">&amp;</span>
<span class="identifier">get_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">object</span>
<span class="identifier">get_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">data_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">data_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">delete_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">delete_slice</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">size_t</span>
<span class="identifier">size</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">bool</span>
<span class="identifier">contains</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">key_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">key</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">index_type</span>
<span class="identifier">convert_index</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">index_type</span>
<span class="identifier">adjust_index</span><span class="special">(</span><span class="identifier">index_type</span> <span class="identifier">current</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">from</span><span class="special">,</span>
<span class="identifier">index_type</span> <span class="identifier">to</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">len</span><span class="special">);</span>
<span class="special">};</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.indexing_support.class_map_indexing_suite"></a><a class="link" href="indexing_support.html#topics.indexing_support.class_map_indexing_suite" title="class map_indexing_suite">class
<code class="computeroutput"><span class="identifier">map_indexing_suite</span></code></a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Template Parameter
</p>
</th>
<th>
<p>
Requirements
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
<th>
<p>
Default
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Container
</p>
</td>
<td>
<p>
A class type
</p>
</td>
<td>
<p>
The container type to be wrapped to Python.
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
NoProxy
</p>
</td>
<td>
<p>
A boolean
</p>
</td>
<td>
<p>
By default indexed elements have Python reference semantics and
are returned by proxy. This can be disabled by supplying true
in the NoProxy template parameter.
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
DerivedPolicies
</p>
</td>
<td>
<p>
A subclass of indexing_suite
</p>
</td>
<td>
<p>
The vector_indexing_suite may still be derived to further tweak
any of the predefined policies. Static polymorphism through CRTP
(James Coplien. "Curiously Recurring Template Pattern".
C++ Report, Feb. 1995) enables the base indexing_suite class
to call policy function of the most derived class
</p>
</td>
<td>
</td>
</tr>
</tbody>
</table></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span>
<span class="keyword">bool</span> <span class="identifier">NoProxy</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">,</span>
<span class="keyword">class</span> <span class="identifier">DerivedPolicies</span> <span class="special">=</span> <span class="identifier">unspecified_default</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">map_indexing_suite</span> <span class="special">:</span> <span class="identifier">unspecified_base</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">value_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">::</span><span class="identifier">second_type</span> <span class="identifier">data_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">key_type</span> <span class="identifier">key_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">key_type</span> <span class="identifier">index_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Container</span><span class="special">::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">data_type</span><span class="special">&amp;</span>
<span class="identifier">get_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">set_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">data_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">delete_item</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">i</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">size_t</span>
<span class="identifier">size</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">bool</span>
<span class="identifier">contains</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">key_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">key</span><span class="special">);</span>
<span class="keyword">static</span> <span class="keyword">bool</span>
<span class="identifier">compare_index</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">index_type</span> <span class="identifier">b</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">index_type</span>
<span class="identifier">convert_index</span><span class="special">(</span><span class="identifier">Container</span><span class="special">&amp;</span> <span class="identifier">container</span><span class="special">,</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">i</span><span class="special">);</span>
<span class="special">};</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="pickle_support.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../topics.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../glossary.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,356 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Pickle support</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../topics.html" title="Chapter&#160;8.&#160;Topics">
<link rel="prev" href="../topics.html" title="Chapter&#160;8.&#160;Topics">
<link rel="next" href="indexing_support.html" title="Indexing support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../topics.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../topics.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="indexing_support.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="topics.pickle_support"></a><a class="link" href="pickle_support.html" title="Pickle support">Pickle support</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.the_pickle_interface">The Pickle
Interface</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.example">Example</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.pitfall_and_safety_guard">Pitfall
and Safety Guard</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.practical_advice">Practical Advice</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.light_weight_alternative_pickle_">Light-weight
alternative: pickle support implemented in Python</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.introduction"></a><a class="link" href="pickle_support.html#topics.pickle_support.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Pickle is a Python module for object serialization, also known as persistence,
marshalling, or flattening.
</p>
<p>
It is often necessary to save and restore the contents of an object to
a file. One approach to this problem is to write a pair of functions that
read and write data from a file in a special format. A powerful alternative
approach is to use Python's pickle module. Exploiting Python's ability
for introspection, the pickle module recursively converts nearly arbitrary
Python objects into a stream of bytes that can be written to a file.
</p>
<p>
The Boost Python Library supports the pickle module through the interface
as described in detail in the <a href="https://docs.python.org/2/library/pickle.html" target="_top">Python
Library Reference for pickle</a>. This interface involves the special
methods <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>,
<code class="computeroutput"><span class="identifier">__getstate__</span></code> and <code class="computeroutput"><span class="identifier">__setstate__</span></code> as described in the following.
Note that <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code> is also fully compatible with
Python's cPickle module.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.the_pickle_interface"></a><a class="link" href="pickle_support.html#topics.pickle_support.the_pickle_interface" title="The Pickle Interface">The Pickle
Interface</a>
</h3></div></div></div>
<p>
At the user level, the Boost.Python pickle interface involves three special
methods:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">__getinitargs__</span></dt>
<dd>
<p>
When an instance of a Boost.Python extension class is pickled, the
pickler tests if the instance has a <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>
method. This method must return a Python <code class="computeroutput"><span class="identifier">tuple</span></code>
(it is most convenient to use a <a class="link" href="../object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple" title="Class tuple"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span></code></a>). When the instance
is restored by the unpickler, the contents of this tuple are used
as the arguments for the class constructor.
</p>
<p>
If <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>
is not defined, <code class="computeroutput"><span class="identifier">pickle</span><span class="special">.</span><span class="identifier">load</span></code>
will call the constructor (<code class="computeroutput"><span class="identifier">__init__</span></code>)
without arguments; i.e., the object must be default-constructible.
</p>
</dd>
<dt><span class="term">__getstate__</span></dt>
<dd><p>
When an instance of a <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code>
extension class is pickled, the pickler tests if the instance has
a <code class="computeroutput"><span class="identifier">__getstate__</span></code> method.
This method should return a Python object representing the state
of the instance.
</p></dd>
<dt><span class="term">__setstate__</span></dt>
<dd><p>
When an instance of a <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code>
extension class is restored by the unpickler (<code class="computeroutput"><span class="identifier">pickle</span><span class="special">.</span><span class="identifier">load</span></code>),
it is first constructed using the result of <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>
as arguments (see above). Subsequently the unpickler tests if the
new instance has a <code class="computeroutput"><span class="identifier">__setstate__</span></code>
method. If so, this method is called with the result of <code class="computeroutput"><span class="identifier">__getstate__</span></code> (a Python object)
as the argument.
</p></dd>
</dl>
</div>
<p>
The three special methods described above may be <code class="computeroutput"><span class="special">.</span><span class="identifier">def</span><span class="special">()</span></code>'ed
individually by the user. However, <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code>
provides an easy to use high-level interface via the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">pickle_suite</span></code>
class that also enforces consistency: <code class="computeroutput"><span class="identifier">__getstate__</span></code>
and <code class="computeroutput"><span class="identifier">__setstate__</span></code> must be
defined as pairs. Use of this interface is demonstrated by the following
examples.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.example"></a><a class="link" href="pickle_support.html#topics.pickle_support.example" title="Example">Example</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.example.pickle1_cpp">pickle1.cpp</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.example.pickle2_cpp">pickle2.cpp</a></span></dt>
<dt><span class="section"><a href="pickle_support.html#topics.pickle_support.example.pickle3_cpp">pickle3.cpp</a></span></dt>
</dl></div>
<p>
There are three files in <code class="computeroutput"><span class="identifier">python</span><span class="special">/</span><span class="identifier">test</span></code>
that show how to provide pickle support.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.pickle_support.example.pickle1_cpp"></a><a class="link" href="pickle_support.html#topics.pickle_support.example.pickle1_cpp" title="pickle1.cpp">pickle1.cpp</a>
</h4></div></div></div>
<p>
The C++ class in this example can be fully restored by passing the appropriate
argument to the constructor. Therefore it is sufficient to define the
pickle interface method <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>.
This is done in the following way: Definition of the C++ pickle function:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">world_pickle_suite</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">pickle_suite</span>
<span class="special">{</span>
<span class="keyword">static</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span>
<span class="identifier">getinitargs</span><span class="special">(</span><span class="identifier">world</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">w</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">w</span><span class="special">.</span><span class="identifier">get_country</span><span class="special">());</span>
<span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Establishing the Python binding:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">world</span><span class="special">&gt;(</span><span class="string">"world"</span><span class="special">,</span> <span class="identifier">args</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;&gt;())</span>
<span class="comment">// ...</span>
<span class="special">.</span><span class="identifier">def_pickle</span><span class="special">(</span><span class="identifier">world_pickle_suite</span><span class="special">())</span>
<span class="comment">// ...</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.pickle_support.example.pickle2_cpp"></a><a class="link" href="pickle_support.html#topics.pickle_support.example.pickle2_cpp" title="pickle2.cpp">pickle2.cpp</a>
</h4></div></div></div>
<p>
The C++ class in this example contains member data that cannot be restored
by any of the constructors. Therefore it is necessary to provide the
<code class="computeroutput"><span class="identifier">__getstate__</span></code>/<code class="computeroutput"><span class="identifier">__setstate__</span></code> pair of pickle interface
methods:
</p>
<p>
Definition of the C++ pickle functions:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">world_pickle_suite</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">pickle_suite</span>
<span class="special">{</span>
<span class="keyword">static</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span>
<span class="identifier">getinitargs</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">world</span><span class="special">&amp;</span> <span class="identifier">w</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="special">}</span>
<span class="keyword">static</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span>
<span class="identifier">getstate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">world</span><span class="special">&amp;</span> <span class="identifier">w</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="special">}</span>
<span class="keyword">static</span>
<span class="keyword">void</span>
<span class="identifier">setstate</span><span class="special">(</span><span class="identifier">world</span><span class="special">&amp;</span> <span class="identifier">w</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">tuple</span> <span class="identifier">state</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Establishing the Python bindings for the entire suite:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">world</span><span class="special">&gt;(</span><span class="string">"world"</span><span class="special">,</span> <span class="identifier">args</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;&gt;())</span>
<span class="comment">// ...</span>
<span class="special">.</span><span class="identifier">def_pickle</span><span class="special">(</span><span class="identifier">world_pickle_suite</span><span class="special">())</span>
<span class="comment">// ...</span>
</pre>
<p>
For simplicity, the <code class="computeroutput"><span class="identifier">__dict__</span></code>
is not included in the result of <code class="computeroutput"><span class="identifier">__getstate__</span></code>.
This is not generally recommended, but a valid approach if it is anticipated
that the object's <code class="computeroutput"><span class="identifier">__dict__</span></code>
will always be empty. Note that the safety guard described below will
catch the cases where this assumption is violated.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="topics.pickle_support.example.pickle3_cpp"></a><a class="link" href="pickle_support.html#topics.pickle_support.example.pickle3_cpp" title="pickle3.cpp">pickle3.cpp</a>
</h4></div></div></div>
<p>
This example is similar to pickle2.cpp. However, the object's <code class="computeroutput"><span class="identifier">__dict__</span></code> is included in the result
of <code class="computeroutput"><span class="identifier">__getstate__</span></code>. This
requires a little more code but is unavoidable if the object's <code class="computeroutput"><span class="identifier">__dict__</span></code> is not always empty.
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.pitfall_and_safety_guard"></a><a class="link" href="pickle_support.html#topics.pickle_support.pitfall_and_safety_guard" title="Pitfall and Safety Guard">Pitfall
and Safety Guard</a>
</h3></div></div></div>
<p>
The pickle protocol described above has an important pitfall that the end
user of a Boost.Python extension module might not be aware of:
</p>
<p>
<span class="bold"><strong><code class="computeroutput"><span class="identifier">__getstate__</span></code>
is defined and the instance's <code class="computeroutput"><span class="identifier">__dict__</span></code>
is not empty.</strong></span>
</p>
<p>
The author of a <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code> extension class might provide
a <code class="computeroutput"><span class="identifier">__getstate__</span></code> method without
considering the possibilities that: * his class is used in Python as a
base class. Most likely the <code class="computeroutput"><span class="identifier">__dict__</span></code>
of instances of the derived class needs to be pickled in order to restore
the instances correctly. * the user adds items to the instance's <code class="computeroutput"><span class="identifier">__dict__</span></code> directly. Again, the <code class="computeroutput"><span class="identifier">__dict__</span></code> of the instance then needs to
be pickled.
</p>
<p>
To alert the user to this highly unobvious problem, a safety guard is provided.
If <code class="computeroutput"><span class="identifier">__getstate__</span></code> is defined
and the instance's <code class="computeroutput"><span class="identifier">__dict__</span></code>
is not empty, <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code> tests if the class has an attribute
<code class="computeroutput"><span class="identifier">__getstate_manages_dict__</span></code>.
An exception is raised if this attribute is not defined:
</p>
<pre class="programlisting"><span class="identifier">RuntimeError</span><span class="special">:</span> <span class="identifier">Incomplete</span> <span class="identifier">pickle</span> <span class="identifier">support</span> <span class="special">(</span><span class="identifier">__getstate_manages_dict__</span> <span class="keyword">not</span> <span class="identifier">set</span><span class="special">)</span>
</pre>
<p>
To resolve this problem, it should first be established that the <code class="computeroutput"><span class="identifier">__getstate__</span></code> and <code class="computeroutput"><span class="identifier">__setstate__</span></code>
methods manage the instances's <code class="computeroutput"><span class="identifier">__dict__</span></code>
correctly. Note that this can be done either at the C++ or the Python level.
Finally, the safety guard should intentionally be overridden. E.g. in C++
(from pickle3.cpp):
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">world_pickle_suite</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">pickle_suite</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">getstate_manages_dict</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Alternatively in Python:
</p>
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">your_bpl_module</span>
<span class="keyword">class</span> <span class="identifier">your_class</span><span class="special">(</span><span class="identifier">your_bpl_module</span><span class="special">.</span><span class="identifier">your_class</span><span class="special">):</span>
<span class="identifier">__getstate_manages_dict__</span> <span class="special">=</span> <span class="number">1</span>
<span class="identifier">def</span> <span class="identifier">__getstate__</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="preprocessor"># your</span> <span class="identifier">code</span> <span class="identifier">here</span>
<span class="identifier">def</span> <span class="identifier">__setstate__</span><span class="special">(</span><span class="identifier">self</span><span class="special">,</span> <span class="identifier">state</span><span class="special">):</span>
<span class="preprocessor"># your</span> <span class="identifier">code</span> <span class="identifier">here</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.practical_advice"></a><a class="link" href="pickle_support.html#topics.pickle_support.practical_advice" title="Practical Advice">Practical Advice</a>
</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
In <code class="computeroutput"><span class="identifier">Boost</span><span class="special">.</span><span class="identifier">Python</span></code> extension modules with many
extension classes, providing complete pickle support for all classes
would be a significant overhead. In general complete pickle support
should only be implemented for extension classes that will eventually
be pickled.
</li>
<li class="listitem">
Avoid using <code class="computeroutput"><span class="identifier">__getstate__</span></code>
if the instance can also be reconstructed by way of <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>.
This automatically avoids the pitfall described above.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">__getstate__</span></code> is
required, include the instance's <code class="computeroutput"><span class="identifier">__dict__</span></code>
in the Python object that is returned.
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="topics.pickle_support.light_weight_alternative_pickle_"></a><a class="link" href="pickle_support.html#topics.pickle_support.light_weight_alternative_pickle_" title="Light-weight alternative: pickle support implemented in Python">Light-weight
alternative: pickle support implemented in Python</a>
</h3></div></div></div>
<p>
The pickle4.cpp example demonstrates an alternative technique for implementing
pickle support. First we direct Boost.Python via the class_::enable_pickling()
member function to define only the basic attributes required for pickling:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">world</span><span class="special">&gt;(</span><span class="string">"world"</span><span class="special">,</span> <span class="identifier">args</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;&gt;())</span>
<span class="comment">// ...</span>
<span class="special">.</span><span class="identifier">enable_pickling</span><span class="special">()</span>
<span class="comment">// ...</span>
</pre>
<p>
This enables the standard Python pickle interface as described in the Python
documentation. By "injecting" a <code class="computeroutput"><span class="identifier">__getinitargs__</span></code>
method into the definition of the wrapped class we make all instances pickleable:
</p>
<pre class="programlisting"><span class="preprocessor"># import</span> <span class="identifier">the</span> <span class="identifier">wrapped</span> <span class="identifier">world</span> <span class="keyword">class</span>
<span class="identifier">from</span> <span class="identifier">pickle4_ext</span> <span class="identifier">import</span> <span class="identifier">world</span>
<span class="preprocessor"># definition</span> <span class="identifier">of</span> <span class="identifier">__getinitargs__</span>
<span class="identifier">def</span> <span class="identifier">world_getinitargs</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="keyword">return</span> <span class="special">(</span><span class="identifier">self</span><span class="special">.</span><span class="identifier">get_country</span><span class="special">(),)</span>
<span class="preprocessor"># now</span> <span class="identifier">inject</span> <span class="identifier">__getinitargs__</span> <span class="special">(</span><span class="identifier">Python</span> <span class="identifier">is</span> <span class="identifier">a</span> <span class="identifier">dynamic</span> <span class="identifier">language</span><span class="special">!)</span>
<span class="identifier">world</span><span class="special">.</span><span class="identifier">__getinitargs__</span> <span class="special">=</span> <span class="identifier">world_getinitargs</span>
</pre>
<p>
See also the tutorial section on injecting additional methods from Python.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../topics.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../topics.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="indexing_support.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,240 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;7.&#160;Utility and Infrastructure</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="embedding/boost_python_import_hpp.html" title="boost/python/import.hpp">
<link rel="next" href="utility_and_infrastructure/boost_python_instance_holder_hpp.html" title="boost/python/instance_holder.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="embedding/boost_python_import_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="utility_and_infrastructure/boost_python_instance_holder_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="utility_and_infrastructure"></a>Chapter&#160;7.&#160;Utility and Infrastructure</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_">boost/python/has_back_reference.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc">Class
template <code class="computeroutput"><span class="identifier">has_back_reference</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html">boost/python/instance_holder.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder">Class
template <code class="computeroutput"><span class="identifier">instance_holder</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html">boost/python/pointee.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee">Class
template <code class="computeroutput"><span class="identifier">pointee</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html">boost/python/handle.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle">Class
template <code class="computeroutput"><span class="identifier">handle</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_borrowed">Function
<code class="computeroutput"><span class="identifier">borrowed</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_allow_null">Function
<code class="computeroutput"><span class="identifier">allow_null</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html">boost/python/type_id.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example">Example</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html">boost/python/ssize_t.hpp</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.typedefs">Typedefs</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure/boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.constants">Constants</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_has_back_reference_"></a><a class="link" href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_" title="boost/python/has_back_reference.hpp">boost/python/has_back_reference.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc">Class
template <code class="computeroutput"><span class="identifier">has_back_reference</span></code></a></span></dt>
<dt><span class="section"><a href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_has_back_reference_.introduction"></a><a class="link" href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/has_back_reference.hpp&gt; defines the predicate metafunction
<code class="computeroutput"><span class="identifier">has_back_reference</span><span class="special">&lt;&gt;</span></code>,
which can be specialized by the user to indicate that a wrapped class instance
holds a <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
corresponding to a Python object.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc"></a><a class="link" href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.class_template_has_back_referenc" title="Class template has_back_reference">Class
template <code class="computeroutput"><span class="identifier">has_back_reference</span></code></a>
</h3></div></div></div>
<p>
A unary metafunction whose value is true iff its argument is a <code class="computeroutput"><span class="identifier">pointer_wrapper</span><span class="special">&lt;&gt;</span></code>.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">WrappedClass</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">has_back_reference</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<p>
A metafunction that is inspected by Boost.Python to determine how wrapped
classes can be constructed.
</p>
<p>
<code class="computeroutput"><span class="identifier">type</span><span class="special">::</span><span class="identifier">value</span></code> is an integral constant convertible
to bool of unspecified type. Specializations may substitute a true-valued
integral constant wrapper for type iff for each invocation of <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">WrappedClass</span><span class="special">&gt;::</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span> <span class="identifier">type</span><span class="special">-</span><span class="identifier">sequence</span><span class="special">...&gt;())</span></code>
and the implicitly wrapped copy constructor (unless it is noncopyable),
there exists a corresponding constructor <code class="computeroutput"><span class="identifier">WrappedClass</span><span class="special">::</span><span class="identifier">WrappedClass</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*,</span> <span class="identifier">type</span><span class="special">-</span><span class="identifier">sequence</span><span class="special">...)</span></code>. If such a specialization exists, the
WrappedClass constructors will be called with a "back reference"
pointer to the corresponding Python object whenever they are invoked from
Python. The easiest way to provide this nested type is to derive the specialization
from <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_has_back_reference_.examples"></a><a class="link" href="utility_and_infrastructure.html#utility_and_infrastructure.boost_python_has_back_reference_.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
In C++:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">has_back_reference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">handle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">shared_ptr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">;</span>
<span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_self</span><span class="special">(</span><span class="identifier">self</span><span class="special">),</span> <span class="identifier">m_x</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_self</span><span class="special">(</span><span class="identifier">self</span><span class="special">),</span> <span class="identifier">m_x</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">X</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">,</span> <span class="identifier">X</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_self</span><span class="special">(</span><span class="identifier">self</span><span class="special">),</span> <span class="identifier">m_x</span><span class="special">(</span><span class="identifier">other</span><span class="special">.</span><span class="identifier">m_x</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;</span> <span class="identifier">self</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">m_self</span><span class="special">));</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">get</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">m_x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">m_x</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">m_self</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">m_x</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">// specialize has_back_reference for X</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;&gt;</span>
<span class="keyword">struct</span> <span class="identifier">has_back_reference</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span>
<span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span>
<span class="special">{};</span>
<span class="special">}}</span>
<span class="keyword">struct</span> <span class="identifier">Y</span>
<span class="special">{</span>
<span class="identifier">Y</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">m_x</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">Y</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">m_x</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{}</span>
<span class="keyword">int</span> <span class="identifier">get</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">m_x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">m_x</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">m_x</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span>
<span class="identifier">Y_self</span><span class="special">(</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="identifier">self</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">self</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">back_references</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"self"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">self</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">set</span><span class="special">)</span>
<span class="special">;</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">,</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"Y"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"get"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Y</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Y</span><span class="special">::</span><span class="identifier">set</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"self"</span><span class="special">,</span> <span class="identifier">Y_self</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
The following Python session illustrates that x.self() returns the same
Python object on which it is invoked, while y.self() must create a new
Python object which refers to the same Y instance.
</p>
<p>
In Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">back_references</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">X</span><span class="special">(</span><span class="number">1</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x2</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">self</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x2</span> <span class="identifier">is</span> <span class="identifier">x</span>
<span class="number">1</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">(),</span> <span class="identifier">x2</span><span class="special">.</span><span class="identifier">get</span><span class="special">())</span>
<span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">1</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="number">10</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">(),</span> <span class="identifier">x2</span><span class="special">.</span><span class="identifier">get</span><span class="special">())</span>
<span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">10</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span>
<span class="special">&gt;&gt;&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">Y</span><span class="special">(</span><span class="number">2</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y2</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">self</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y2</span> <span class="identifier">is</span> <span class="identifier">y</span>
<span class="number">0</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">(</span><span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">(),</span> <span class="identifier">y2</span><span class="special">.</span><span class="identifier">get</span><span class="special">())</span>
<span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="number">20</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">(</span><span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">(),</span> <span class="identifier">y2</span><span class="special">.</span><span class="identifier">get</span><span class="special">())</span>
<span class="special">(</span><span class="number">20</span><span class="special">,</span> <span class="number">20</span><span class="special">)</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="embedding/boost_python_import_hpp.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="utility_and_infrastructure/boost_python_instance_holder_hpp.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,363 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/handle.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="boost_python_pointee_hpp.html" title="boost/python/pointee.hpp">
<link rel="next" href="boost_python_type_id_hpp.html" title="boost/python/type_id.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_pointee_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_type_id_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_handle_hpp"></a><a class="link" href="boost_python_handle_hpp.html" title="boost/python/handle.hpp">boost/python/handle.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle">Class
template <code class="computeroutput"><span class="identifier">handle</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_borrowed">Function
<code class="computeroutput"><span class="identifier">borrowed</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_allow_null">Function
<code class="computeroutput"><span class="identifier">allow_null</span></code></a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.introduction"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/handle.hpp&gt; provides class template <code class="computeroutput"><span class="identifier">handle</span></code>,
a smart pointer for managing reference-counted Python objects.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.class_template_handle"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle" title="Class template handle">Class
template <code class="computeroutput"><span class="identifier">handle</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_constructo">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> constructors
and destructor</a></span></dt>
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_modifiers">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> modifiers</a></span></dt>
<dt><span class="section"><a href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_observers">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> observers</a></span></dt>
</dl></div>
<p>
<code class="computeroutput"><span class="identifier">handle</span></code> is a smart pointer
to a Python object type; it holds a pointer of type <code class="computeroutput"><span class="identifier">T</span><span class="special">*</span></code>, where <code class="computeroutput"><span class="identifier">T</span></code>
is its template parameter. T must be either a type derived from <code class="computeroutput"><span class="identifier">PyObject</span></code> or a <a class="link" href="../glossary.html#pod">POD</a>
type whose initial <code class="computeroutput"><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">)</span></code> bytes are layout-compatible with <code class="computeroutput"><span class="identifier">PyObject</span></code>. Use <code class="computeroutput"><span class="identifier">handle</span><span class="special">&lt;&gt;</span></code> at the boundary between the Python/'C'
API and high-level code; prefer object for a generalized interface to Python
objects.
</p>
<p>
In this document, the term "upcast" refers to an operation which
converts a pointer <code class="computeroutput"><span class="identifier">Y</span><span class="special">*</span></code>
to a base class <code class="computeroutput"><span class="identifier">pointer</span> <span class="identifier">T</span><span class="special">*</span></code> via
<code class="computeroutput"><span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;</span></code>
if <code class="computeroutput"><span class="identifier">Y</span></code> is derived from <code class="computeroutput"><span class="identifier">T</span></code>, or via C-style cast (<code class="computeroutput"><span class="identifier">T</span><span class="special">*</span></code>) if
it is not. However, in the latter case the "upcast" is ill-formed
if the initial <code class="computeroutput"><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">)</span></code>
bytes of <code class="computeroutput"><span class="identifier">Y</span></code> are not layout-compatible
with <code class="computeroutput"><span class="identifier">PyObject</span></code>.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">handle</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">unspecified</span><span class="special">-</span><span class="identifier">member</span><span class="special">-</span><span class="identifier">function</span><span class="special">-</span><span class="identifier">pointer</span> <span class="identifier">bool_type</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span> <span class="comment">// types</span>
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">element_type</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span> <span class="comment">// member functions</span>
<span class="special">~</span><span class="identifier">handle</span><span class="special">();</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">Y</span><span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">();</span>
<span class="identifier">handle</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">handle</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="identifier">handle</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span> <span class="comment">// never throws</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="identifier">handle</span><span class="special">(</span><span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">(</span><span class="identifier">handle</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
<span class="identifier">T</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">-&gt;</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">T</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">*</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">reset</span><span class="special">();</span>
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">release</span><span class="special">();</span>
<span class="keyword">operator</span> <span class="identifier">bool_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// never throws</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">m_p</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">null_ok</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">detail</span> <span class="special">{</span> <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">borrowed</span><span class="special">;</span> <span class="special">}</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_constructo"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_constructo" title="Class template handle constructors and destructor">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> constructors
and destructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">handle</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">Py_XDECREF</span><span class="special">(</span><span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">m_p</span><span class="special">))</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><pre class="programlisting"><span class="identifier">Py_XINCREF</span><span class="special">(</span><span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">));</span>
<span class="identifier">m_p</span> <span class="special">=</span> <span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">);</span>
</pre></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><pre class="programlisting"><span class="identifier">Py_XINCREF</span><span class="special">(</span><span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">));</span>
<span class="identifier">m_p</span> <span class="special">=</span> <span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">);</span>
</pre></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><pre class="programlisting"><span class="identifier">Py_XINCREF</span><span class="special">(</span><span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">));</span>
<span class="identifier">m_p</span> <span class="special">=</span> <span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;(</span><span class="identifier">expect_non_null</span><span class="special">(</span><span class="identifier">p</span><span class="special">));</span>
</pre></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;*</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">m_p</span> <span class="special">=</span>
<span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;(</span><span class="identifier">p</span><span class="special">);</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">handle</span><span class="special">(</span><span class="identifier">Y</span><span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">m_p</span> <span class="special">=</span>
<span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;(</span><span class="identifier">expect_non_null</span><span class="special">(</span><span class="identifier">p</span><span class="special">));</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">handle</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">m_p</span> <span class="special">=</span>
<span class="number">0</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="identifier">handle</span><span class="special">(</span><span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">(</span><span class="identifier">handle</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
m_p = r.m_p; Py_XINCREF(upcast&lt;PyObject*&gt;(m_p));
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_modifiers"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_modifiers" title="Class template handle modifiers">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> modifiers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">handle</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">handle</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Y</span><span class="special">&gt;</span>
<span class="identifier">handle</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">r</span><span class="special">);</span> <span class="comment">// never throws</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">Py_XINCREF</span><span class="special">(</span><span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">m_p</span><span class="special">));</span>
<span class="identifier">Py_XDECREF</span><span class="special">(</span>
<span class="identifier">upcast</span><span class="special">&lt;</span><span class="identifier">PyObject</span><span class="special">*&gt;(</span><span class="identifier">m_p</span><span class="special">));</span>
<span class="identifier">m_p</span> <span class="special">=</span>
<span class="identifier">r</span><span class="special">.</span><span class="identifier">m_p</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">T</span><span class="special">*</span> <span class="identifier">release</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">T</span><span class="special">*</span>
<span class="identifier">x</span> <span class="special">=</span>
<span class="identifier">m_p</span><span class="special">;</span>
<span class="identifier">m_p</span> <span class="special">=</span>
<span class="number">0</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">reset</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span>
<span class="special">=</span> <span class="identifier">handle</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;();</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_observers"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.class_template_handle.class_template_handle_observers" title="Class template handle observers">Class
template <code class="computeroutput"><span class="identifier">handle</span></code> observers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">T</span><span class="special">*</span> <span class="keyword">operator</span><span class="special">-&gt;</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">m_p</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="identifier">T</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">*</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">*</span><span class="identifier">m_p</span><span class="special">;</span></code>
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">bool_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// never throws</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="number">0</span></code> if <code class="computeroutput"><span class="identifier">m_p</span> <span class="special">==</span>
<span class="number">0</span></code>, a pointer convertible
to true otherwise.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.function_borrowed"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_borrowed" title="Function borrowed">Function
<code class="computeroutput"><span class="identifier">borrowed</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;*</span> <span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="special">(</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;*)</span><span class="identifier">p</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_handle_hpp.function_allow_null"></a><a class="link" href="boost_python_handle_hpp.html#utility_and_infrastructure.boost_python_handle_hpp.function_allow_null" title="Function allow_null">Function
<code class="computeroutput"><span class="identifier">allow_null</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;*</span> <span class="identifier">allow_null</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="special">(</span><span class="identifier">null_ok</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;*)</span><span class="identifier">p</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_pointee_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_type_id_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,212 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/instance_holder.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="next" href="boost_python_pointee_hpp.html" title="boost/python/pointee.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../utility_and_infrastructure.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_pointee_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp"></a><a class="link" href="boost_python_instance_holder_hpp.html" title="boost/python/instance_holder.hpp">boost/python/instance_holder.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder">Class
template <code class="computeroutput"><span class="identifier">instance_holder</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.introduction"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/instance_holder.hpp&gt; provides class <code class="computeroutput"><span class="identifier">instance_holder</span></code>,
the base class for types which hold C++ instances of wrapped classes.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder" title="Class template instance_holder">Class
template <code class="computeroutput"><span class="identifier">instance_holder</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_destructor">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> destructor</a></span></dt>
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_modifiers">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> modifiers</a></span></dt>
<dt><span class="section"><a href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_observers">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> observers</a></span></dt>
</dl></div>
<p>
<code class="computeroutput"><span class="identifier">instance_holder</span></code> is an abstract
base class whose concrete derived classes hold C++ class instances within
their Python object wrappers. To allow multiple inheritance in Python from
C++ class wrappers, each such Python object contains a chain of instance_holders.
When an <code class="computeroutput"><span class="identifier">__init__</span></code> function
for a wrapped C++ class is invoked, a new <code class="computeroutput"><span class="identifier">instance_holder</span></code>
instance is created and installed in the Python object using its <code class="computeroutput"><span class="identifier">install</span><span class="special">()</span></code>
function. Each concrete class derived from <code class="computeroutput"><span class="identifier">instance_holder</span></code>
must provide a <code class="computeroutput"><span class="identifier">holds</span><span class="special">()</span></code>
implementation which allows Boost.Python to query it for the type(s) it
is holding. In order to support the held type's wrapped constructor(s),
the class must also provide constructors that can accept an initial <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
argument referring to the owning Python object, and which forward the rest
of their arguments to the constructor of the held type. The initial argument
is needed to enable virtual function overriding in Python, and may be ignored,
depending on the specific <code class="computeroutput"><span class="identifier">instance_holder</span></code>
subclass.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">instance_holder</span> <span class="special">:</span> <span class="identifier">noncopyable</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="comment">// destructor</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">instance_holder</span><span class="special">();</span>
<span class="comment">// instance_holder modifiers</span>
<span class="keyword">void</span> <span class="identifier">install</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">inst</span><span class="special">)</span> <span class="keyword">throw</span><span class="special">();</span>
<span class="comment">// instance_holder observers</span>
<span class="keyword">virtual</span> <span class="keyword">void</span><span class="special">*</span> <span class="identifier">holds</span><span class="special">(</span><span class="identifier">type_info</span><span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_destructor"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_destructor" title="Class intance_holder destructor">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> destructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">instance_holder</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
destroys the object
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_modifiers"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_modifiers" title="Class intance_holder modifiers">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> modifiers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">install</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">inst</span><span class="special">)</span> <span class="keyword">throw</span><span class="special">();</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">inst</span></code> is a Python
instance of a wrapped C++ class type, or is a type derived from
a wrapped C++ class type.
</p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
installs the new instance at the head of the Python object's chain
of held instances.
</p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
nothing
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_observers"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.class_template_instance_holder.class_intance_holder_observers" title="Class intance_holder observers">Class
<code class="computeroutput"><span class="identifier">intance_holder</span></code> observers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">*</span><span class="identifier">holds</span><span class="special">(</span><span class="identifier">type_info</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
A pointer to an object of the type described by <code class="computeroutput"><span class="identifier">x</span></code>
if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
contains such an object, 0 otherwise.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_instance_holder_hpp.examples"></a><a class="link" href="boost_python_instance_holder_hpp.html#utility_and_infrastructure.boost_python_instance_holder_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
The following is a simplified version of the instance holder template used
by Boost.Python to wrap classes held by smart pointers:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">SmartPtr</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Value</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">pointer_holder</span> <span class="special">:</span> <span class="identifier">instance_holder</span>
<span class="special">{</span>
<span class="comment">// construct from the SmartPtr type</span>
<span class="identifier">pointer_holder</span><span class="special">(</span><span class="identifier">SmartPtr</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">:</span><span class="identifier">m_p</span><span class="special">(</span><span class="identifier">p</span><span class="special">)</span>
<span class="comment">// Forwarding constructors for the held type</span>
<span class="identifier">pointer_holder</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*)</span>
<span class="special">:</span><span class="identifier">m_p</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">Value</span><span class="special">())</span>
<span class="special">{</span>
<span class="special">}</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">&gt;</span>
<span class="identifier">pointer_holder</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*,</span><span class="identifier">A0</span> <span class="identifier">a0</span><span class="special">)</span>
<span class="special">:</span><span class="identifier">m_p</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">Value</span><span class="special">(</span><span class="identifier">a0</span><span class="special">))</span>
<span class="special">{</span>
<span class="special">}</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A0</span><span class="special">,</span><span class="keyword">class</span> <span class="identifier">A1</span><span class="special">&gt;</span>
<span class="identifier">pointer_holder</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*,</span><span class="identifier">A0</span> <span class="identifier">a0</span><span class="special">,</span><span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
<span class="special">:</span><span class="identifier">m_p</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">Value</span><span class="special">(</span><span class="identifier">a0</span><span class="special">,</span><span class="identifier">a1</span><span class="special">))</span>
<span class="special">{</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="keyword">private</span><span class="special">:</span> <span class="comment">// required holder implementation</span>
<span class="keyword">void</span><span class="special">*</span> <span class="identifier">holds</span><span class="special">(</span><span class="identifier">type_info</span> <span class="identifier">dst_t</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// holds an instance of the SmartPtr type...</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">dst_t</span> <span class="special">==</span> <span class="identifier">python</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">SmartPtr</span><span class="special">&gt;())</span>
<span class="keyword">return</span> <span class="special">&amp;</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">m_p</span><span class="special">;</span>
<span class="comment">// ...and an instance of the SmartPtr's element_type, if the</span>
<span class="comment">// pointer is non-null</span>
<span class="keyword">return</span> <span class="identifier">python</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">Value</span><span class="special">&gt;()</span> <span class="special">==</span> <span class="identifier">dst_t</span> <span class="special">?</span> <span class="special">&amp;*</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">m_p</span> <span class="special">:</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span> <span class="comment">// data members</span>
<span class="identifier">SmartPtr</span> <span class="identifier">m_p</span><span class="special">;</span>
<span class="special">};</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../utility_and_infrastructure.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_pointee_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,106 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/pointee.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="boost_python_instance_holder_hpp.html" title="boost/python/instance_holder.hpp">
<link rel="next" href="boost_python_handle_hpp.html" title="boost/python/handle.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_instance_holder_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_handle_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_pointee_hpp"></a><a class="link" href="boost_python_pointee_hpp.html" title="boost/python/pointee.hpp">boost/python/pointee.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee">Class
template <code class="computeroutput"><span class="identifier">pointee</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples">Examples</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_pointee_hpp.introduction"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/pointee.hpp&gt; introduces a traits metafunction <code class="computeroutput"><span class="keyword">template</span> <span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> that can be used to extract the "pointed-to"
type from the type of a pointer or smart pointer.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee" title="Class template pointee">Class
template <code class="computeroutput"><span class="identifier">pointee</span></code></a>
</h3></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
is used by the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;"><code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;...&gt;</span></code></a>
template to deduce the type being held when a pointer or smart pointer
type is used as its HeldType argument.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">pointee</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">::</span><span class="identifier">element_type</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">// specialization for pointers</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">*&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_pointee_hpp.examples"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
Given a 3rd-party smart pointer type <code class="computeroutput"><span class="identifier">smart_pointer</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>, one might partially specialize <code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">smart_pointer</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;</span></code> so that it can be used as the HeldType
for a class wrapper:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">pointee</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">third_party_lib</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">smart_pointer</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">pointee_demo</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">third_party_class</span><span class="special">,</span> <span class="identifier">smart_pointer</span><span class="special">&lt;</span><span class="identifier">third_party_class</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"third_party_class"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(...)</span>
<span class="special">...</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_instance_holder_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_handle_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,90 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/ssize_t.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="boost_python_type_id_hpp.html" title="boost/python/type_id.hpp">
<link rel="next" href="../topics.html" title="Chapter&#160;8.&#160;Topics">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_type_id_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../topics.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_ssize_t_hpp"></a><a class="link" href="boost_python_ssize_t_hpp.html" title="boost/python/ssize_t.hpp">boost/python/ssize_t.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.typedefs">Typedefs</a></span></dt>
<dt><span class="section"><a href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.constants">Constants</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_ssize_t_hpp.introduction"></a><a class="link" href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Python 2.5 introduces a new <code class="computeroutput"><span class="identifier">Py_ssize_t</span></code>
typedef and two related macros (<a href="http://www.python.org/dev/peps/pep-0353/" target="_top">PEP
353</a>). The &lt;boost/python/ssize_t.hpp&gt; header imports these
definitions into the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span></code>
namespace as <code class="computeroutput"><span class="identifier">ssize_t</span></code>,
<code class="computeroutput"><span class="identifier">ssize_t_max</span></code>, and <code class="computeroutput"><span class="identifier">ssize_t_min</span></code>. Appropriate definitions
are provided for backward compatibility with previous Python versions.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_ssize_t_hpp.typedefs"></a><a class="link" href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.typedefs" title="Typedefs">Typedefs</a>
</h3></div></div></div>
<p>
Imports <code class="computeroutput"><span class="identifier">Py_ssize_t</span></code> into
the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span></code> namespace if available, or provides
an appropriate typedef for backward compatibility:
</p>
<pre class="programlisting"><span class="preprocessor">#if</span> <span class="identifier">PY_VERSION_HEX</span> <span class="special">&gt;=</span> <span class="number">0x02050000</span>
<span class="keyword">typedef</span> <span class="identifier">Py_ssize_t</span> <span class="identifier">ssize_t</span><span class="special">;</span>
<span class="preprocessor">#else</span>
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">ssize_t</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_ssize_t_hpp.constants"></a><a class="link" href="boost_python_ssize_t_hpp.html#utility_and_infrastructure.boost_python_ssize_t_hpp.constants" title="Constants">Constants</a>
</h3></div></div></div>
<p>
Imports <code class="computeroutput"><span class="identifier">PY_SSIZE_T_MAX</span></code>
and <code class="computeroutput"><span class="identifier">PY_SSIZE_T_MIN</span></code> as constants
into the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span></code> namespace if available, or provides
appropriate constants for backward compatibility:
</p>
<pre class="programlisting"><span class="preprocessor">#if</span> <span class="identifier">PY_VERSION_HEX</span> <span class="special">&gt;=</span> <span class="number">0x02050000</span>
<span class="identifier">ssize_t</span> <span class="keyword">const</span> <span class="identifier">ssize_t_max</span> <span class="special">=</span> <span class="identifier">PY_SSIZE_T_MAX</span><span class="special">;</span>
<span class="identifier">ssize_t</span> <span class="keyword">const</span> <span class="identifier">ssize_t_min</span> <span class="special">=</span> <span class="identifier">PY_SSIZE_T_MIN</span><span class="special">;</span>
<span class="preprocessor">#else</span>
<span class="identifier">ssize_t</span> <span class="keyword">const</span> <span class="identifier">ssize_t_max</span> <span class="special">=</span> <span class="identifier">INT_MAX</span><span class="special">;</span>
<span class="identifier">ssize_t</span> <span class="keyword">const</span> <span class="identifier">ssize_t_min</span> <span class="special">=</span> <span class="identifier">INT_MIN</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_type_id_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../topics.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,234 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/type_id.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="boost_python_handle_hpp.html" title="boost/python/handle.hpp">
<link rel="next" href="boost_python_ssize_t_hpp.html" title="boost/python/ssize_t.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_handle_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ssize_t_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_type_id_hpp"></a><a class="link" href="boost_python_type_id_hpp.html" title="boost/python/type_id.hpp">boost/python/type_id.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.introduction"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
&lt;boost/python/type_id.hpp&gt; provides types and functions for runtime
type identification like those of of <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</span></code>.
It exists mostly to work around certain compiler bugs and platform-dependent
interactions with shared libraries.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info" title="Class template type_info">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code></a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> comparison</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> observers</a></span></dt>
</dl></div>
<p>
<code class="computeroutput"><span class="identifier">type_info</span></code> instances identify
a type. As <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span></code> is specified to (but unlike
its implementation in some compilers), <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_info</span></code>
never represents top-level references or cv-qualification (see section
5.2.8 in the C++ standard). Unlike <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span></code>,
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_info</span></code> instances are copyable, and
comparisons always work reliably across shared library boundaries.
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">type_info</span> <span class="special">:</span> <span class="identifier">totally_ordered</span><span class="special">&lt;</span><span class="identifier">type_info</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="comment">// constructor</span>
<span class="identifier">type_info</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">void</span><span class="special">));</span>
<span class="comment">// comparisons</span>
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&lt;(</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="comment">// observers</span>
<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru" title="Class template type_info constructor">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> constructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">type_info</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">void</span><span class="special">));</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
constructs a <code class="computeroutput"><span class="identifier">type_info</span></code>
object which identifies the same type as its argument.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Since it is occasionally necessary to make an array of <code class="computeroutput"><span class="identifier">type_info</span></code> objects a benign default
argument is supplied. Note: this constructor does not correct for
non-conformance of compiler <code class="computeroutput"><span class="keyword">typeid</span><span class="special">()</span></code> implementations. See <code class="computeroutput"><span class="identifier">type_id</span></code>, below.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari" title="Class template type_info comparison">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> comparison</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&lt;(</span><span class="identifier">type_info</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
yields a total order over <code class="computeroutput"><span class="identifier">type_info</span></code>
objects.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">type_info</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="keyword">true</span></code> iff the two values
describe the same type.
</p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
The use of <code class="computeroutput"><span class="identifier">totally_ordered</span><span class="special">&lt;</span><span class="identifier">type_info</span><span class="special">&gt;</span></code> as a private base class supplies
operators <code class="computeroutput"><span class="special">&lt;=</span></code>,
<code class="computeroutput"><span class="special">&gt;=</span></code>, <code class="computeroutput"><span class="special">&gt;</span></code>, and <code class="computeroutput"><span class="special">!=</span></code>
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe" title="Class template type_info observers">Class
template <code class="computeroutput"><span class="identifier">type_info</span></code> observers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
The result of calling <code class="computeroutput"><span class="identifier">name</span><span class="special">()</span></code> on the argument used to construct
the object.
</p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.functions"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&lt;&lt;(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="identifier">x</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Effects</span></dt>
<dd><p>
Writes a description of the type described by to <code class="computeroutput"><span class="identifier">x</span></code>
into s.
</p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
Not every C++ implementation provides a truly human-readable <code class="computeroutput"><span class="identifier">type_info</span><span class="special">::</span><span class="identifier">name</span><span class="special">()</span></code>
string, but for some we may be able to decode the string and produce
a reasonable representation.
</p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
On some non-conforming C++ implementations, the code is not actually
as simple as described above; the semantics are adjusted to work
as-if the C++ implementation were conforming.
</p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type_info</span> <span class="identifier">type_id</span><span class="special">()</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">type_info</span><span class="special">(</span><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">))</span></code>
</p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
On some non-conforming C++ implementations, the code is not actually
as simple as described above; the semantics are adjusted to work
as-if the C++ implementation were conforming.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.example"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
The following example, though silly, illustrates how the type_id facility
might be used
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">type_id</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// Returns true iff the user passes an int argument</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">is_int</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;()</span> <span class="special">==</span> <span class="identifier">type_id</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_handle_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ssize_t_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>