Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/doc/v2/init.html @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 8.8 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
4<!-- Software License, Version 1.0. (See accompanying -->
5<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
6<html>
7  <head>
8    <meta name="generator" content=
9    "HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
10    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
11    <link rel="stylesheet" type="text/css" href="../boost.css">
12
13    <title>Boost.Python - &lt;boost/python/init.hpp&gt;</title>
14  </head>
15
16  <body link="#0000ff" vlink="#800080">
17    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
18    "header">
19      <tr>
20        <td valign="top" width="300">
21          <h3><a href="../../../../index.htm"><img height="86" width="277"
22          alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
23        </td>
24
25        <td valign="top">
26          <h1 align="center"><a href="../index.html">Boost.Python</a></h1>
27
28          <h2 align="center">Headers &lt;boost/python/init.hpp&gt;</h2>
29        </td>
30      </tr>
31    </table>
32    <hr>
33
34    <h2>Contents</h2>
35
36    <dl class="page-index">
37      <dt><a href="#introduction">Introduction</a></dt>
38
39              <dt><a href=
40              "#init-expressions"><em>init-expressions</em></a></dt>
41
42      <dt><a href="#classes">Classes</a></dt>
43
44      <dd>
45        <dl class="page-index">
46          <dt><a href="#init-spec">Class template <code>init</code></a></dt>
47
48          <dd>
49            <dl class="page-index">
50              <dt><a href="#init-spec-synopsis">Class template
51              <code>init</code> synopsis</a></dt>
52
53              <dt><a href="#init-spec-ctors">Class <code>init</code>
54              constructors</a></dt>
55
56            </dl>
57          </dd>
58
59          <dt><a href="#optional-spec">Class template
60          <code>optional</code></a></dt>
61
62          <dd>
63            <dl class="page-index">
64              <dt><a href="#optional-spec-synopsis">Class template
65              <code>optional</code> synopsis</a></dt>
66            </dl>
67          </dd>
68        </dl>
69      </dd>
70
71      <dt><a href="#examples">Example(s)</a></dt>
72    </dl>
73    <hr>
74
75    <h2><a name="introduction"></a>Introduction</h2>
76
77    <p><code>&lt;boost/python/init.hpp&gt;</code> defines the interface for
78    exposing C++ constructors to Python as extension class
79    <code>__init__</code> functions.</p>
80
81    <h2><a name="init-expressions"><em>init-expressions</em></a></h2>
82    An <em>init-expression</em> is used to describe a family of
83    <code>__init__</code> methods to be generated for an extension class, and
84    the result has the following properties:
85
86    <blockquote>
87      <dl class="properties">
88        <dt><b>docstring:</b> An <a href="definitions.html#ntbs">ntbs</a>
89        whose value will bound to the method's <code>__doc__</code>
90        attribute</dt>
91
92        <dt><b>keywords:</b> A <a href=
93        "args.html#keyword-expression">keyword-expression</a> which will be
94        used to name (a trailing subsequence of) the arguments to the
95        generated <code>__init__</code> function(s).</dt>
96
97        <dt><b>call policies:</b> An instance of a model of <a href=
98        "CallPolicies.html">CallPolicies</a>.</dt>
99
100        <dt><b>argument types:</b> An MPL sequence of C++ argument types
101        which will be used to construct the wrapped C++ object. An init
102        expression has one or more
103        <b>valid prefixes</b> which are given by a sequence of
104        prefixes of its argument types.</dt>
105      </dl>
106    </blockquote>
107
108    <h2><a name="classes"></a>Classes</h2>
109
110    <h3><a name="init-spec"></a>Class template <code>init&lt;T1 =</code>
111    <i>unspecified</i><code>,&nbsp;T2 =</code>
112    <i>unspecified</i><code>,</code>...<code>Tn</code> =
113    <i>unspecified</i><code>&gt;</code></h3>
114
115    <p>A <a href="../../../mpl/doc/refmanual/forward-sequence.html">MPL sequence</a> which
116    can be used to specify a family of one or more <code>__init__</code>
117    functions. Only the last <code>T</code><i><small>i</small></i> supplied
118    may be an instantiation of <a href=
119    "#optional-spec"><code>optional</code></a><code>&lt;</code>...<code>&gt;</code>.</p>
120
121    <h4><a name="init-spec-synopsis"></a>Class template <code>init</code>
122    synopsis</h4>
123<pre>
124namespace boost { namespace python
125{
126  template &lt;T1 = <i>unspecified</i>,...T<i>n</i> = <i>unspecified</i>&gt;
127  struct init
128  {
129      init(char const* doc = 0);
130      template &lt;class Keywords&gt; init(Keywords const&amp; kw, char const* doc = 0);
131      template &lt;class Keywords&gt; init(char const* doc, Keywords const&amp; kw);
132
133      template &lt;class CallPolicies&gt;
134      <em>unspecified</em> operator[](CallPolicies const&amp; policies) const
135  };
136}}
137</pre>
138
139    <h4><a name="init-spec-ctors"></a>Class template <code>init</code>
140    constructors</h4>
141<pre>
142init(char const* doc = 0);
143template &lt;class Keywords&gt; init(Keywords const&amp; kw, char const* doc = 0);
144template &lt;class Keywords&gt; init(char const* doc, Keywords const&amp; kw);
145</pre>
146
147    <dl class="function-semantics">
148      <dt><b>Requires:</b> If supplied, <code>doc</code> is an <a href=
149      "definitions.html#ntbs">ntbs</a>. If supplied, <code>kw</code> is the
150      result of a <a href="args.html#keyword-expression"></a></dt>
151
152      <dt><b>Effects:</b> The result is an <em>init-expression</em> whose
153      <em>docstring</em> is <code>doc</code> and whose <em>keywords</em> are
154      a reference to <code>kw</code>. If the first form is used, the
155      resulting expression's <em>keywords</em> are empty. The expression's
156      <em>call policies</em> are an instance of <a href=
157      "default_call_policies.html#default_call_policies-spec">default_call_policies</a>.
158      If <code>T</code><i><small>n</small></i> is <a href=
159      "#optional-spec"><code>optional</code></a><code>&lt;U1,&nbsp;U2,</code>...
160      <code>U</code><small><i>m</i></small><code>&gt;</code>, the
161      expression's <em>valid prefixes</em> are given by:</dt>
162
163      <dd>
164        <blockquote>
165          (<code>T1,&nbsp;T2,</code>...<code>T</code><i><small>n-1</small></i>),
166          (<code>T1,&nbsp;T2,</code>...<code>T</code><i><small>n-1</small></i>
167          <code>,&nbsp;U1</code>),
168          (<code>T1,&nbsp;T2,</code>...<code>T</code><i><small>n-1</small></i>
169          <code>,&nbsp;U1,&nbsp;U2</code>),
170          ...(<code>T1,&nbsp;T2,</code>...<code>T</code><i><small>n-1</small></i>
171          <code>,&nbsp;U1,&nbsp;U2,</code>...<code>U</code><i><small>m</small></i>).
172        </blockquote>
173        Otherwise, the expression has one <em>valid prefix</em> given by the
174        the template arguments the user specified.
175      </dd>
176    </dl>
177
178    <h4><a name="init-spec-observers"></a>Class template <code>init</code>
179    observer functions</h4>
180<pre>
181template &lt;class Policies&gt;
182<em>unspecified</em> operator[](Policies const&amp; policies) const
183</pre>
184
185    <dl class="function-semantics">
186      <dt><b>Requires:</b> Policies is a model of <a href=
187      "CallPolicies.html">CallPolicies</a>.</dt>
188
189      <dt><b>Effects:</b> Returns a new <a href=
190      "#init-expressions"><em>init-expression</em></a> with all the same
191      properties as the <code>init</code> object except that its <em>call
192      policies</em> are replaced by a reference to
193      <code>policies</code>.</dt>
194    </dl>
195
196    <h3><a name="optional-spec"></a>Class template <code>optional&lt;T1
197    =</code> <i>unspecified</i><code>,&nbsp;T2 =</code>
198    <i>unspecified</i><code>,</code>...<code>Tn</code> =
199    <i>unspecified</i><code>&gt;</code></h3>
200
201    <p>A <a href="../../../mpl/doc/refmanual/forward-sequence.html">MPL sequence</a> which
202    can be used to specify the optional arguments to an <code>__init__</code>
203    function.</p>
204
205    <h4><a name="optional-spec-synopsis"></a>Class template
206    <code>optional</code> synopsis</h4>
207<pre>
208namespace boost { namespace python
209{
210  template &lt;T1 = <i>unspecified</i>,...T<i>n</i> = <i>unspecified</i>&gt;
211  struct optional {};
212}}
213</pre>
214
215    <h2><a name="examples"></a>Example(s)</h2>
216
217    <p>Given the C++ declarations:</p>
218<pre>
219class Y;
220class X
221{
222 public:
223   X(int x, Y* y) : m_y(y) {}
224   X(double);
225 private:
226   Y* m_y;
227};
228</pre>
229    A corresponding Boost.Python extension class can be created with:
230<pre>
231using namespace boost::python;
232
233class_&lt;X&gt;("X", "This is X's docstring.",
234          init&lt;int,char const*&gt;(args("x","y"), "X.__init__'s docstring")[
235                with_custodian_and_ward&lt;1,3&gt;()]
236          )
237   .def(init&lt;double&gt;())
238   ;
239</pre>
240    <hr>
241    Revised
242    <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
243  13 November, 2002
244  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
245     
246
247    <p><i>&copy; Copyright <a href=
248    "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
249  </body>
250</html>
251
Note: See TracBrowser for help on using the repository browser.