1 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
---|
2 | <!-- Software License, Version 1.0. (See accompanying --> |
---|
3 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
---|
4 | <html> |
---|
5 | <head> |
---|
6 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
7 | <link rel="stylesheet" type="text/css" href="../boost.css"> |
---|
8 | <title>Boost.Python - <call.hpp></title> |
---|
9 | </head> |
---|
10 | <body link="#0000ff" vlink="#800080"> |
---|
11 | <table border="0" cellpadding="7" cellspacing="0" width="100%" summary= |
---|
12 | "header"> |
---|
13 | <tr> |
---|
14 | <td valign="top" width="300"> |
---|
15 | <h3><a href="../../../../index.htm"><img height="86" width="277" alt= |
---|
16 | "C++ Boost" src="../../../../boost.png" border="0"></a></h3> |
---|
17 | </td> |
---|
18 | <td valign="top"> |
---|
19 | <h1 align="center"><a href="../index.html">Boost.Python</a></h1> |
---|
20 | <h2 align="center">Header <call.hpp></h2> |
---|
21 | </td> |
---|
22 | </tr> |
---|
23 | </table> |
---|
24 | <hr> |
---|
25 | <h2>Contents</h2> |
---|
26 | <dl class="page-index"> |
---|
27 | <dt><a href="#introduction">Introduction</a></dt> |
---|
28 | <dt><a href="#functions">Functions</a></dt> |
---|
29 | <dl class="page-index"> |
---|
30 | <dt><a href="#call-spec">call</a></dt> |
---|
31 | </dl> |
---|
32 | |
---|
33 | <dt><a href="#examples">Example(s)</a></dt> |
---|
34 | |
---|
35 | </dl> |
---|
36 | <hr> |
---|
37 | <h2><a name="introduction"></a>Introduction</h2> |
---|
38 | <p> |
---|
39 | <code><boost/python/call.hpp></code> defines the <a |
---|
40 | href="#call-spec"><code>call</code></a> family of overloaded function |
---|
41 | templates, used to invoke Python callable objects from C++. |
---|
42 | |
---|
43 | <h2><a name="functions"></a>Functions</h2> |
---|
44 | <pre> |
---|
45 | <a name="call-spec">template <class R, class A1, class A2, ... class A<i>n</i>></a> |
---|
46 | R call(PyObject* callable, A1 const&, A2 const&, ... A<i>n</i> const&) |
---|
47 | </pre> |
---|
48 | <dl class="function-semantics"> |
---|
49 | <dt><b>Requires:</b> <code>R</code> is a pointer type, reference |
---|
50 | type, or a complete type with an accessible copy constructor</dt> |
---|
51 | |
---|
52 | <dt><b>Effects:</b> Invokes <code>callable(a1, a2, ...a<i>n</i>)</code> in |
---|
53 | Python, where <code>a1</code>...<code>a<i>n</i></code> are the arguments to |
---|
54 | <code>call()</code>, converted to Python objects. |
---|
55 | <dt><b>Returns:</b> The result of the Python call, converted to the C++ type <code>R</code>.</dt> |
---|
56 | |
---|
57 | </dt> |
---|
58 | <dt><b>Rationale:</b> For a complete semantic description and |
---|
59 | rationale, see <a href="callbacks.html">this page</a>. |
---|
60 | </dt> |
---|
61 | </dl> |
---|
62 | |
---|
63 | <h2><a name="examples"></a>Example(s)</h2> |
---|
64 | |
---|
65 | The following C++ function applies a Python callable object to its two |
---|
66 | arguments and returns the result. If a Python exception is raised or |
---|
67 | the result can't be converted to a <code>double</code>, an exception |
---|
68 | is thrown. |
---|
69 | |
---|
70 | <pre> |
---|
71 | double apply2(PyObject* func, double x, double y) |
---|
72 | { |
---|
73 | return boost::python::call<double>(func, x, y); |
---|
74 | } |
---|
75 | </pre> |
---|
76 | |
---|
77 | <p>Revised |
---|
78 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
---|
79 | 9 May, 2002 <!-- Luann's birthday! --> |
---|
80 | <!--webbot bot="Timestamp" endspan i-checksum="39359" --> |
---|
81 | </p> |
---|
82 | <p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a> |
---|
83 | 2002. </i></p> |
---|
84 | </body> |
---|
85 | </html> |
---|