mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
https://svn.boost.org/svn/boost/trunk ........ r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line Fix some broken links. ........ r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line Link to people pages on the website, as they've been removed from the download. ........ r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line Point links to the pages that used to be in 'more' to the site. ........ r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line Fix links on the home page as well. ........ r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line Generated documentation which is no longer generated. ........ [SVN r43214]
252 lines
8.8 KiB
HTML
252 lines
8.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
|
<!-- Software License, Version 1.0. (See accompanying -->
|
|
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content=
|
|
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link rel="stylesheet" type="text/css" href="../boost.css">
|
|
|
|
<title>Boost.Python - <boost/python/init.hpp></title>
|
|
</head>
|
|
|
|
<body link="#0000ff" vlink="#800080">
|
|
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
|
"header">
|
|
<tr>
|
|
<td valign="top" width="300">
|
|
<h3><a href="../../../../index.htm"><img height="86" width="277"
|
|
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
|
|
</td>
|
|
|
|
<td valign="top">
|
|
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
|
|
|
|
<h2 align="center">Headers <boost/python/init.hpp></h2>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr>
|
|
|
|
<h2>Contents</h2>
|
|
|
|
<dl class="page-index">
|
|
<dt><a href="#introduction">Introduction</a></dt>
|
|
|
|
<dt><a href=
|
|
"#init-expressions"><em>init-expressions</em></a></dt>
|
|
|
|
<dt><a href="#classes">Classes</a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#init-spec">Class template <code>init</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#init-spec-synopsis">Class template
|
|
<code>init</code> synopsis</a></dt>
|
|
|
|
<dt><a href="#init-spec-ctors">Class <code>init</code>
|
|
constructors</a></dt>
|
|
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#optional-spec">Class template
|
|
<code>optional</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#optional-spec-synopsis">Class template
|
|
<code>optional</code> synopsis</a></dt>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#examples">Example(s)</a></dt>
|
|
</dl>
|
|
<hr>
|
|
|
|
<h2><a name="introduction"></a>Introduction</h2>
|
|
|
|
<p><code><boost/python/init.hpp></code> defines the interface for
|
|
exposing C++ constructors to Python as extension class
|
|
<code>__init__</code> functions.</p>
|
|
|
|
<h2><a name="init-expressions"><em>init-expressions</em></a></h2>
|
|
An <em>init-expression</em> is used to describe a family of
|
|
<code>__init__</code> methods to be generated for an extension class, and
|
|
the result has the following properties:
|
|
|
|
<blockquote>
|
|
<dl class="properties">
|
|
<dt><b>docstring:</b> An <a href="definitions.html#ntbs">ntbs</a>
|
|
whose value will bound to the method's <code>__doc__</code>
|
|
attribute</dt>
|
|
|
|
<dt><b>keywords:</b> A <a href=
|
|
"args.html#keyword-expression">keyword-expression</a> which will be
|
|
used to name (a trailing subsequence of) the arguments to the
|
|
generated <code>__init__</code> function(s).</dt>
|
|
|
|
<dt><b>call policies:</b> An instance of a model of <a href=
|
|
"CallPolicies.html">CallPolicies</a>.</dt>
|
|
|
|
<dt><b>argument types:</b> An MPL sequence of C++ argument types
|
|
which will be used to construct the wrapped C++ object. An init
|
|
expression has one or more
|
|
<b>valid prefixes</b> which are given by a sequence of
|
|
prefixes of its argument types.</dt>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h2><a name="classes"></a>Classes</h2>
|
|
|
|
<h3><a name="init-spec"></a>Class template <code>init<T1 =</code>
|
|
<i>unspecified</i><code>, T2 =</code>
|
|
<i>unspecified</i><code>,</code>...<code>Tn</code> =
|
|
<i>unspecified</i><code>></code></h3>
|
|
|
|
<p>A <a href="../../../mpl/doc/refmanual/forward-sequence.html">MPL sequence</a> which
|
|
can be used to specify a family of one or more <code>__init__</code>
|
|
functions. Only the last <code>T</code><i><small>i</small></i> supplied
|
|
may be an instantiation of <a href=
|
|
"#optional-spec"><code>optional</code></a><code><</code>...<code>></code>.</p>
|
|
|
|
<h4><a name="init-spec-synopsis"></a>Class template <code>init</code>
|
|
synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python
|
|
{
|
|
template <T1 = <i>unspecified</i>,...T<i>n</i> = <i>unspecified</i>>
|
|
struct init
|
|
{
|
|
init(char const* doc = 0);
|
|
template <class Keywords> init(Keywords const& kw, char const* doc = 0);
|
|
template <class Keywords> init(char const* doc, Keywords const& kw);
|
|
|
|
template <class CallPolicies>
|
|
<em>unspecified</em> operator[](CallPolicies const& policies) const
|
|
};
|
|
}}
|
|
</pre>
|
|
|
|
<h4><a name="init-spec-ctors"></a>Class template <code>init</code>
|
|
constructors</h4>
|
|
<pre>
|
|
init(char const* doc = 0);
|
|
template <class Keywords> init(Keywords const& kw, char const* doc = 0);
|
|
template <class Keywords> init(char const* doc, Keywords const& kw);
|
|
</pre>
|
|
|
|
<dl class="function-semantics">
|
|
<dt><b>Requires:</b> If supplied, <code>doc</code> is an <a href=
|
|
"definitions.html#ntbs">ntbs</a>. If supplied, <code>kw</code> is the
|
|
result of a <a href="args.html#keyword-expression"></a></dt>
|
|
|
|
<dt><b>Effects:</b> The result is an <em>init-expression</em> whose
|
|
<em>docstring</em> is <code>doc</code> and whose <em>keywords</em> are
|
|
a reference to <code>kw</code>. If the first form is used, the
|
|
resulting expression's <em>keywords</em> are empty. The expression's
|
|
<em>call policies</em> are an instance of <a href=
|
|
"default_call_policies.html#default_call_policies-spec">default_call_policies</a>.
|
|
If <code>T</code><i><small>n</small></i> is <a href=
|
|
"#optional-spec"><code>optional</code></a><code><U1, U2,</code>...
|
|
<code>U</code><small><i>m</i></small><code>></code>, the
|
|
expression's <em>valid prefixes</em> are given by:</dt>
|
|
|
|
<dd>
|
|
<blockquote>
|
|
(<code>T1, T2,</code>...<code>T</code><i><small>n-1</small></i>),
|
|
(<code>T1, T2,</code>...<code>T</code><i><small>n-1</small></i>
|
|
<code>, U1</code>),
|
|
(<code>T1, T2,</code>...<code>T</code><i><small>n-1</small></i>
|
|
<code>, U1, U2</code>),
|
|
...(<code>T1, T2,</code>...<code>T</code><i><small>n-1</small></i>
|
|
<code>, U1, U2,</code>...<code>U</code><i><small>m</small></i>).
|
|
</blockquote>
|
|
Otherwise, the expression has one <em>valid prefix</em> given by the
|
|
the template arguments the user specified.
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4><a name="init-spec-observers"></a>Class template <code>init</code>
|
|
observer functions</h4>
|
|
<pre>
|
|
template <class Policies>
|
|
<em>unspecified</em> operator[](Policies const& policies) const
|
|
</pre>
|
|
|
|
<dl class="function-semantics">
|
|
<dt><b>Requires:</b> Policies is a model of <a href=
|
|
"CallPolicies.html">CallPolicies</a>.</dt>
|
|
|
|
<dt><b>Effects:</b> Returns a new <a href=
|
|
"#init-expressions"><em>init-expression</em></a> with all the same
|
|
properties as the <code>init</code> object except that its <em>call
|
|
policies</em> are replaced by a reference to
|
|
<code>policies</code>.</dt>
|
|
</dl>
|
|
|
|
<h3><a name="optional-spec"></a>Class template <code>optional<T1
|
|
=</code> <i>unspecified</i><code>, T2 =</code>
|
|
<i>unspecified</i><code>,</code>...<code>Tn</code> =
|
|
<i>unspecified</i><code>></code></h3>
|
|
|
|
<p>A <a href="../../../mpl/doc/refmanual/forward-sequence.html">MPL sequence</a> which
|
|
can be used to specify the optional arguments to an <code>__init__</code>
|
|
function.</p>
|
|
|
|
<h4><a name="optional-spec-synopsis"></a>Class template
|
|
<code>optional</code> synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python
|
|
{
|
|
template <T1 = <i>unspecified</i>,...T<i>n</i> = <i>unspecified</i>>
|
|
struct optional {};
|
|
}}
|
|
</pre>
|
|
|
|
<h2><a name="examples"></a>Example(s)</h2>
|
|
|
|
<p>Given the C++ declarations:</p>
|
|
<pre>
|
|
class Y;
|
|
class X
|
|
{
|
|
public:
|
|
X(int x, Y* y) : m_y(y) {}
|
|
X(double);
|
|
private:
|
|
Y* m_y;
|
|
};
|
|
</pre>
|
|
A corresponding Boost.Python extension class can be created with:
|
|
<pre>
|
|
using namespace boost::python;
|
|
|
|
class_<X>("X", "This is X's docstring.",
|
|
init<int,char const*>(args("x","y"), "X.__init__'s docstring")[
|
|
with_custodian_and_ward<1,3>()]
|
|
)
|
|
.def(init<double>())
|
|
;
|
|
</pre>
|
|
<hr>
|
|
Revised
|
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
|
13 November, 2002
|
|
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
|
|
|
|
|
<p><i>© Copyright <a href=
|
|
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
|
|
</body>
|
|
</html>
|
|
|