Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/doc/v2/overloads.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: 7.5 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/overloads.hpp&gt;</title>
14  </head>
15
16  <body>
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">Header &lt;boost/python/overloads.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      "#overload-dispatch-expression"><i>overload-dispatch-expressions</i></a></dt>
41
42      <dt><a href= "#OverloadDispatcher-concept">OverloadDispatcher</a> concept</dt>
43
44      <dt><a href="#macros">Macros</a></dt>
45
46      <dd>
47        <dl class="page-index">
48          <dt><a href=
49          "#BOOST_PYTHON_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_FUNCTION_OVERLOADS</a></dt>
50
51          <dt><a href=
52          "#BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</a></dt>
53        </dl>
54      </dd>
55
56      <dt><a href="#examples">Example(s)</a></dt>
57    </dl>
58    <hr>
59
60    <h2><a name="introduction"></a>Introduction</h2>
61
62    <p>Defines facilities for generating families of overloaded Python
63    functions and extension class methods from C++ functions and
64    member functions with default arguments, or from similar families
65    of C++ overloads</p>
66
67    <h2><a name=
68    "overload-dispatch-expression"></a><i>overload-dispatch-expressions</i></h2>
69
70    <p>
71    An <em>overload-dispatch-expression</em> is used to describe a
72    family of overloaded methods to be generated for an extension
73    class. It has the following properties:
74
75    <blockquote>
76      <dl class="properties">
77        <dt><b>docstring:</b> An <a href="definitions.html#ntbs">ntbs</a>
78        whose value will bound to the methods' <code>__doc__</code>
79        attribute</dt>
80
81        <dt><b>keywords:</b> A <a href=
82        "args.html#keyword-expression">keyword-expression</a> which
83        will be used to name (a trailing subsequence of) the arguments
84        to the generated methods.</dt>
85
86        <dt><b>call policies:</b> An instance of some type which models <a href=
87        "CallPolicies.html">CallPolicies</a>.</dt>
88
89        <dt><b>minimum <a href="definitions.html#arity">arity</a></b>
90        The minimum number of arguments to be accepted by a generated
91        method overload.</dt>
92
93        <dt><b>maximum <a href="definitions.html#arity">arity</a></b>
94        The maximum number of arguments to be accepted by a generated
95        method overload.</dt>
96      </dl>
97    </blockquote>
98
99    <h2><a name="OverloadDispatcher-concept"></a>OverloadDispatcher Concept</h2>
100
101    An OverloadDispatcher <code>X</code> is a class which has a
102    <em>minimum arity</em> and a <em>maximum arity</em>, and for which
103    the following following are valid <a
104    href="#overload-dispatch-expression"><em>overload-dispatch-expression</em></a>s,
105    with the same minimum and maximum arity as the OverloadDispatcher.
106
107<pre>
108X()
109X(docstring)
110X(docstring, keywords)
111X(keywords, docstring)
112X()[policies]
113X(docstring)[policies]
114X(docstring, keywords)[policies]
115X(keywords, docstring)[policies]
116</pre>
117
118<ul>
119<li>If <code>policies</code> are supplied, it must be an instance of a
120type which models <a
121href="CallPolicies.html#CallPolicies-concept">CallPolicies</a>, and
122will be used as the result's call policies. Otherwise the result's
123call policies will be an instance of <a
124href="default_call_policies.html#default_call_policies-spec">default_call_policies</a>.
125
126<li>If <code>docstring</code> is supplied it must be an <a
127href="definitions.html#ntbs">ntbs</a>, and will be used as the result's docstring. Otherwise the result has an empty docstring.
128
129<li>If <code>keywords</code> is supplied it must be the result of a <a
130        href= "args.html#keyword-expression">keyword-expression</a>
131        whose length is no greater than <code>X</code>'s maximum
132        arity, and will be used as the result's keywords. Otherwise
133        the result's keywords will be empty.
134</ul>
135
136
137
138
139    <h2><a name="macros"></a>Macros</h2>
140
141    <h3><a name=
142    "BOOST_PYTHON_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_FUNCTION_OVERLOADS(name,&nbsp;func_id,&nbsp;min_args,&nbsp;max_args)</a></h3>
143    Expands to the definition of an OverloadDispatcher called
144    <code>name</code> in the current scope which can be used to
145    generate the following function invocation:
146<pre>
147func_id(a<small><i>1</i></small>, a<small><i>2</i></small>,...a<small><i>i</i></small>);
148</pre>
149
150   for all <code>min_args</code> &lt;= <i>i</i> &lt;= <code>max_args</code>.
151
152    <h3><a name=
153    "BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(name,&nbsp;member_name,&nbsp;min_args,&nbsp;max_args)</a></h3>
154
155    Expands to the definition of an OverloadDispatcher called
156    <code>name</code> in the current scope which can be used to
157    generate the following function invocation:
158<pre>
159x.member_name(a<small><i>1</i></small>, a<small><i>2</i></small>,...a<small><i>i</i></small>);
160</pre>
161
162   for all <code>min_args</code> &lt;= <i>i</i> &lt;=
163   <code>max_args</code>, where <code>x</code> is a reference to an
164   object of class type.
165
166    <h2><a name="examples"></a>Example(s)</h2>
167
168<pre>
169#include &lt;boost/python/module.hpp&gt;
170#include &lt;boost/python/def.hpp&gt;
171#include &lt;boost/python/args.hpp&gt;
172#include &lt;boost/python/tuple.hpp&gt;
173#include &lt;boost/python/class.hpp&gt;
174#include &lt;boost/python/overloads.hpp&gt;
175#include &lt;boost/python/return_internal_reference.hpp&gt;
176
177using namespace boost::python;
178
179tuple f(int x = 1, double y = 4.25, char const* z = &quot;wow&quot;)
180{
181    return make_tuple(x, y, z);
182}
183
184BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads, f, 0, 3)
185
186struct Y {};
187struct X
188{
189    Y&amp; f(int x, double y = 4.25, char const* z = &quot;wow&quot;)
190    {
191        return inner;
192    }
193    Y inner;
194};
195
196BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_member_overloads, f, 1, 3)
197
198BOOST_PYTHON_MODULE(args_ext)
199{
200    def(&quot;f&quot;, f,
201        f_overloads(
202            args(&quot;x&quot;, &quot;y&quot;, &quot;z&quot;), &quot;This is f's docstring&quot;
203        ));
204
205   
206    class_&lt;Y&gt;(&quot;Y&quot;)
207        ;
208           
209    class_&lt;X&gt;(&quot;X&quot;, &quot;This is X's docstring&quot;)
210        .def(&quot;f1&quot;, &amp;X::f,
211                f_member_overloads(
212                    args(&quot;x&quot;, &quot;y&quot;, &quot;z&quot;), &quot;f's docstring&quot;
213                )[return_internal_reference&lt;&gt;()]
214        )
215        ;
216}
217</pre>
218
219    <p>Revised
220    <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
221  15 April, 2003
222  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
223    </p>
224
225    <p><i>&copy; Copyright <a href=
226    "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
227  </body>
228</html>
229
Note: See TracBrowser for help on using the repository browser.