mirror of
https://github.com/boostorg/python.git
synced 2026-01-20 04:42:28 +00:00
Compare commits
128 Commits
boost-1.31
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c8f1fb5d3 | ||
|
|
d79c063b97 | ||
|
|
386bfcf20a | ||
|
|
61b03a8ce2 | ||
|
|
e163e0cc10 | ||
|
|
494bede2c0 | ||
|
|
183918be07 | ||
|
|
b9ff2f1a11 | ||
|
|
c7ad999adb | ||
|
|
04e16988ae | ||
|
|
272559c3be | ||
|
|
31bc1a4466 | ||
|
|
aa0dc52c94 | ||
|
|
dfcce0f2a9 | ||
|
|
182d9e9447 | ||
|
|
3c65122e1d | ||
|
|
7107628ae0 | ||
|
|
415016191a | ||
|
|
7430b7c4a6 | ||
|
|
d5c9831da8 | ||
|
|
1d295d7f11 | ||
|
|
0bc4ee884f | ||
|
|
bdde13d1bc | ||
|
|
887faad373 | ||
|
|
712b90dfe0 | ||
|
|
922a1b9194 | ||
|
|
3cadfa529e | ||
|
|
b5cd8c537f | ||
|
|
91db6f2d50 | ||
|
|
997467c29f | ||
|
|
2b127f9533 | ||
|
|
3bf081fcf9 | ||
|
|
a1da924e28 | ||
|
|
5a740d06c6 | ||
|
|
ef80b390cd | ||
|
|
e425a15fd2 | ||
|
|
1addeee962 | ||
|
|
f415f18574 | ||
|
|
5e6f06fde3 | ||
|
|
eaf784b024 | ||
|
|
4c4676db3e | ||
|
|
54114b2bd1 | ||
|
|
e2c58fcb7c | ||
|
|
c9de2a660f | ||
|
|
cbbc52e9d1 | ||
|
|
4e414c5371 | ||
|
|
0af5dc09c8 | ||
|
|
264ec8ddca | ||
|
|
5295f58aff | ||
|
|
88c03a6ef4 | ||
|
|
d9478fb117 | ||
|
|
d17ce4e588 | ||
|
|
06814a2251 | ||
|
|
cb26cf1a5b | ||
|
|
87217f8009 | ||
|
|
ecfd820d62 | ||
|
|
d91baaaa59 | ||
|
|
27bc69adbf | ||
|
|
0fd414f8cd | ||
|
|
5fc0aba562 | ||
|
|
b81435f4aa | ||
|
|
7482040832 | ||
|
|
2daf80f91e | ||
|
|
d3a25d2e72 | ||
|
|
a653c321f9 | ||
|
|
4f7abba608 | ||
|
|
b1a0f0a373 | ||
|
|
bb3887660e | ||
|
|
10bc8a3709 | ||
|
|
f57c10905a | ||
|
|
e39ede3116 | ||
|
|
b07d2e8591 | ||
|
|
d4ad3f55d5 | ||
|
|
324bba771c | ||
|
|
b032914876 | ||
|
|
43e1dc9d5b | ||
|
|
3847f1d455 | ||
|
|
5f9c0e5b50 | ||
|
|
1c5450292d | ||
|
|
2c93ea31dc | ||
|
|
89122d2415 | ||
|
|
20896e809d | ||
|
|
ba6cbe42de | ||
|
|
fbf82cc6e9 | ||
|
|
278bb1a861 | ||
|
|
82b1fd637d | ||
|
|
26d5ca22aa | ||
|
|
18279496da | ||
|
|
536ef11cce | ||
|
|
32f1d028e2 | ||
|
|
c7913267d4 | ||
|
|
73a65235c6 | ||
|
|
3267d5a2f3 | ||
|
|
e0ae98ee56 | ||
|
|
62a213fbbe | ||
|
|
1ddd2b800d | ||
|
|
9e593f1f79 | ||
|
|
237cce7dae | ||
|
|
55a33c287c | ||
|
|
f9ddcdf61b | ||
|
|
5c5ed38973 | ||
|
|
2ecb9c6232 | ||
|
|
7c14b3fac4 | ||
|
|
6b4d0a1119 | ||
|
|
05dd7bf52a | ||
|
|
125d2084df | ||
|
|
314dbcae33 | ||
|
|
e13f2f11db | ||
|
|
28ad5ff233 | ||
|
|
41bf4105c2 | ||
|
|
9c773b5387 | ||
|
|
4eb977b511 | ||
|
|
1dff9421dd | ||
|
|
ec7b352178 | ||
|
|
186693f710 | ||
|
|
d7a88b6f7e | ||
|
|
c8898caba0 | ||
|
|
9983782b2c | ||
|
|
87f1985463 | ||
|
|
13e118b0dd | ||
|
|
f7c034d510 | ||
|
|
2f68553e18 | ||
|
|
9980a5824e | ||
|
|
c3ac52a4a8 | ||
|
|
14a7d7fba4 | ||
|
|
7d77f80036 | ||
|
|
6eeb6e6650 | ||
|
|
0b1e457c77 |
@@ -52,6 +52,8 @@ if [ check-python-config ]
|
||||
object/iterator.cpp
|
||||
object_protocol.cpp
|
||||
object_operators.cpp
|
||||
indexing/slice.cpp
|
||||
indexing/python_iterator.cpp
|
||||
;
|
||||
|
||||
dll boost_python
|
||||
@@ -60,7 +62,6 @@ if [ check-python-config ]
|
||||
<define>BOOST_PYTHON_SOURCE
|
||||
$(bpl-linkflags)
|
||||
<msvc-stlport><release>$(msvc-stlport-workarounds)
|
||||
<darwin><*><linkflags>-bind_at_load
|
||||
;
|
||||
|
||||
template extension
|
||||
@@ -86,8 +87,4 @@ if [ check-python-config ]
|
||||
:
|
||||
debug release
|
||||
;
|
||||
|
||||
install python lib
|
||||
: <dll>boost_python <lib>boost_python
|
||||
;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -77,7 +77,7 @@
|
||||
library, but if multiple Boost.Python extension modules are used
|
||||
together, it will prevent sharing of types across extension modules, and
|
||||
consume extra code space. To build <code>boost_python</code>, use <a
|
||||
href="../../../tools/build/v1/build_system.htm">Boost.Build</a> in the usual way
|
||||
href="../../../tools/build/index.html">Boost.Build</a> in the usual way
|
||||
from the <code>libs/python/build</code> subdirectory of your boost
|
||||
installation (if you have already built boost from the top level this may
|
||||
have no effect, since the work is already done).</p>
|
||||
@@ -249,7 +249,7 @@
|
||||
<blockquote>
|
||||
<pre>
|
||||
bjam -sTOOLS=<i><a href=
|
||||
"../../../more/getting_started.html#Tools">toolset</a></i> test
|
||||
"../../../tools/build/index.html#Tools">toolset</a></i> test
|
||||
</pre>
|
||||
</blockquote>
|
||||
This will update all of the Boost.Python v1 test and example targets. The
|
||||
@@ -259,7 +259,7 @@ bjam -sTOOLS=<i><a href=
|
||||
<blockquote>
|
||||
<pre>
|
||||
bjam -sTOOLS=<i><a href=
|
||||
"../../../more/getting_started.html#Tools">toolset</a></i> -sPYTHON_TEST_ARGS=-v test
|
||||
"../../../tools/build/index.html#Tools">toolset</a></i> -sPYTHON_TEST_ARGS=-v test
|
||||
</pre>
|
||||
</blockquote>
|
||||
which will print each test's Python code with the expected output as it
|
||||
@@ -286,11 +286,11 @@ edit the line which reads
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
boost-build ../../../tools/build/v1 ;
|
||||
boost-build ../../../tools/build ;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
so that the path refers to the <code>tools/build/v1</code> subdirectory
|
||||
so that the path refers to the <code>tools/build</code> subdirectory
|
||||
of your Boost installation.
|
||||
|
||||
|
||||
@@ -311,10 +311,10 @@ so that the path refers to the root directory of your Boost installation.
|
||||
|
||||
<h2><a name="variants">Build Variants</a></h2>
|
||||
Three <a href=
|
||||
"../../../tools/build/v1/build_system.htm#variants">variant</a>
|
||||
"../../../tools/build/build_system.htm#variants">variant</a>
|
||||
configurations of all python-related targets are supported, and can be
|
||||
selected by setting the <code><a href=
|
||||
"../../../tools/build/v1/build_system.htm#user_globals">BUILD</a></code>
|
||||
"../../../tools/build/build_system.htm#user_globals">BUILD</a></code>
|
||||
variable:
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -73,14 +73,6 @@
|
||||
|
||||
<dt><a href="v2/reference.html">Reference Manual</a></dt>
|
||||
|
||||
<dt>Suites:</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="v2/pickle.html">Pickle</a></li>
|
||||
<li><a href="v2/indexing.html">Indexing</a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
<dt><a href="v2/configuration.html">Configuration Information</a></dt>
|
||||
|
||||
<dt><a href="v2/platforms.html">Known Working Platforms and
|
||||
@@ -122,7 +114,7 @@
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p><i>© Copyright <a href="../../../people/dave_abrahams.htm">Dave
|
||||
<p><i>© Copyright <a href="../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002-2003. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams and Brett Calcott 2003. See
|
||||
accompanying <a class="reference" href="../../../LICENSE_1_0.txt">license</a> for terms of use.</td>
|
||||
accompanying <a class="reference" href="../../../LICENSE">license</a> for terms of use.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -9,7 +9,7 @@ __ ../../../index.htm
|
||||
|
||||
.. _`Boost.Python`: index.html
|
||||
|
||||
.. _license: ../../../LICENSE_1_0.txt
|
||||
.. _license: ../../../LICENSE
|
||||
|
||||
|
||||
-------------------------------------------------------
|
||||
|
||||
@@ -108,7 +108,7 @@ BOOST_PYTHON_MODULE(test)
|
||||
<dd><a href="mailto:Gottfried.Ganssauge-at-haufe.de">Gottfried
|
||||
Ganßauge</a> has contributed <a href=
|
||||
"v2/opaque_pointer_converter.html">opaque pointer support</a>.<br>
|
||||
<a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de Oliveira</a>
|
||||
<a href="nicodemus-at-globalite.com.br">Bruno da Silva de Oliveira</a>
|
||||
has contributed the exciting <a href="../pyste/index.html">Pyste</a>
|
||||
("Pie-steh") package.</dd>
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</table>
|
||||
<p>
|
||||
It was mentioned in passing in the previous section that
|
||||
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt>
|
||||
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>
|
||||
can also be used for overloaded functions and member functions with a
|
||||
common sequence of initial arguments. Here is an example:</p>
|
||||
<code><pre>
|
||||
|
||||
@@ -32,17 +32,15 @@ with every boost distribution: <b>bjam</b>.</p>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/lens.gif"></img> <b>Building without bjam</b><br><br>
|
||||
|
||||
Besides bjam, there are of course other ways to get your module built.
|
||||
What's written here should not be taken as "the one and only way".
|
||||
There are of course other build tools apart from <tt>bjam</tt>.
|
||||
|
||||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from people
|
||||
who had to use a different tool.
|
||||
</td>
|
||||
<p><img src="theme/lens.gif"></img> <b>Building without bjam</b><br>
|
||||
<br>
|
||||
Besides bjam, there are of course other ways to get your module built.
|
||||
What's written here should not be taken as "the one and only way".
|
||||
There are of course other build tools apart from <tt>bjam</tt>. </p>
|
||||
<p>Take note however that the preferred build tool for Boost.Python is <tt>bjam</tt>.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from
|
||||
people who had to use a different tool<tt></tt>.</p></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
|
||||
@@ -1,210 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Creating Packages</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="general_techniques.html">
|
||||
<link rel="next" href="extending_wrapped_objects_in_python.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Creating Packages</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="general_techniques.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="extending_wrapped_objects_in_python.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
A Python package is a collection of modules that provide to the user a certain
|
||||
functionality. If you're not familiar on how to create packages, a good
|
||||
introduction to them is provided in the
|
||||
<a href="http://www.python.org/doc/current/tut/node8.html">
|
||||
Python Tutorial</a>.</p>
|
||||
<p>
|
||||
But we are wrapping C++ code, using Boost.Python. How can we provide a nice
|
||||
package interface to our users? To better explain some concepts, let's work
|
||||
with an example.</p>
|
||||
<p>
|
||||
We have a C++ library that works with sounds: reading and writing various
|
||||
formats, applying filters to the sound data, etc. It is named (conveniently)
|
||||
<tt>sounds</tt>. Our library already has a neat C++ namespace hierarchy, like so: </p>
|
||||
<code><pre>
|
||||
<span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core
|
||||
</span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>io
|
||||
</span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>filters
|
||||
</span></pre></code>
|
||||
<p>
|
||||
We would like to present this same hierarchy to the Python user, allowing him
|
||||
to write code like this:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters
|
||||
</span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(...) </span>##<span class=identifier>echo </span><span class=identifier>is </span><span class=identifier>a </span><span class=identifier>C</span><span class=special>++ </span><span class=identifier>function
|
||||
</span></pre></code>
|
||||
<p>
|
||||
The first step is to write the wrapping code. We have to export each module
|
||||
separately with Boost.Python, like this:</p>
|
||||
<code><pre>
|
||||
<span class=comment>/* file core.cpp */
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>core</span><span class=special>)
|
||||
{
|
||||
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core </span><span class=keyword>namespace </span><span class=special>*/
|
||||
...
|
||||
}
|
||||
|
||||
/* </span><span class=identifier>file </span><span class=identifier>io</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>io</span><span class=special>)
|
||||
{
|
||||
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>io </span><span class=keyword>namespace </span><span class=special>*/
|
||||
...
|
||||
}
|
||||
|
||||
/* </span><span class=identifier>file </span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>filters</span><span class=special>)
|
||||
{
|
||||
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>filters </span><span class=keyword>namespace </span><span class=special>*/
|
||||
...
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Compiling these files will generate the following Python extensions:
|
||||
<tt>core.pyd</tt>, <tt>io.pyd</tt> and <tt>filters.pyd</tt>.</p>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/note.gif"></img> The extension <tt>.pyd</tt> is used for python extension modules, which
|
||||
are just shared libraries. Using the default for your system, like <tt>.so</tt> for
|
||||
Unix and <tt>.dll</tt> for Windows, works just as well. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Now, we create this directory structure for our Python package:</p>
|
||||
<code><pre>
|
||||
sounds/
|
||||
__init__.py
|
||||
core.pyd
|
||||
filters.pyd
|
||||
io.pyd
|
||||
</pre></code><p>
|
||||
The file <tt>__init__.py</tt> is what tells Python that the directory <tt>sounds/</tt> is
|
||||
actually a Python package. It can be a empty file, but can also perform some
|
||||
magic, that will be shown later. </p>
|
||||
<p>
|
||||
Now our package is ready. All the user has to do is put <tt>sounds</tt> into his
|
||||
<a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000">
|
||||
PYTHONPATH</a> and fire up the interpreter:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>io
|
||||
</span><span class=special>>>> </span><span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters
|
||||
</span><span class=special>>>> </span><span class=identifier>sound </span><span class=special>= </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>io</span><span class=special>.</span><span class=identifier>open</span><span class=special>(</span><span class=literal>'file.mp3'</span><span class=special>)
|
||||
>>> </span><span class=identifier>new_sound </span><span class=special>= </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(</span><span class=identifier>sound</span><span class=special>, </span><span class=number>1.0</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Nice heh? </p>
|
||||
<p>
|
||||
This is the simplest way to create hierarchies of packages, but it is not very
|
||||
flexible. What if we want to add a <i>pure</i> Python function to the filters
|
||||
package, for instance, one that applies 3 filters in a sound object at once?
|
||||
Sure, you can do this in C++ and export it, but why not do so in Python? You
|
||||
don't have to recompile the extension modules, plus it will be easier to write
|
||||
it.</p>
|
||||
<p>
|
||||
If we want this flexibility, we will have to complicate our package hierarchy a
|
||||
little. First, we will have to change the name of the extension modules:</p>
|
||||
<code><pre>
|
||||
<span class=comment>/* file core.cpp */
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_core</span><span class=special>)
|
||||
{
|
||||
...
|
||||
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core </span><span class=keyword>namespace </span><span class=special>*/
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Note that we added an underscore to the module name. The filename will have to
|
||||
be changed to <tt>_core.pyd</tt> as well, and we do the same to the other extension modules.
|
||||
Now, we change our package hierarchy like so:</p>
|
||||
<code><pre>
|
||||
sounds/
|
||||
__init__.py
|
||||
core/
|
||||
__init__.py
|
||||
_core.pyd
|
||||
filters/
|
||||
__init__.py
|
||||
_filters.pyd
|
||||
io/
|
||||
__init__.py
|
||||
_io.pyd
|
||||
</pre></code><p>
|
||||
Note that we created a directory for each extension module, and added a
|
||||
__init__.py to each one. But if we leave it that way, the user will have to
|
||||
access the functions in the core module with this syntax: </p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>core</span><span class=special>.</span><span class=identifier>_core
|
||||
</span><span class=special>>>> </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>core</span><span class=special>.</span><span class=identifier>_core</span><span class=special>.</span><span class=identifier>foo</span><span class=special>(...)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
which is not what we want. But here enters the <tt>__init__.py</tt> magic: everything
|
||||
that is brought to the <tt>__init__.py</tt> namespace can be accessed directly by the
|
||||
user. So, all we have to do is bring the entire namespace from <tt>_core.pyd</tt>
|
||||
to <tt>core/__init__.py</tt>. So add this line of code to <tt>sounds/core/__init__.py</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>from </span><span class=identifier>_core </span><span class=identifier>import </span><span class=special>*
|
||||
</span></pre></code>
|
||||
<p>
|
||||
We do the same for the other packages. Now the user accesses the functions and
|
||||
classes in the extension modules like before:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters
|
||||
</span><span class=special>>>> </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(...)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
with the additional benefit that we can easily add pure Python functions to
|
||||
any module, in a way that the user can't tell the difference between a C++
|
||||
function and a Python function. Let's add a <i>pure</i> Python function,
|
||||
<tt>echo_noise</tt>, to the <tt>filters</tt> package. This function applies both the
|
||||
<tt>echo</tt> and <tt>noise</tt> filters in sequence in the given <tt>sound</tt> object. We
|
||||
create a file named <tt>sounds/filters/echo_noise.py</tt> and code our function:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>import </span><span class=identifier>_filters
|
||||
</span><span class=identifier>def </span><span class=identifier>echo_noise</span><span class=special>(</span><span class=identifier>sound</span><span class=special>):
|
||||
</span><span class=identifier>s </span><span class=special>= </span><span class=identifier>_filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(</span><span class=identifier>sound</span><span class=special>)
|
||||
</span><span class=identifier>s </span><span class=special>= </span><span class=identifier>_filters</span><span class=special>.</span><span class=identifier>noise</span><span class=special>(</span><span class=identifier>sound</span><span class=special>)
|
||||
</span><span class=keyword>return </span><span class=identifier>s
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Next, we add this line to <tt>sounds/filters/__init__.py</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>from </span><span class=identifier>echo_noise </span><span class=identifier>import </span><span class=identifier>echo_noise
|
||||
</span></pre></code>
|
||||
<p>
|
||||
And that's it. The user now accesses this function like any other function
|
||||
from the <tt>filters</tt> package:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters
|
||||
</span><span class=special>>>> </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo_noise</span><span class=special>(...)
|
||||
</span></pre></code>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="general_techniques.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="extending_wrapped_objects_in_python.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -93,7 +93,7 @@ arguments or overloads with a common sequence of initial arguments come
|
||||
into play. Another macro is provided to make this a breeze.</p>
|
||||
<p>
|
||||
Like <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>,
|
||||
<tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> may be used to automatically create
|
||||
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> may be used to automatically create
|
||||
the thin wrappers for wrapping member functions. Let's have an example:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>george
|
||||
|
||||
@@ -44,9 +44,10 @@ both Boost.Python's and Python's static link library.</p>
|
||||
Boost.Python's static link library comes in two variants. Both are located
|
||||
in Boost's <tt>/libs/python/build/bin-stage</tt> subdirectory. On Windows, the
|
||||
variants are called <tt>boost_python.lib</tt> (for release builds) and
|
||||
<tt>boost_python_debug.lib</tt> (for debugging). If you can't find the libraries,
|
||||
you probably haven't built Boost.Python yet. See <a href="../../building.html">
|
||||
Building and Testing</a> on how to do this.</p>
|
||||
<tt>boost_python_debug.lib</tt> (for debugging). If you can't find the
|
||||
libraries, you probably haven't built Boost.Python yet. See <a
|
||||
href="../../building.html">Building and Testing</a> on how to do
|
||||
this.</p>
|
||||
<p>
|
||||
Python's static link library can be found in the <tt>/libs</tt> subdirectory of
|
||||
your Python directory. On Windows it is called pythonXY.lib where X.Y is
|
||||
@@ -87,7 +88,7 @@ Py_Finalize</a>() to stop the interpreter and release its resources.</li></ol><p
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 Dirk Gerrits<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<title>Exception Translation</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="iterators.html">
|
||||
<link rel="next" href="general_techniques.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
@@ -21,7 +20,7 @@
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="general_techniques.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
@@ -48,7 +47,7 @@ Users may provide custom translation. Here's an example:</p>
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="general_techniques.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Extending Wrapped Objects in Python</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="creating_packages.html">
|
||||
<link rel="next" href="reducing_compiling_time.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Extending Wrapped Objects in Python</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="creating_packages.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="reducing_compiling_time.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Thanks to Python's flexibility, you can easily add new methods to a class,
|
||||
even after it was already created:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=keyword>class </span><span class=identifier>C</span><span class=special>(</span><span class=identifier>object</span><span class=special>): </span><span class=identifier>pass
|
||||
</span><span class=special>>>>
|
||||
>>> </span>##<span class=identifier>a </span><span class=identifier>regular </span><span class=identifier>function
|
||||
</span><span class=special>>>> </span><span class=identifier>def </span><span class=identifier>C_str</span><span class=special>(</span><span class=identifier>self</span><span class=special>): </span><span class=keyword>return </span><span class=literal>'A C instance!'
|
||||
</span><span class=special>>>>
|
||||
>>> </span>##<span class=identifier>now </span><span class=identifier>we </span><span class=identifier>turn </span><span class=identifier>it </span><span class=identifier>in </span><span class=identifier>a </span><span class=identifier>member </span><span class=identifier>function
|
||||
</span><span class=special>>>> </span><span class=identifier>C</span><span class=special>.</span><span class=identifier>__str__ </span><span class=special>= </span><span class=identifier>C_str
|
||||
</span><span class=special>>>>
|
||||
>>> </span><span class=identifier>c </span><span class=special>= </span><span class=identifier>C</span><span class=special>()
|
||||
>>> </span><span class=identifier>print </span><span class=identifier>c
|
||||
</span><span class=identifier>A </span><span class=identifier>C </span><span class=identifier>instance</span><span class=special>!
|
||||
>>> </span><span class=identifier>C_str</span><span class=special>(</span><span class=identifier>c</span><span class=special>)
|
||||
</span><span class=identifier>A </span><span class=identifier>C </span><span class=identifier>instance</span><span class=special>!
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Yes, Python rox. <img src="theme/smiley.gif"></img></p>
|
||||
<p>
|
||||
We can do the same with classes that were wrapped with Boost.Python. Suppose
|
||||
we have a class <tt>point</tt> in C++:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>class </span><span class=identifier>point </span><span class=special>{...};
|
||||
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>class_</span><span class=special><</span><span class=identifier>point</span><span class=special>>(</span><span class=string>"point"</span><span class=special>)...;
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
If we are using the technique from the previous session, <a href="creating_packages.html">
|
||||
|
||||
Creating Packages</a>, we can code directly into <tt>geom/__init__.py</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>from </span><span class=identifier>_geom </span><span class=identifier>import </span><span class=special>*
|
||||
|
||||
</span>##<span class=identifier>a </span><span class=identifier>regular </span><span class=identifier>function
|
||||
</span><span class=identifier>def </span><span class=identifier>point_str</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
|
||||
</span><span class=keyword>return </span><span class=identifier>str</span><span class=special>((</span><span class=identifier>self</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=identifier>y</span><span class=special>))
|
||||
|
||||
</span>##<span class=identifier>now </span><span class=identifier>we </span><span class=identifier>turn </span><span class=identifier>it </span><span class=identifier>into </span><span class=identifier>a </span><span class=identifier>member </span><span class=identifier>function
|
||||
</span><span class=identifier>point</span><span class=special>.</span><span class=identifier>__str__ </span><span class=special>= </span><span class=identifier>point_str
|
||||
</span></pre></code>
|
||||
<p>
|
||||
<b>All</b> point instances created from C++ will also have this member function!
|
||||
This technique has several advantages:</p>
|
||||
<ul><li>Cut down compile times to zero for these additional functions</li><li>Reduce the memory footprint to virtually zero</li><li>Minimize the need to recompile</li><li>Rapid prototyping (you can move the code to C++ if required without changing the interface)</li></ul><p>
|
||||
You can even add a little syntactic sugar with the use of metaclasses. Let's
|
||||
create a special metaclass that "injects" methods in other classes.</p>
|
||||
<code><pre>
|
||||
##<span class=identifier>The </span><span class=identifier>one </span><span class=identifier>Boost</span><span class=special>.</span><span class=identifier>Python </span><span class=identifier>uses </span><span class=keyword>for </span><span class=identifier>all </span><span class=identifier>wrapped </span><span class=identifier>classes</span><span class=special>.
|
||||
</span>##<span class=identifier>You </span><span class=identifier>can </span><span class=identifier>use </span><span class=identifier>here </span><span class=identifier>any </span><span class=keyword>class </span><span class=identifier>exported </span><span class=identifier>by </span><span class=identifier>Boost </span><span class=identifier>instead </span><span class=identifier>of </span><span class=string>"point"
|
||||
</span><span class=identifier>BoostPythonMetaclass </span><span class=special>= </span><span class=identifier>point</span><span class=special>.</span><span class=identifier>__class__
|
||||
|
||||
</span><span class=keyword>class </span><span class=identifier>injector</span><span class=special>(</span><span class=identifier>object</span><span class=special>):
|
||||
</span><span class=keyword>class </span><span class=identifier>__metaclass__</span><span class=special>(</span><span class=identifier>BoostPythonMetaclass</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=identifier>name</span><span class=special>, </span><span class=identifier>bases</span><span class=special>, </span><span class=identifier>dict</span><span class=special>):
|
||||
</span><span class=keyword>for </span><span class=identifier>b </span><span class=identifier>in </span><span class=identifier>bases</span><span class=special>:
|
||||
</span><span class=keyword>if </span><span class=identifier>type</span><span class=special>(</span><span class=identifier>b</span><span class=special>) </span><span class=keyword>not </span><span class=identifier>in </span><span class=special>(</span><span class=identifier>self</span><span class=special>, </span><span class=identifier>type</span><span class=special>):
|
||||
</span><span class=keyword>for </span><span class=identifier>k</span><span class=special>,</span><span class=identifier>v </span><span class=identifier>in </span><span class=identifier>dict</span><span class=special>.</span><span class=identifier>items</span><span class=special>():
|
||||
</span><span class=identifier>setattr</span><span class=special>(</span><span class=identifier>b</span><span class=special>,</span><span class=identifier>k</span><span class=special>,</span><span class=identifier>v</span><span class=special>)
|
||||
</span><span class=keyword>return </span><span class=identifier>type</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=identifier>name</span><span class=special>, </span><span class=identifier>bases</span><span class=special>, </span><span class=identifier>dict</span><span class=special>)
|
||||
|
||||
</span>##<span class=identifier>inject </span><span class=identifier>some </span><span class=identifier>methods </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>point </span><span class=identifier>foo
|
||||
</span><span class=keyword>class </span><span class=identifier>more_point</span><span class=special>(</span><span class=identifier>injector</span><span class=special>, </span><span class=identifier>point</span><span class=special>):
|
||||
</span><span class=identifier>def </span><span class=identifier>__repr__</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
|
||||
</span><span class=keyword>return </span><span class=literal>'Point(x=%s, y=%s)' </span><span class=special>% (</span><span class=identifier>self</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=identifier>y</span><span class=special>)
|
||||
</span><span class=identifier>def </span><span class=identifier>foo</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
|
||||
</span><span class=identifier>print </span><span class=literal>'foo!'
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Now let's see how it got:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>print </span><span class=identifier>point</span><span class=special>()
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=identifier>x</span><span class=special>=</span><span class=number>10</span><span class=special>, </span><span class=identifier>y</span><span class=special>=</span><span class=number>10</span><span class=special>)
|
||||
>>> </span><span class=identifier>point</span><span class=special>().</span><span class=identifier>foo</span><span class=special>()
|
||||
</span><span class=identifier>foo</span><span class=special>!
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Another useful idea is to replace constructors with factory functions:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>_point </span><span class=special>= </span><span class=identifier>point
|
||||
|
||||
</span><span class=identifier>def </span><span class=identifier>point</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=identifier>y</span><span class=special>=</span><span class=number>0</span><span class=special>):
|
||||
</span><span class=keyword>return </span><span class=identifier>_point</span><span class=special>(</span><span class=identifier>x</span><span class=special>, </span><span class=identifier>y</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
In this simple case there is not much gained, but for constructurs with
|
||||
many overloads and/or arguments this is often a great simplification, again
|
||||
with virtually zero memory footprint and zero compile-time overhead for
|
||||
the keyword support.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="creating_packages.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="reducing_compiling_time.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,43 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>General Techniques</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="exception_translation.html">
|
||||
<link rel="next" href="creating_packages.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>General Techniques</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="exception_translation.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="creating_packages.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Here are presented some useful techniques that you can use while wrapping code with Boost.Python.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="exception_translation.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="creating_packages.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -63,9 +63,9 @@ Besides bjam, there are of course other ways to get your module built.
|
||||
What's written here should not be taken as "the one and only way".
|
||||
There are of course other build tools apart from [^bjam].
|
||||
|
||||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from people
|
||||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from people
|
||||
who had to use a different tool.
|
||||
]
|
||||
|
||||
@@ -1010,7 +1010,7 @@ arguments or overloads with a common sequence of initial arguments come
|
||||
into play. Another macro is provided to make this a breeze.
|
||||
|
||||
Like [^BOOST_PYTHON_FUNCTION_OVERLOADS],
|
||||
[^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS] may be used to automatically create
|
||||
[^BOOST_PYTHON_FUNCTION_OVERLOADS] may be used to automatically create
|
||||
the thin wrappers for wrapping member functions. Let's have an example:
|
||||
|
||||
struct george
|
||||
@@ -1058,7 +1058,7 @@ Notice the use of [^init<...>] and [^optional<...>] to signify the default
|
||||
[page:1 Auto-Overloading]
|
||||
|
||||
It was mentioned in passing in the previous section that
|
||||
[^BOOST_PYTHON_FUNCTION_OVERLOADS] and [^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS]
|
||||
[^BOOST_PYTHON_FUNCTION_OVERLOADS] and [^BOOST_PYTHON_FUNCTION_OVERLOADS]
|
||||
can also be used for overloaded functions and member functions with a
|
||||
common sequence of initial arguments. Here is an example:
|
||||
|
||||
@@ -1698,7 +1698,7 @@ with an example.
|
||||
|
||||
We have a C++ library that works with sounds: reading and writing various
|
||||
formats, applying filters to the sound data, etc. It is named (conveniently)
|
||||
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
|
||||
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
|
||||
|
||||
sounds::core
|
||||
sounds::io
|
||||
@@ -1718,21 +1718,21 @@ separately with Boost.Python, like this:
|
||||
{
|
||||
/* export everything in the sounds::core namespace */
|
||||
...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* file io.cpp */
|
||||
BOOST_PYTHON_MODULE(io)
|
||||
{
|
||||
/* export everything in the sounds::io namespace */
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
/* file filters.cpp */
|
||||
BOOST_PYTHON_MODULE(filters)
|
||||
{
|
||||
/* export everything in the sounds::filters namespace */
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
Compiling these files will generate the following Python extensions:
|
||||
[^core.pyd], [^io.pyd] and [^filters.pyd].
|
||||
@@ -1753,7 +1753,7 @@ Now, we create this directory structure for our Python package:
|
||||
|
||||
The file [^__init__.py] is what tells Python that the directory [^sounds/] is
|
||||
actually a Python package. It can be a empty file, but can also perform some
|
||||
magic, that will be shown later.
|
||||
magic, that will be shown later.
|
||||
|
||||
Now our package is ready. All the user has to do is put [^sounds] into his
|
||||
[@http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000 PYTHONPATH] and fire up the interpreter:
|
||||
@@ -1763,7 +1763,7 @@ Now our package is ready. All the user has to do is put [^sounds] into his
|
||||
>>> sound = sounds.io.open('file.mp3')
|
||||
>>> new_sound = sounds.filters.echo(sound, 1.0)
|
||||
|
||||
Nice heh?
|
||||
Nice heh?
|
||||
|
||||
This is the simplest way to create hierarchies of packages, but it is not very
|
||||
flexible. What if we want to add a ['pure] Python function to the filters
|
||||
@@ -1780,7 +1780,7 @@ little. First, we will have to change the name of the extension modules:
|
||||
{
|
||||
...
|
||||
/* export everything in the sounds::core namespace */
|
||||
}
|
||||
}
|
||||
|
||||
Note that we added an underscore to the module name. The filename will have to
|
||||
be changed to [^_core.pyd] as well, and we do the same to the other extension modules.
|
||||
@@ -1802,7 +1802,7 @@ Now, we change our package hierarchy like so:
|
||||
|
||||
Note that we created a directory for each extension module, and added a
|
||||
__init__.py to each one. But if we leave it that way, the user will have to
|
||||
access the functions in the core module with this syntax:
|
||||
access the functions in the core module with this syntax:
|
||||
|
||||
>>> import sounds.core._core
|
||||
>>> sounds.core._core.foo(...)
|
||||
@@ -1854,7 +1854,7 @@ even after it was already created:
|
||||
>>> def C_str(self): return 'A C instance!'
|
||||
>>>
|
||||
>>> # now we turn it in a member function
|
||||
>>> C.__str__ = C_str
|
||||
>>> C.__str__ = C_str
|
||||
>>>
|
||||
>>> c = C()
|
||||
>>> print c
|
||||
@@ -1874,7 +1874,7 @@ we have a class [^point] in C++:
|
||||
class_<point>("point")...;
|
||||
}
|
||||
|
||||
If we are using the technique from the previous session, [@creating_packages.html
|
||||
If we are using the technique from the previous session, [@creating_packages.html
|
||||
Creating Packages], we can code directly into [^geom/__init__.py]:
|
||||
|
||||
from _geom import *
|
||||
@@ -1882,7 +1882,7 @@ Creating Packages], we can code directly into [^geom/__init__.py]:
|
||||
# a regular function
|
||||
def point_str(self):
|
||||
return str((self.x, self.y))
|
||||
|
||||
|
||||
# now we turn it into a member function
|
||||
point.__str__ = point_str
|
||||
|
||||
@@ -1897,9 +1897,9 @@ This technique has several advantages:
|
||||
You can even add a little syntactic sugar with the use of metaclasses. Let's
|
||||
create a special metaclass that "injects" methods in other classes.
|
||||
|
||||
# The one Boost.Python uses for all wrapped classes.
|
||||
# The one Boost.Python uses for all wrapped classes.
|
||||
# You can use here any class exported by Boost instead of "point"
|
||||
BoostPythonMetaclass = point.__class__
|
||||
BoostPythonMetaclass = point.__class__
|
||||
|
||||
class injector(object):
|
||||
class __metaclass__(BoostPythonMetaclass):
|
||||
@@ -1946,10 +1946,10 @@ class_ definitions in multiple files:
|
||||
/* file point.cpp */
|
||||
#include <point.h>
|
||||
#include <boost/python.hpp>
|
||||
|
||||
|
||||
void export_point()
|
||||
{
|
||||
class_<point>("point")...;
|
||||
class_<point>("point")...;
|
||||
}
|
||||
|
||||
/* file triangle.cpp */
|
||||
@@ -1962,11 +1962,11 @@ class_ definitions in multiple files:
|
||||
}
|
||||
|
||||
Now you create a file [^main.cpp], which contains the [^BOOST_PYTHON_MODULE]
|
||||
macro, and call the various export functions inside it.
|
||||
macro, and call the various export functions inside it.
|
||||
|
||||
void export_point();
|
||||
void export_triangle();
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(_geom)
|
||||
{
|
||||
export_point();
|
||||
@@ -1984,15 +1984,15 @@ usual approach:
|
||||
{
|
||||
class_<point>("point")...;
|
||||
class_<triangle>("triangle")...;
|
||||
}
|
||||
}
|
||||
|
||||
but the memory is kept under control.
|
||||
but the memory is kept under control.
|
||||
|
||||
This method is recommended too if you are developing the C++ library and
|
||||
exporting it to Python at the same time: changes in a class will only demand
|
||||
the compilation of a single cpp, instead of the entire wrapper code.
|
||||
|
||||
[blurb __note__ If you're exporting your classes with [@../../../pyste/index.html Pyste],
|
||||
[blurb __note__ If you're exporting your classes with [@../../../pyste/index.html Pyste],
|
||||
take a look at the [^--multiple] option, that generates the wrappers in
|
||||
various files as demonstrated here.]
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Reducing Compiling Time</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="extending_wrapped_objects_in_python.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Reducing Compiling Time</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
If you have ever exported a lot of classes, you know that it takes quite a good
|
||||
time to compile the Boost.Python wrappers. Plus the memory consumption can
|
||||
easily become too high. If this is causing you problems, you can split the
|
||||
class_ definitions in multiple files:</p>
|
||||
<code><pre>
|
||||
<span class=comment>/* file point.cpp */
|
||||
</span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>point</span><span class=special>.</span><span class=identifier>h</span><span class=special>>
|
||||
</span><span class=preprocessor>#include </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>hpp</span><span class=special>>
|
||||
|
||||
</span><span class=keyword>void </span><span class=identifier>export_point</span><span class=special>()
|
||||
{
|
||||
</span><span class=identifier>class_</span><span class=special><</span><span class=identifier>point</span><span class=special>>(</span><span class=string>"point"</span><span class=special>)...;
|
||||
}
|
||||
|
||||
/* </span><span class=identifier>file </span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
|
||||
</span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>h</span><span class=special>>
|
||||
</span><span class=preprocessor>#include </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>hpp</span><span class=special>>
|
||||
|
||||
</span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>()
|
||||
{
|
||||
</span><span class=identifier>class_</span><span class=special><</span><span class=identifier>triangle</span><span class=special>>(</span><span class=string>"triangle"</span><span class=special>)...;
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Now you create a file <tt>main.cpp</tt>, which contains the <tt>BOOST_PYTHON_MODULE</tt>
|
||||
macro, and call the various export functions inside it. </p>
|
||||
<code><pre>
|
||||
<span class=keyword>void </span><span class=identifier>export_point</span><span class=special>();
|
||||
</span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>();
|
||||
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>export_point</span><span class=special>();
|
||||
</span><span class=identifier>export_triangle</span><span class=special>();
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Compiling and linking together all this files produces the same result as the
|
||||
usual approach:</p>
|
||||
<code><pre>
|
||||
<span class=preprocessor>#include </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>hpp</span><span class=special>>
|
||||
</span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>point</span><span class=special>.</span><span class=identifier>h</span><span class=special>>
|
||||
</span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>h</span><span class=special>>
|
||||
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>class_</span><span class=special><</span><span class=identifier>point</span><span class=special>>(</span><span class=string>"point"</span><span class=special>)...;
|
||||
</span><span class=identifier>class_</span><span class=special><</span><span class=identifier>triangle</span><span class=special>>(</span><span class=string>"triangle"</span><span class=special>)...;
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
but the memory is kept under control. </p>
|
||||
<p>
|
||||
This method is recommended too if you are developing the C++ library and
|
||||
exporting it to Python at the same time: changes in a class will only demand
|
||||
the compilation of a single cpp, instead of the entire wrapper code.</p>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/note.gif"></img> If you're exporting your classes with <a href="../../../pyste/index.html">
|
||||
Pyste</a>,
|
||||
take a look at the <tt>--multiple</tt> option, that generates the wrappers in
|
||||
various files as demonstrated here. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/note.gif"></img> This method is useful too if you are getting the error message
|
||||
<i>"fatal error C1204:Compiler limit:internal structure overflow"</i> when compiling
|
||||
a large source file, as explained in the <a href="../../v2/faq.html#c1204">
|
||||
FAQ</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -145,13 +145,15 @@ previous section</a>: the aptly named <tt>object</tt>
|
||||
class and it's derivatives. What we haven't seen, is that they can be
|
||||
constructed from a <tt>handle</tt>. The following examples should illustrate this
|
||||
fact:</p>
|
||||
<code><pre>
|
||||
<code>
|
||||
<pre>
|
||||
<span class=identifier>handle</span><span class=special><> </span><span class=identifier>main_module</span><span class=special>(</span><span class=identifier>borrowed</span><span class=special>( </span><span class=identifier>PyImport_AddModule</span><span class=special>(</span><span class=string>"__main__"</span><span class=special>) ));
|
||||
</span><span class=identifier>dict </span><span class=identifier>main_namespace</span><span class=special>(</span><span class=identifier>handle</span><span class=special><>(</span><span class=identifier>borrowed</span><span class=special>( </span><span class=identifier>PyModule_GetDict</span><span class=special>(</span><span class=identifier>main_module</span><span class=special>.</span><span class=identifier>get</span><span class=special>()) )));
|
||||
</span><span class=identifier>handle</span><span class=special><>( </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=string>"result = 5 ** 2"</span><span class=special>, </span><span class=identifier>Py_file_input</span><span class=special>,
|
||||
</span><span class=identifier>main_namespace</span><span class=special>.</span><span class=identifier>ptr</span><span class=special>(), </span><span class=identifier>main_namespace</span><span class=special>.</span><span class=identifier>ptr</span><span class=special>()) );
|
||||
</span><span class=keyword>int </span><span class=identifier>five_squared </span><span class=special>= </span><span class=identifier>extract</span><span class=special><</span><span class=keyword>int</span><span class=special>>( </span><span class=identifier>main_namespace</span><span class=special>[</span><span class=string>"result"</span><span class=special>] );
|
||||
</span></pre></code>
|
||||
</span></pre>
|
||||
</code>
|
||||
<p>
|
||||
Here we create a dictionary object for the <tt>__main__</tt> module's namespace.
|
||||
Then we assign 5 squared to the result variable and read this variable from
|
||||
@@ -227,7 +229,7 @@ allow_null</a> function in the same way you'd use borrowed:</p>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 Dirk Gerrits<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
|
||||
@@ -145,26 +145,6 @@
|
||||
<a href="doc/exception_translation.html">Exception Translation</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L0">
|
||||
<a href="doc/general_techniques.html">General Techniques</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/creating_packages.html">Creating Packages</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/extending_wrapped_objects_in_python.html">Extending Wrapped Objects in Python</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/reducing_compiling_time.html">Reducing Compiling Time</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
|
||||
@@ -45,7 +45,7 @@ of work got done...
|
||||
<h3><a name="arity">Arbitrary Arity Support</a></h3>
|
||||
|
||||
I began using the <a
|
||||
href="../../../preprocessor/doc/index.html">Boost.Preprocessor</a>
|
||||
href="../../../preprocessor/doc/index.htm">Boost.Preprocessor</a>
|
||||
metaprogramming library to generate support for functions and member
|
||||
functions of arbitrary arity, which was, to say the least, quite an
|
||||
adventure. The feedback cycle resulting from my foray into
|
||||
|
||||
@@ -28,40 +28,50 @@
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p>Instances of a Dereferenceable type can be used like a pointer to access an lvalue.
|
||||
<p>Instances of a dereferenceable type can be used like a pointer to access an lvalue.
|
||||
|
||||
<h2><a name="concept-requirements"></a>Concept Requirements</h2>
|
||||
<h3><a name="Dereferenceable-concept"></a>Dereferenceable Concept</h3>
|
||||
|
||||
<p>In the table below, <code><b>T</b></code> is a model of
|
||||
Dereferenceable, and <code><b>x</b></code> denotes an object of
|
||||
type <code>T</code>. In addition, all pointers are Dereferenceable.
|
||||
<p>In the table below, <code><b>x</b></code> denotes an object whose
|
||||
type is a model of Dereferenceable.
|
||||
|
||||
<table summary="Dereferenceable expressions" border="1" cellpadding="5">
|
||||
|
||||
<tr>
|
||||
<td><b>Expression</b></td>
|
||||
<td><b>Requirements</b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top"><code>*x</code></td>
|
||||
<td>An lvalue
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
If <code><b>x</b></code> is not a pointer type, it also must satsify the following expression:
|
||||
|
||||
<table summary="Dereferenceable expressions" border="1" cellpadding="5">
|
||||
|
||||
<tr>
|
||||
<td><b>Expression</b></td>
|
||||
<td><b>Result</b></td>
|
||||
<td><b>Operational Semantics</b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><code>get_pointer(x)</code></td>
|
||||
<td>convertible to <code><a href="pointee.html#pointee-spec">pointee</a><T>::type*</code>
|
||||
<td valign="top"><code>x.get()</code></td>
|
||||
<td><code>&*x</code>, or a null pointer
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
18 December, 2003
|
||||
29 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002-2003. All Rights Reserved.</i>
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
<p>Permission to copy, use, modify, sell
|
||||
and distribute this software is granted provided this copyright notice appears
|
||||
|
||||
@@ -54,7 +54,7 @@ focused on reducing the support burden. In recent weeks, responding to
|
||||
requests for support, espcially surrounding building the library, had
|
||||
begun to impede progress on development. There was a major push to
|
||||
release a stable 1.28.0 of Boost, including documentation of <a
|
||||
href="../../../../tools/build/v1/build_system.htm">Boost.Build</a> and specific
|
||||
href="../../../../tools/build/index.html">Boost.Build</a> and specific
|
||||
<a href="../building.html">instructions</a> for building Boost.Python
|
||||
v1. The documentation for Boost.Python v2 was also updated as
|
||||
described <a href="#documentation">here</a>.
|
||||
@@ -70,7 +70,7 @@ described <a href="#documentation">here</a>.
|
||||
Martin Casado which uncovered the key mechanism required to allow
|
||||
shared libraries to use functions from the Python executable. The
|
||||
current solution used in Boost.Build relies on a <a
|
||||
href="../../../../tools/build/v1/gen_aix_import_file.py">Python
|
||||
href="../../../../tools/build/gen_aix_import_file.py">Python
|
||||
Script</a> as part of the build process. This is not a problem for
|
||||
Boost.Python, as Python will be available. However, the commands
|
||||
issued by the script are so simple that a 100%-pure-Boost.Jam
|
||||
@@ -84,7 +84,8 @@ described <a href="#documentation">here</a>.
|
||||
|
||||
Support for exposing C++ operators and functions as the corresponding
|
||||
Python special methods was added. Thinking that the Boost.Python
|
||||
v1 interface was a little too esoteric (especially the use of
|
||||
<a href="../special.html#numeric">v1 interface</a> was a little too
|
||||
esoteric (especially the use of
|
||||
<code>left_operand<...>/right_operand<...></code> for
|
||||
asymmetric operands), I introduced a simple form of <a
|
||||
href="http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html">expression
|
||||
@@ -154,7 +155,7 @@ This forced the exposure of the <a
|
||||
href="http://www.python.org/2.2/descrintro.html#property"><code>property</code></a>
|
||||
interface used internally to implement the data member exposure
|
||||
facility described in <a
|
||||
href="Mar2002.html#data_members">March</a>. Properties are an
|
||||
href="Mar2002#data_members">March</a>. Properties are an
|
||||
incredibly useful idiom, so it's good to be able to provide them
|
||||
at little new development cost.
|
||||
|
||||
@@ -211,7 +212,7 @@ Major updates were made to the following pages:
|
||||
|
||||
<blockquote>
|
||||
<dl>
|
||||
<dt><a href="call.html">call.html</a><dd> <dt>updated<dd>
|
||||
<dt><a href="call.html">call.html</a><dd> <dt><a href="updated">updated</a><dd>
|
||||
<dt><a href="class.html">class.html</a><dd>
|
||||
<dt><a href="reference.html">reference.html</a><dd>
|
||||
</dl>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
use the new preproccessor metaprogramming constructs and helping us to
|
||||
work around buggy and slow C++ preprocessors.</p>
|
||||
|
||||
<p><a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de
|
||||
<p><a href="nicodemus-at-globalite.com.br">Bruno da Silva de
|
||||
Oliveira</a> contributed the ingenious <a
|
||||
href="../../pyste/index.html">Pyste</a> ("Pie-Steh")
|
||||
code generator.
|
||||
|
||||
2267
doc/v2/containers.html
Executable file
2267
doc/v2/containers.html
Executable file
File diff suppressed because it is too large
Load Diff
438
doc/v2/faq.html
438
doc/v2/faq.html
@@ -58,25 +58,10 @@
|
||||
<dt><a href="#ownership">How can I wrap a function which needs to take
|
||||
ownership of a raw pointer?</a></dt>
|
||||
|
||||
<dt><a href="#slow_compilation">Compilation takes too much time and eats too much memory!
|
||||
<dt><a href="#slow_compilation">Compilation takes too much time and eats too much memory!
|
||||
What can I do to make it faster?</a></dt>
|
||||
|
||||
<dt><a href="#packages">How do I create sub-packages using Boost.Python?</a></dt>
|
||||
|
||||
<dt><a href="#msvcthrowbug"
|
||||
>error C2064: term does not evaluate to a function taking 2 arguments</a>
|
||||
</dt>
|
||||
|
||||
<dt><a href="#voidptr">How do I handle <tt>void *</tt> conversion?</a></dt>
|
||||
|
||||
<dt><a href="#custom_string"
|
||||
>How can I automatically convert my custom string type to
|
||||
and from a Python string?</a></dt>
|
||||
|
||||
<dt><a href="#topythonconversionfailed">Why is my automatic to-python conversion not being
|
||||
found?</a></dt>
|
||||
|
||||
<dt><a href="#threadsupport">Is Boost.Python thread-aware/compatible with multiple interpreters?</a></dt>
|
||||
|
||||
<dt><a href="#packages">How do I create sub-packages using Boost.Python?</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
@@ -102,7 +87,7 @@ And then:
|
||||
|
||||
<pre>
|
||||
>>> def hello(s):
|
||||
... print s
|
||||
... print s
|
||||
...
|
||||
>>> foo(hello)
|
||||
hello, world!
|
||||
@@ -134,7 +119,7 @@ hello, world!
|
||||
<h2><a name="dangling">I'm getting the "attempt to return dangling
|
||||
reference" error. What am I doing wrong?</a></h2>
|
||||
That exception is protecting you from causing a nasty crash. It usually
|
||||
happens in response to some code like this:
|
||||
happens in response to some code like this:
|
||||
<pre>
|
||||
period const& get_floating_frequency() const
|
||||
{
|
||||
@@ -142,7 +127,7 @@ period const& get_floating_frequency() const
|
||||
m_self,"get_floating_frequency");
|
||||
}
|
||||
</pre>
|
||||
And you get:
|
||||
And you get:
|
||||
<pre>
|
||||
ReferenceError: Attempt to return dangling reference to object of type:
|
||||
class period
|
||||
@@ -173,7 +158,7 @@ class period
|
||||
I have the choice of using copy_const_reference or
|
||||
return_internal_reference. Are there considerations that would lead me
|
||||
to prefer one over the other, such as size of generated code or memory
|
||||
overhead?</i>
|
||||
overhead?</i>
|
||||
|
||||
<p><b>A:</b> copy_const_reference will make an instance with storage
|
||||
for one of your objects, size = base_size + 12 * sizeof(double).
|
||||
@@ -195,7 +180,7 @@ class period
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Using the regular <code>class_<></code> wrapper:
|
||||
Using the regular <code>class_<></code> wrapper:
|
||||
<pre>
|
||||
class_<std::vector<double> >("std_vector_double")
|
||||
.def(...)
|
||||
@@ -204,13 +189,13 @@ class_<std::vector<double> >("std_vector_double")
|
||||
</pre>
|
||||
This can be moved to a template so that several types (double, int,
|
||||
long, etc.) can be wrapped with the same code. This technique is used
|
||||
in the file
|
||||
in the file
|
||||
|
||||
<blockquote>
|
||||
scitbx/include/scitbx/array_family/boost_python/flex_wrapper.h
|
||||
</blockquote>
|
||||
in the "scitbx" package. The file could easily be modified for
|
||||
wrapping std::vector<> instantiations.
|
||||
wrapping std::vector<> instantiations.
|
||||
|
||||
<p>This type of C++/Python binding is most suitable for containers
|
||||
that may contain a large number of elements (>10000).</p>
|
||||
@@ -218,19 +203,19 @@ class_<std::vector<double> >("std_vector_double")
|
||||
|
||||
<li>
|
||||
Using custom rvalue converters. Boost.Python "rvalue converters"
|
||||
match function signatures such as:
|
||||
match function signatures such as:
|
||||
<pre>
|
||||
void foo(std::vector<double> const& array); // pass by const-reference
|
||||
void foo(std::vector<double> array); // pass by value
|
||||
</pre>
|
||||
Some custom rvalue converters are implemented in the file
|
||||
Some custom rvalue converters are implemented in the file
|
||||
|
||||
<blockquote>
|
||||
scitbx/include/scitbx/boost_python/container_conversions.h
|
||||
</blockquote>
|
||||
This code can be used to convert from C++ container types such as
|
||||
std::vector<> or std::list<> to Python tuples and vice
|
||||
versa. A few simple examples can be found in the file
|
||||
versa. A few simple examples can be found in the file
|
||||
|
||||
<blockquote>
|
||||
scitbx/array_family/boost_python/regression_test_module.cpp
|
||||
@@ -245,7 +230,7 @@ void foo(std::vector<double> array); // pass by value
|
||||
rvalue converters that convert to a "math_array" type instead of tuples.
|
||||
This is currently not implemented but is possible within the framework of
|
||||
Boost.Python V2 as it will be released in the next couple of weeks. [ed.:
|
||||
this was posted on 2002/03/10]
|
||||
this was posted on 2002/03/10]
|
||||
|
||||
<p>It would also be useful to also have "custom lvalue converters" such
|
||||
as std::vector<> <-> Python list. These converters would
|
||||
@@ -260,7 +245,7 @@ void foo(std::vector<double>& array)
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
Python:
|
||||
Python:
|
||||
<pre>
|
||||
>>> l = [1, 2, 3]
|
||||
>>> foo(l)
|
||||
@@ -268,7 +253,7 @@ void foo(std::vector<double>& array)
|
||||
[2, 4, 6]
|
||||
</pre>
|
||||
Custom lvalue converters require changes to the Boost.Python core library
|
||||
and are currently not available.
|
||||
and are currently not available.
|
||||
|
||||
<p>P.S.:</p>
|
||||
|
||||
@@ -285,7 +270,7 @@ cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx co scitbx
|
||||
|
||||
<blockquote>
|
||||
<b>Q:</b> <i>I get this error message when compiling a large source
|
||||
file. What can I do?</i>
|
||||
file. What can I do?</i>
|
||||
|
||||
<p><b>A:</b> You have two choices:</p>
|
||||
|
||||
@@ -293,7 +278,7 @@ cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx co scitbx
|
||||
<li>Upgrade your compiler (preferred)</li>
|
||||
|
||||
<li>
|
||||
Break your source file up into multiple translation units.
|
||||
Break your source file up into multiple translation units.
|
||||
|
||||
<p><code><b>my_module.cpp</b></code>:</p>
|
||||
<pre>
|
||||
@@ -307,7 +292,7 @@ BOOST_PYTHON_MODULE(my_module)
|
||||
more_of_my_module();
|
||||
}
|
||||
</pre>
|
||||
<code><b>more_of_my_module.cpp</b></code>:
|
||||
<code><b>more_of_my_module.cpp</b></code>:
|
||||
<pre>
|
||||
void more_of_my_module()
|
||||
{
|
||||
@@ -321,7 +306,7 @@ void more_of_my_module()
|
||||
can always pass a reference to the <code>class_</code> object to a
|
||||
function in another source file, and call some of its member
|
||||
functions (e.g. <code>.def(...)</code>) in the auxilliary source
|
||||
file:
|
||||
file:
|
||||
|
||||
<p><code><b>more_of_my_class.cpp</b></code>:</p>
|
||||
<pre>
|
||||
@@ -352,7 +337,7 @@ void more_of_my_class(class<my_class>& x)
|
||||
library that is under test, given that python code is minimal and
|
||||
boost::python either works or it doesn't. (ie. While errors can occur
|
||||
when the wrapping method is invalid, most errors are caught by the
|
||||
compiler ;-).
|
||||
compiler ;-).
|
||||
|
||||
<p>The basic steps required to initiate a gdb session to debug a c++
|
||||
library via python are shown here. Note, however that you should start
|
||||
@@ -383,69 +368,20 @@ Current language: auto; currently c++
|
||||
solid and "just works" without requiring any special tricks from the
|
||||
user.</p>
|
||||
|
||||
<p>Raoul Gough has provided the following for gdb on Windows:</p>
|
||||
|
||||
<blockquote>
|
||||
|
||||
<p>gdb support for Windows DLLs has improved lately, so it is
|
||||
now possible to debug Python extensions using a few
|
||||
tricks. Firstly, you will need an up-to-date gdb with support
|
||||
for minimal symbol extraction from a DLL. Any gdb from version 6
|
||||
onwards, or Cygwin gdb-20030214-1 and onwards should do. A
|
||||
suitable release will have a section in the gdb.info file under
|
||||
Configuration – Native – Cygwin Native –
|
||||
Non-debug DLL symbols. Refer to that info section for more
|
||||
details of the procedures outlined here.</p>
|
||||
|
||||
<p>Secondly, it seems necessary to set a breakpoint in the
|
||||
Python interpreter, rather than using ^C to break execution. A
|
||||
good place to set this breakpoint is PyOS_Readline, which will
|
||||
stop execution immediately before reading each interactive
|
||||
Python command. You have to let Python start once under the
|
||||
debugger, so that it loads its own DLL, before you can set the
|
||||
breakpoint:</p>
|
||||
|
||||
<p>
|
||||
<pre>
|
||||
$ gdb python
|
||||
GNU gdb 2003-09-02-cvs (cygwin-special)
|
||||
[...]
|
||||
|
||||
(gdb) run
|
||||
Starting program: /cygdrive/c/Python22/python.exe
|
||||
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> ^Z
|
||||
|
||||
|
||||
Program exited normally.
|
||||
(gdb) break *&PyOS_Readline
|
||||
Breakpoint 1 at 0x1e04eff0
|
||||
(gdb) run
|
||||
Starting program: /cygdrive/c/Python22/python.exe
|
||||
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
|
||||
Breakpoint 1, 0x1e04eff0 in python22!PyOS_Readline ()
|
||||
from /cygdrive/c/WINNT/system32/python22.dll
|
||||
(gdb) cont
|
||||
Continuing.
|
||||
>>> from my_ext import *
|
||||
|
||||
Breakpoint 1, 0x1e04eff0 in python22!PyOS_Readline ()
|
||||
from /cygdrive/c/WINNT/system32/python22.dll
|
||||
(gdb) # my_ext now loaded (with any debugging symbols it contains)
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Unfortunately for Cygwin and MinGW users, as of this writing gdb on
|
||||
Windows has a very hard time dealing with shared libraries, which could
|
||||
make Greg's approach next to useless for you. My best advice for you is
|
||||
to use Metrowerks C++ for compiler conformance and Microsoft Visual
|
||||
Studio as a debugger when you need one.</p>
|
||||
|
||||
<h3>Debugging extensions through Boost.Build</h3>
|
||||
If you are launching your extension module tests with <a href=
|
||||
"../../../../tools/build/v1/build_system.htm">Boost.Build</a> using the
|
||||
"../../../tools/build">Boost.Build</a> using the
|
||||
<code>boost-python-runtest</code> rule, you can ask it to launch your
|
||||
debugger for you by adding "--debugger=<i>debugger</i>" to your bjam
|
||||
command-line:
|
||||
debugger for you by adding "-sPYTHON_LAUNCH=<i>debugger</i>" to your bjam
|
||||
command-line:
|
||||
<pre>
|
||||
bjam -sTOOLS=vc7.1 "--debugger=devenv /debugexe" test
|
||||
bjam -sTOOLS=metrowerks "-sPYTHON_LAUNCH=devenv /debugexe" test
|
||||
bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
|
||||
</pre>
|
||||
It can also be extremely useful to add the <code>-d+2</code> option when
|
||||
@@ -453,7 +389,7 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
|
||||
commands it uses to invoke it. This will invariably involve setting up
|
||||
PYTHONPATH and other important environment variables such as
|
||||
LD_LIBRARY_PATH which may be needed by your debugger in order to get
|
||||
things to work right.
|
||||
things to work right.
|
||||
<hr>
|
||||
|
||||
<h2><a name="imul"></a>Why doesn't my <code>*=</code> operator work?</h2>
|
||||
@@ -464,7 +400,7 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
|
||||
<i>operator. It always tells me "can't multiply sequence with non int
|
||||
type". If I use</i> <code>p1.__imul__(p2)</code> <i>instead of</i>
|
||||
<code>p1 *= p2</code><i>, it successfully executes my code. What's
|
||||
wrong with me?</i>
|
||||
wrong with me?</i>
|
||||
|
||||
<p><b>A:</b> There's nothing wrong with you. This is a bug in Python
|
||||
2.2. You can see the same effect in Pure Python (you can learn a lot
|
||||
@@ -485,54 +421,24 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
|
||||
|
||||
<h2><a name="macosx"></a>Does Boost.Python work with Mac OS X?</h2>
|
||||
|
||||
It is known to work under 10.2.8 and 10.3 using
|
||||
Apple's gcc 3.3 compiler:
|
||||
<pre>gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1493)</pre>
|
||||
Under 10.2.8 get the August 2003 gcc update (free at
|
||||
<a href="http://connect.apple.com/">http://connect.apple.com/</a>).
|
||||
Under 10.3 get the Xcode Tools v1.0 (also free).
|
||||
<p>
|
||||
Python 2.3 is required. The Python that ships with 10.3 is
|
||||
fine. Under 10.2.8 use these commands to install Python
|
||||
as a framework:
|
||||
<pre>./configure --enable-framework
|
||||
make
|
||||
make frameworkinstall</pre>
|
||||
The last command requires root privileges because the target
|
||||
directory is
|
||||
<tt>/Library/Frameworks/Python.framework/Versions/2.3</tt>.
|
||||
However, the installation does not interfere with the Python
|
||||
version that ships with 10.2.8.
|
||||
<p>
|
||||
It is also crucial to increase the <tt>stacksize</tt> before
|
||||
starting compilations, e.g.:
|
||||
<pre>limit stacksize 8192k</pre>
|
||||
If the <tt>stacksize</tt> is too small the build might crash with
|
||||
internal compiler errors.
|
||||
<p>
|
||||
Sometimes Apple's compiler exhibits a bug by printing an error
|
||||
like the following while compiling a
|
||||
<tt>boost::python::class_<your_type></tt>
|
||||
template instantiation:
|
||||
<pre>.../inheritance.hpp:44: error: cannot
|
||||
dynamic_cast `p' (of type `struct cctbx::boost_python::<unnamed>::add_pair*
|
||||
') to type `void*' (source type is not polymorphic)</pre>
|
||||
<blockquote>
|
||||
<p>The short answer: as of January 2003, unfortunately not.</p>
|
||||
|
||||
We do not know a general workaround, but if the definition of
|
||||
<tt>your_type</tt> can be modified the following was found
|
||||
to work in all cases encountered so far:<pre>struct your_type
|
||||
{
|
||||
// before defining any member data
|
||||
#if defined(__MACH__) && defined(__APPLE_CC__) && __APPLE_CC__ == 1493
|
||||
bool dummy_;
|
||||
#endif
|
||||
// now your member data, e.g.
|
||||
double x;
|
||||
int j;
|
||||
// etc.
|
||||
};</pre>
|
||||
<p>The longer answer: using Mac OS 10.2.3 with the December Developer's
|
||||
Kit, Python 2.3a1, and bjam's darwin-tools.jam, Boost.Python compiles
|
||||
fine, including the examples. However, there are problems at runtime
|
||||
(see <a href=
|
||||
"http://mail.python.org/pipermail/c++-sig/2003-January/003267.html">http://mail.python.org/pipermail/c++-sig/2003-January/003267.html</a>).
|
||||
Solutions are currently unknown.</p>
|
||||
|
||||
<p>It is known that under certain circumstances objects are
|
||||
double-destructed. See <a href=
|
||||
"http://mail.python.org/pipermail/c++-sig/2003-January/003278.html">http://mail.python.org/pipermail/c++-sig/2003-January/003278.html</a>
|
||||
for details. It is not clear however if this problem is related to the
|
||||
Boost.Python runtime issues.</p>
|
||||
</blockquote>
|
||||
<hr>
|
||||
|
||||
<h2><a name="xref">How can I find the existing PyObject that holds a C++
|
||||
object?</a></h2>
|
||||
|
||||
@@ -544,7 +450,7 @@ make frameworkinstall</pre>
|
||||
with virtual functions. If you make a wrapper class with an initial
|
||||
PyObject* constructor argument and store that PyObject* as "self", you
|
||||
can get back to it by casting down to that wrapper type in a thin wrapper
|
||||
function. For example:
|
||||
function. For example:
|
||||
<pre>
|
||||
class X { X(int); virtual ~X(); ... };
|
||||
X* f(); // known to return Xs that are managed by Python objects
|
||||
@@ -577,7 +483,7 @@ class_<X,X_wrap>("X", init<int>())
|
||||
runtime check that it's valid. This approach also only works if the
|
||||
<code>X</code> object was constructed from Python, because
|
||||
<code>X</code>s constructed from C++ are of course never
|
||||
<code>X_wrap</code> objects.
|
||||
<code>X_wrap</code> objects.
|
||||
|
||||
<p>Another approach to this requires you to change your C++ code a bit;
|
||||
if that's an option for you it might be a better way to go. work we've
|
||||
@@ -596,13 +502,11 @@ class_<X,X_wrap>("X", init<int>())
|
||||
its containing Python object, and you could have your f_wrap function
|
||||
look in that mapping to get the Python object out.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2><a name="ownership">How can I wrap a function which needs to take
|
||||
ownership of a raw pointer?</a></h2>
|
||||
|
||||
<blockquote>
|
||||
<i>Part of an API that I'm wrapping goes something like this:</i>
|
||||
<i>Part of an API that I'm wrapping goes something like this:</i>
|
||||
<pre>
|
||||
struct A {}; struct B { void add( A* ); }
|
||||
where B::add() takes ownership of the pointer passed to it.
|
||||
@@ -613,9 +517,9 @@ where B::add() takes ownership of the pointer passed to it.
|
||||
a = mod.A()
|
||||
b = mod.B()
|
||||
b.add( a )
|
||||
del a
|
||||
del a
|
||||
del b
|
||||
# python interpreter crashes
|
||||
# python interpreter crashes
|
||||
# later due to memory corruption.
|
||||
</pre>
|
||||
|
||||
@@ -626,13 +530,13 @@ del b
|
||||
|
||||
<p><i>--Bruce Lowery</i></p>
|
||||
</blockquote>
|
||||
Yes: Make sure the C++ object is held by auto_ptr:
|
||||
Yes: Make sure the C++ object is held by auto_ptr:
|
||||
<pre>
|
||||
class_<A, std::auto_ptr<A> >("A")
|
||||
...
|
||||
;
|
||||
</pre>
|
||||
Then make a thin wrapper function which takes an auto_ptr parameter:
|
||||
Then make a thin wrapper function which takes an auto_ptr parameter:
|
||||
<pre>
|
||||
void b_insert(B& b, std::auto_ptr<A> a)
|
||||
{
|
||||
@@ -643,237 +547,26 @@ void b_insert(B& b, std::auto_ptr<A> a)
|
||||
Wrap that as B.add. Note that pointers returned via <code><a href=
|
||||
"manage_new_object.html#manage_new_object-spec">manage_new_object</a></code>
|
||||
will also be held by <code>auto_ptr</code>, so this transfer-of-ownership
|
||||
will also work correctly.
|
||||
will also work correctly.
|
||||
|
||||
<hr>
|
||||
<h2><a name="slow_compilation">Compilation takes too much time and eats too
|
||||
much memory! What can I do to make it faster?</a></h2>
|
||||
much memory! What can I do to make it faster?</a></h2>
|
||||
<p>
|
||||
Please refer to the <a href="../tutorial/doc/reducing_compiling_time.html"
|
||||
>Reducing Compiling Time</a> section in the tutorial.
|
||||
Please refer to the <a href="../tutorial/doc/reducing_compiling_time.html">Techniques</a>
|
||||
section in the tutorial.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
<h2><a name="packages">How do I create sub-packages using Boost.Python?</a></h2>
|
||||
|
||||
<h2><a name="packages">How do I create sub-packages using Boost.Python?</a></h2>
|
||||
<p>
|
||||
Please refer to the <a href="../tutorial/doc/creating_packages.html"
|
||||
>Creating Packages</a> section in the tutorial.
|
||||
In the <a href="../tutorial/doc/creating_packages.html">Techniques</a>
|
||||
section of the tutorial this topic is explored.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
<h2><a name="msvcthrowbug"></a>error C2064: term does
|
||||
not evaluate to a function taking 2 arguments</h2>
|
||||
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
|
||||
If you see Microsoft Visual C++ 7.1 (MS Visual Studio .NET 2003) issue
|
||||
an error message like the following it is most likely due to a bug
|
||||
in the compiler:
|
||||
<pre>boost\boost\python\detail\invoke.hpp(76):
|
||||
error C2064: term does not evaluate to a function taking 2 arguments"</pre>
|
||||
This message is triggered by code like the following:
|
||||
<pre>#include <boost/python.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
class FXThread
|
||||
{
|
||||
public:
|
||||
bool setAutoDelete(bool doso) throw();
|
||||
};
|
||||
|
||||
void Export_FXThread()
|
||||
{
|
||||
class_< FXThread >("FXThread")
|
||||
.def("setAutoDelete", &FXThread::setAutoDelete)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
The bug is related to the <code>throw()</code> modifier.
|
||||
As a workaround cast off the modifier. E.g.:
|
||||
<pre>
|
||||
.def("setAutoDelete", (bool (FXThread::*)(bool)) &FXThread::setAutoDelete)</pre>
|
||||
<p>(The bug has been reported to Microsoft.)</p>
|
||||
|
||||
<hr>
|
||||
<h2><a name="voidptr"></a>How do I handle <tt>void *</tt> conversion?</h2>
|
||||
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
|
||||
For several reasons Boost.Python does not support <tt>void *</tt> as
|
||||
an argument or as a return value. However, it is possible to wrap
|
||||
functions with <tt>void *</tt> arguments or return values using
|
||||
thin wrappers and the <i>opaque pointer</i> facility. E.g.:
|
||||
<pre>// Declare the following in each translation unit
|
||||
struct void_; // Deliberately do not define
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);
|
||||
|
||||
void *foo(int par1, void *par2);
|
||||
|
||||
void_ *foo_wrapper(int par1, void_ *par2)
|
||||
{
|
||||
return (void_ *) foo(par1, par2);
|
||||
}
|
||||
...
|
||||
BOOST_PYTHON_MODULE(bar)
|
||||
{
|
||||
def("foo", &foo_wrapper);
|
||||
}</pre>
|
||||
|
||||
<hr>
|
||||
<h2><a name="custom_string"></a>How can I automatically
|
||||
convert my custom string type to and from a Python string?</h2>
|
||||
<font size="-1"><i>Ralf W. Grosse-Kunstleve provides these
|
||||
notes:</i></font><p>
|
||||
Below is a small, self-contained demo extension module that shows
|
||||
how to do this. Here is the corresponding trivial test:
|
||||
<pre>import custom_string
|
||||
assert custom_string.hello() == "Hello world."
|
||||
assert custom_string.size("california") == 10</pre>
|
||||
|
||||
If you look at the code you will find:
|
||||
|
||||
<ul>
|
||||
<li>A custom <tt>to_python</tt> converter (easy):
|
||||
<tt>custom_string_to_python_str</tt>
|
||||
|
||||
<li>A custom lvalue converter (needs more code):
|
||||
<tt>custom_string_from_python_str</tt>
|
||||
</ul>
|
||||
|
||||
The custom converters are registered in the global Boost.Python
|
||||
registry near the top of the module initialization function. Once
|
||||
flow control has passed through the registration code the automatic
|
||||
conversions from and to Python strings will work in any module
|
||||
imported in the same process.
|
||||
|
||||
<pre>#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/to_python_converter.hpp>
|
||||
|
||||
namespace sandbox { namespace {
|
||||
|
||||
class custom_string
|
||||
{
|
||||
public:
|
||||
custom_string() {}
|
||||
custom_string(std::string const& value) : value_(value) {}
|
||||
std::string const& value() const { return value_; }
|
||||
private:
|
||||
std::string value_;
|
||||
};
|
||||
|
||||
struct custom_string_to_python_str
|
||||
{
|
||||
static PyObject* convert(custom_string const& s)
|
||||
{
|
||||
return boost::python::incref(boost::python::object(s.value()).ptr());
|
||||
}
|
||||
};
|
||||
|
||||
struct custom_string_from_python_str
|
||||
{
|
||||
custom_string_from_python_str()
|
||||
{
|
||||
boost::python::converter::registry::push_back(
|
||||
&convertible,
|
||||
&construct,
|
||||
boost::python::type_id<custom_string>());
|
||||
}
|
||||
|
||||
static void* convertible(PyObject* obj_ptr)
|
||||
{
|
||||
if (!PyString_Check(obj_ptr)) return 0;
|
||||
return obj_ptr;
|
||||
}
|
||||
|
||||
static void construct(
|
||||
PyObject* obj_ptr,
|
||||
boost::python::converter::rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
const char* value = PyString_AsString(obj_ptr);
|
||||
if (value == 0) boost::python::throw_error_already_set();
|
||||
void* storage = (
|
||||
(boost::python::converter::rvalue_from_python_storage<custom_string>*)
|
||||
data)->storage.bytes;
|
||||
new (storage) custom_string(value);
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
custom_string hello() { return custom_string("Hello world."); }
|
||||
|
||||
std::size_t size(custom_string const& s) { return s.value().size(); }
|
||||
|
||||
void init_module()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
boost::python::to_python_converter<
|
||||
custom_string,
|
||||
custom_string_to_python_str>();
|
||||
|
||||
custom_string_from_python_str();
|
||||
|
||||
def("hello", hello);
|
||||
def("size", size);
|
||||
}
|
||||
|
||||
}} // namespace sandbox::<anonymous>
|
||||
|
||||
BOOST_PYTHON_MODULE(custom_string)
|
||||
{
|
||||
sandbox::init_module();
|
||||
}</pre>
|
||||
|
||||
<hr>
|
||||
<h2><a name="topythonconversionfailed"></a
|
||||
>Why is my automatic to-python conversion not being found?</h2>
|
||||
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
|
||||
If you define custom converters similar to the ones
|
||||
shown above the <tt>def_readonly()</tt> and <tt>def_readwrite()</tt>
|
||||
member functions provided by <tt>boost::python::class_</tt> for
|
||||
direct access to your member data will not work as expected.
|
||||
This is because <tt>def_readonly("bar", &foo::bar)</tt> is
|
||||
equivalent to:
|
||||
|
||||
<pre>.add_property("bar", make_getter(&foo::bar, return_internal_reference()))</pre>
|
||||
|
||||
Similarly, <tt>def_readwrite("bar", &foo::bar)</tt> is
|
||||
equivalent to:
|
||||
|
||||
<pre>.add_property("bar", make_getter(&foo::bar, return_internal_reference()),
|
||||
make_setter(&foo::bar, return_internal_reference())</pre>
|
||||
|
||||
In order to define return value policies compatible with the
|
||||
custom conversions replace <tt>def_readonly()</tt> and
|
||||
<tt>def_readwrite()</tt> by <tt>add_property()</tt>. E.g.:
|
||||
|
||||
<pre>.add_property("bar", make_getter(&foo::bar, return_value_policy<return_by_value>()),
|
||||
make_setter(&foo::bar, return_value_policy<return_by_value>()))</pre>
|
||||
|
||||
<hr>
|
||||
<h2><a name="threadsupport"></a
|
||||
>Is Boost.Python thread-aware/compatible with multiple interpreters?</h2>
|
||||
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
|
||||
The quick answer to this is: no.</p>
|
||||
<p>
|
||||
The longer answer is that it can be patched to be so, but it's
|
||||
complex. You will need to add custom lock/unlock wrapping of every
|
||||
time your code enters Boost.Python (particularly every virtual
|
||||
function override) plus heavily modify
|
||||
<tt>boost/python/detail/invoke.hpp</tt> with custom unlock/lock
|
||||
wrapping of every time Boost.Python enters your code. You must
|
||||
furthermore take care to <i>not</i> unlock/lock when Boost.Python
|
||||
is invoking iterator changes via <tt>invoke.hpp</tt>.</p>
|
||||
<p>
|
||||
There is a patched <tt>invoke.hpp</tt> posted on the C++-SIG
|
||||
mailing list archives and you can find a real implementation of all
|
||||
the machinery necessary to fully implement this in the TnFOX
|
||||
project at <a href="http://sourceforge.net/projects/tnfox/"> this
|
||||
SourceForge project location</a>.</p>
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
28 January, 2004
|
||||
18 March, 2003
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
@@ -882,3 +575,4 @@ BOOST_PYTHON_MODULE(custom_string)
|
||||
Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -71,8 +71,9 @@ namespace boost { namespace python
|
||||
{
|
||||
template <class T>
|
||||
struct from_python : private <a href=
|
||||
"../../../utility/utility.htm#Class_noncopyable">boost::noncopyable</a> // Exposition only.
|
||||
// from_python<T> meets the NonCopyable requirements
|
||||
"../../../utility/utility.htm#Class noncopyable">boost::noncopyable</a> // Exposition only.
|
||||
// from_python<T> meets the <a href=
|
||||
"NonCopyable.html">NonCopyable</a> requirements
|
||||
{
|
||||
from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
|
||||
@@ -278,7 +278,7 @@
|
||||
std::vector interface]) classes (currently, this is the only predefined
|
||||
suite available). It provides all the policies required by the
|
||||
<tt>indexing_suite</tt>.
|
||||
</p>
|
||||
</p>
|
||||
<p>
|
||||
Example usage:
|
||||
</p>
|
||||
@@ -300,16 +300,16 @@
|
||||
<h2>
|
||||
<a name="indexing_suite_class"></a>indexing_suite class
|
||||
</h2>
|
||||
<h3>
|
||||
<br>
|
||||
<tt>indexing_suite<<br>
|
||||
class Container<br>
|
||||
, class DerivedPolicies<font color="#007F00"><br>
|
||||
</font></tt> <tt>,
|
||||
bool NoProxy<br>
|
||||
, class Element<br>
|
||||
, class Key<br>
|
||||
, class Index</tt>
|
||||
<h3>
|
||||
Class template<br>
|
||||
<tt>indexing_suite<<br>
|
||||
class <font color="#007F00">Container</font><br>
|
||||
, class <font color="#007F00">DerivedPolicies<br></font></tt> <tt>,
|
||||
bool <font color="#007F00">NoProxy</font><br>
|
||||
, bool <font color="#007F00">NoProxy</font>,<br>
|
||||
, class <font color="#007F00">Element</font><br>
|
||||
, class <font color="#007F00">Key</font><br>
|
||||
, class <font color="#007F00">Index</font></tt>
|
||||
</h3>
|
||||
<table width="100%" border="1">
|
||||
<tr>
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
class instance_holder : <a href="../../../utility/utility.htm#Class_noncopyable">noncopyable</a>
|
||||
class instance_holder : <a href="../../../utility/utility.htm#Class noncopyable">noncopyable</a>
|
||||
{
|
||||
public:
|
||||
// destructor
|
||||
|
||||
@@ -99,7 +99,7 @@ template <class F, class Policies, class Keywords, class Signature>
|
||||
arguments of the resulting function.
|
||||
<li>If <code>Signature</code>
|
||||
is supplied, it should be an instance of an <a
|
||||
href="../../../mpl/doc/ref/Sequence.html">MPL front-extensible
|
||||
href="../../mpl/doc/ref/Sequence.html">MPL front-extensible
|
||||
sequence</a> representing the function's return type followed by
|
||||
its argument types. Pass a <code>Signature</code> when wrapping
|
||||
function object types whose signatures can't be deduced, or when
|
||||
@@ -135,7 +135,7 @@ template <class ArgList, class Generator, class Policies>
|
||||
<dt><b>Requires:</b> <code>T</code> is a class type.
|
||||
<code>Policies</code> is a model of <a href=
|
||||
"CallPolicies.html">CallPolicies</a>. <code>ArgList</code> is an <a
|
||||
href="../../../mpl/doc/ref/Sequences.html">MPL sequence</a> of C++ argument
|
||||
href="../../../mpl/doc/Sequences.html">MPL sequence</a> of C++ argument
|
||||
types (<i>A1, A2,... AN</i>) such that if
|
||||
<code>a1, a2</code>... <code>aN</code> are objects of type
|
||||
<i>A1, A2,... AN</i> respectively, the expression <code>new
|
||||
|
||||
BIN
doc/v2/overview.png
Executable file
BIN
doc/v2/overview.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
@@ -27,15 +27,8 @@
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
Please see
|
||||
our <a
|
||||
href="http://boost.sourceforge.net/regression-logs">regression
|
||||
logs</a> for up-to-date information. Note that logs not marked
|
||||
otherwise reflect the CVS state, not the condition of the release.
|
||||
|
||||
<p>
|
||||
Earlier versions of <b>Boost.Python</b> have been successfully
|
||||
tested on the following platforms and compilers.
|
||||
<b>Boost.Python</b> has been successfully tested on the following
|
||||
platforms and compilers:
|
||||
|
||||
<dl class="page-index">
|
||||
<dt>Unix Platforms:</dt>
|
||||
|
||||
BIN
doc/v2/proxy.png
Executable file
BIN
doc/v2/proxy.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
doc/v2/proxy_detached.png
Executable file
BIN
doc/v2/proxy_detached.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -969,7 +969,7 @@
|
||||
<dl>
|
||||
<dt><a href="callbacks.html">Calling Python Functions and Methods</a></dt>
|
||||
<dt><a href="pickle.html">Pickle Support</a><br>
|
||||
<a href="indexing.html">Indexing Support</a></dt>
|
||||
<a href="containers.html">Indexing Support</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
|
||||
@@ -58,9 +58,10 @@
|
||||
void register_ptr_to_python()
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>P</code> is <a href="Dereferenceable.html#Dereferenceable-concept">Dereferenceable</a>.
|
||||
<dt><b>Requires:</b> <code>P</code> is the type of the smart pointer,
|
||||
for example <code>smart_ptr<X></code>.
|
||||
</dt>
|
||||
<dt><b>Effects:</b> Allows conversions to-python of <code>P</code>
|
||||
<dt><b>Effects:</b> Allows conversions to-python of <code>smart_ptr<X></code>
|
||||
instances.
|
||||
</dt>
|
||||
</dl>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a></td>
|
||||
|
||||
<td>A model of <a href=
|
||||
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>.</td>
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a>.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace boost { namespace python
|
||||
template <class T>
|
||||
struct to_python_value
|
||||
{
|
||||
typedef typename <a href="../../../type_traits/index.html#transformations">add_reference</a><
|
||||
typename <a href="../../../type_traits/index.html#transformations">add_const</a><T>::type
|
||||
typedef typename <a href="../../../type_traits/index.htm#transformations">add_reference</a><
|
||||
typename <a href="../../../type_traits/index.htm#transformations">add_const</a><T>::type
|
||||
>::type argument_type;
|
||||
|
||||
static bool convertible();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Copyright David Abrahams 2003. See accompanying LICENSE for terms
|
||||
# and conditions of use.
|
||||
|
||||
# Edit this path to point at the tools/build/v1 subdirectory of your
|
||||
# Edit this path to point at the tools/build subdirectory of your
|
||||
# Boost installation. Absolute paths work, too.
|
||||
boost-build ../../../tools/build/v1 ;
|
||||
boost-build ../../../tools/build ;
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
// See http://www.boost.org/libs/python for documentation.
|
||||
|
||||
#ifndef PYTHON_DWA2002810_HPP
|
||||
# define PYTHON_DWA2002810_HPP
|
||||
|
||||
# include <boost/python/args.hpp>
|
||||
# include <boost/python/args_fwd.hpp>
|
||||
# include <boost/python/back_reference.hpp>
|
||||
# include <boost/python/bases.hpp>
|
||||
# include <boost/python/borrowed.hpp>
|
||||
# include <boost/python/call.hpp>
|
||||
# include <boost/python/call_method.hpp>
|
||||
# include <boost/python/class.hpp>
|
||||
# include <boost/python/copy_const_reference.hpp>
|
||||
# include <boost/python/copy_non_const_reference.hpp>
|
||||
# include <boost/python/data_members.hpp>
|
||||
# include <boost/python/def.hpp>
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
# include <boost/python/dict.hpp>
|
||||
# include <boost/python/enum.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/exception_translator.hpp>
|
||||
# include <boost/python/extract.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/has_back_reference.hpp>
|
||||
# include <boost/python/implicit.hpp>
|
||||
# include <boost/python/init.hpp>
|
||||
# include <boost/python/instance_holder.hpp>
|
||||
# include <boost/python/iterator.hpp>
|
||||
# include <boost/python/list.hpp>
|
||||
# include <boost/python/long.hpp>
|
||||
# include <boost/python/lvalue_from_pytype.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/manage_new_object.hpp>
|
||||
# include <boost/python/module.hpp>
|
||||
# include <boost/python/numeric.hpp>
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/object_protocol.hpp>
|
||||
# include <boost/python/object_protocol_core.hpp>
|
||||
# include <boost/python/opaque_pointer_converter.hpp>
|
||||
# include <boost/python/operators.hpp>
|
||||
# include <boost/python/other.hpp>
|
||||
# include <boost/python/overloads.hpp>
|
||||
# include <boost/python/pointee.hpp>
|
||||
# include <boost/python/pure_virtual.hpp>
|
||||
# include <boost/python/ptr.hpp>
|
||||
# include <boost/python/reference_existing_object.hpp>
|
||||
# include <boost/python/register_ptr_to_python.hpp>
|
||||
# include <boost/python/return_arg.hpp>
|
||||
# include <boost/python/return_internal_reference.hpp>
|
||||
# include <boost/python/return_opaque_pointer.hpp>
|
||||
# include <boost/python/return_value_policy.hpp>
|
||||
# include <boost/python/scope.hpp>
|
||||
# include <boost/python/self.hpp>
|
||||
# include <boost/python/slice_nil.hpp>
|
||||
# include <boost/python/str.hpp>
|
||||
# include <boost/python/to_python_converter.hpp>
|
||||
# include <boost/python/to_python_indirect.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
# include <boost/python/tuple.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/with_custodian_and_ward.hpp>
|
||||
|
||||
#endif // PYTHON_DWA2002810_HPP
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_FROM_PYTHON_DWA2002128_HPP
|
||||
# define ARG_FROM_PYTHON_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/converter/arg_from_python.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
struct arg_from_python
|
||||
: converter::select_arg_from_python<T>::type
|
||||
{
|
||||
typedef typename converter::select_arg_from_python<T>::type base;
|
||||
arg_from_python(PyObject*);
|
||||
};
|
||||
|
||||
// specialization for PyObject*
|
||||
template <>
|
||||
struct arg_from_python<PyObject*>
|
||||
{
|
||||
typedef PyObject* result_type;
|
||||
|
||||
arg_from_python(PyObject* p) : m_source(p) {}
|
||||
bool convertible() const { return true; }
|
||||
PyObject* operator()() const { return m_source; }
|
||||
private:
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct arg_from_python<PyObject* const&>
|
||||
{
|
||||
typedef PyObject* const& result_type;
|
||||
|
||||
arg_from_python(PyObject* p) : m_source(p) {}
|
||||
bool convertible() const { return true; }
|
||||
PyObject*const& operator()() const { return m_source; }
|
||||
private:
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
inline arg_from_python<T>::arg_from_python(PyObject* source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ARG_FROM_PYTHON_DWA2002128_HPP
|
||||
@@ -1,175 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef KEYWORDS_DWA2002323_HPP
|
||||
# define KEYWORDS_DWA2002323_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/args_fwd.hpp>
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/detail/type_list.hpp>
|
||||
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
# include <boost/type_traits/remove_reference.hpp>
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/facilities/intercept.hpp>
|
||||
# include <boost/preprocessor/iteration/local.hpp>
|
||||
|
||||
# include <boost/python/detail/mpl_lambda.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
# include <boost/mpl/bool.hpp>
|
||||
|
||||
# include <cstddef>
|
||||
# include <algorithm>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
typedef detail::keywords<1> arg;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <std::size_t nkeywords>
|
||||
struct keywords_base
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords);
|
||||
|
||||
keyword_range range() const
|
||||
{
|
||||
return keyword_range(elements, elements + nkeywords);
|
||||
}
|
||||
|
||||
keyword elements[nkeywords];
|
||||
|
||||
keywords<nkeywords+1>
|
||||
operator,(arg const &k) const;
|
||||
|
||||
keywords<nkeywords + 1>
|
||||
operator,(char const *name) const;
|
||||
};
|
||||
|
||||
template <std::size_t nkeywords>
|
||||
struct keywords : keywords_base<nkeywords>
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct keywords<1> : keywords_base<1>
|
||||
{
|
||||
explicit keywords(char const *name)
|
||||
{
|
||||
elements[0].name = name;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
arg& operator=(T const& value)
|
||||
{
|
||||
object z(value);
|
||||
elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator detail::keyword const&() const
|
||||
{
|
||||
return elements[0];
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t nkeywords>
|
||||
inline
|
||||
keywords<nkeywords+1>
|
||||
keywords_base<nkeywords>::operator,(arg const &k) const
|
||||
{
|
||||
keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
|
||||
python::detail::keywords<nkeywords+1> res;
|
||||
std::copy(l.elements, l.elements+nkeywords, res.elements);
|
||||
res.elements[nkeywords] = k.elements[0];
|
||||
return res;
|
||||
}
|
||||
|
||||
template <std::size_t nkeywords>
|
||||
inline
|
||||
keywords<nkeywords + 1>
|
||||
keywords_base<nkeywords>::operator,(char const *name) const
|
||||
{
|
||||
return this->operator,(python::arg(name));
|
||||
}
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
struct is_keywords
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template<std::size_t nkeywords>
|
||||
struct is_keywords<keywords<nkeywords> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
template <class T>
|
||||
struct is_reference_to_keywords
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_ref = is_reference<T>::value);
|
||||
typedef typename remove_reference<T>::type deref;
|
||||
typedef typename remove_cv<deref>::type key_t;
|
||||
BOOST_STATIC_CONSTANT(bool, is_key = is_keywords<key_t>::value);
|
||||
BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key));
|
||||
|
||||
typedef mpl::bool_<value> type;
|
||||
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
|
||||
};
|
||||
# else
|
||||
typedef char (&yes_keywords_t)[1];
|
||||
typedef char (&no_keywords_t)[2];
|
||||
|
||||
no_keywords_t is_keywords_test(...);
|
||||
|
||||
template<std::size_t nkeywords>
|
||||
yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords>&));
|
||||
|
||||
template<std::size_t nkeywords>
|
||||
yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords> const&));
|
||||
|
||||
template<typename T>
|
||||
class is_reference_to_keywords
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_keywords_test( (void (*)(T))0 ))
|
||||
== sizeof(detail::yes_keywords_t)));
|
||||
|
||||
typedef mpl::bool_<value> type;
|
||||
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
|
||||
};
|
||||
# endif
|
||||
}
|
||||
|
||||
inline detail::keywords<1> args(char const* name)
|
||||
{
|
||||
return detail::keywords<1>(name);
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
|
||||
# define BOOST_PP_LOCAL_MACRO(n) \
|
||||
inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
|
||||
{ \
|
||||
detail::keywords<n> result; \
|
||||
BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \
|
||||
return result; \
|
||||
}
|
||||
# define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY)
|
||||
# include BOOST_PP_LOCAL_ITERATE()
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
|
||||
# endif // KEYWORDS_DWA2002323_HPP
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARGS_FWD_DWA2002927_HPP
|
||||
# define ARGS_FWD_DWA2002927_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/config.hpp>
|
||||
# include <cstddef>
|
||||
# include <utility>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct keyword
|
||||
{
|
||||
keyword(char const* name_=0)
|
||||
: name(name_)
|
||||
{}
|
||||
|
||||
char const* name;
|
||||
handle<> default_value;
|
||||
};
|
||||
|
||||
template <std::size_t nkeywords = 0> struct keywords;
|
||||
|
||||
typedef std::pair<keyword const*, keyword const*> keyword_range;
|
||||
|
||||
template <>
|
||||
struct keywords<0>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, size = 0);
|
||||
static keyword_range range() { return keyword_range(); }
|
||||
};
|
||||
|
||||
namespace error
|
||||
{
|
||||
template <int keywords, int function_args>
|
||||
struct more_keywords_than_function_arguments
|
||||
{
|
||||
typedef char too_many_keywords[keywords > function_args ? -1 : 1];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ARGS_FWD_DWA2002927_HPP
|
||||
@@ -1,103 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BACK_REFERENCE_DWA2002510_HPP
|
||||
# define BACK_REFERENCE_DWA2002510_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
# include <boost/python/detail/dependent.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
struct back_reference
|
||||
{
|
||||
private: // types
|
||||
typedef typename detail::dependent<object,T>::type source_t;
|
||||
public:
|
||||
typedef T type;
|
||||
|
||||
back_reference(PyObject*, T);
|
||||
source_t const& source() const;
|
||||
T get() const;
|
||||
private:
|
||||
source_t m_source;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
class is_back_reference
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class is_back_reference<back_reference<T> >
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
# else // no partial specialization
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#include <boost/type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_back_reference_t)[1];
|
||||
typedef char (&no_back_reference_t)[2];
|
||||
|
||||
no_back_reference_t is_back_reference_test(...);
|
||||
|
||||
template<typename T>
|
||||
yes_back_reference_t is_back_reference_test(boost::type< back_reference<T> >);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class is_back_reference
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_back_reference_test(boost::type<T>()))
|
||||
== sizeof(detail::yes_back_reference_t)));
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
back_reference<T>::back_reference(PyObject* p, T x)
|
||||
: m_source(detail::borrowed_reference(p))
|
||||
, m_value(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
typename back_reference<T>::source_t const& back_reference<T>::source() const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T back_reference<T>::get() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BACK_REFERENCE_DWA2002510_HPP
|
||||
@@ -1,38 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BASE_TYPE_TRAITS_DWA2002614_HPP
|
||||
# define BASE_TYPE_TRAITS_DWA2002614_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct unspecialized {};
|
||||
}
|
||||
|
||||
// Derive from unspecialized so we can detect whether traits are
|
||||
// specialized
|
||||
template <class T> struct base_type_traits
|
||||
: detail::unspecialized
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct base_type_traits<PyObject>
|
||||
{
|
||||
typedef PyObject type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct base_type_traits<PyTypeObject>
|
||||
{
|
||||
typedef PyObject type;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BASE_TYPE_TRAITS_DWA2002614_HPP
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BASES_DWA2002321_HPP
|
||||
# define BASES_DWA2002321_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/python/detail/type_list.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/preprocessor/enum_params_with_a_default.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# define BOOST_PYTHON_BASE_PARAMS BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, Base)
|
||||
|
||||
// A type list for specifying bases
|
||||
template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_MAX_BASES, typename Base, mpl::void_) >
|
||||
struct bases : detail::type_list< BOOST_PYTHON_BASE_PARAMS >::type
|
||||
{};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T> struct specifies_bases
|
||||
: mpl::false_
|
||||
{
|
||||
};
|
||||
|
||||
template < BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, class Base) >
|
||||
struct specifies_bases< bases< BOOST_PYTHON_BASE_PARAMS > >
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
# else
|
||||
template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class Base) >
|
||||
static char is_bases_helper(bases< BOOST_PYTHON_BASE_PARAMS > const&);
|
||||
|
||||
static char (& is_bases_helper(...) )[256];
|
||||
|
||||
template <class T>
|
||||
struct specifies_bases
|
||||
{
|
||||
private:
|
||||
static typename add_reference<T>::type make();
|
||||
BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
|
||||
typedef mpl::bool_<value> type;
|
||||
};
|
||||
# endif
|
||||
template <class T, class Prev = bases<> >
|
||||
struct select_bases
|
||||
: mpl::if_<
|
||||
specifies_bases<T>
|
||||
, T
|
||||
, Prev
|
||||
>
|
||||
{
|
||||
};
|
||||
}
|
||||
# undef BOOST_PYTHON_BASE_PARAMS
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BASES_DWA2002321_HPP
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BORROWED_DWA2002614_HPP
|
||||
# define BORROWED_DWA2002614_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/borrowed_ptr.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
inline python::detail::borrowed<T>* borrowed(T* p)
|
||||
{
|
||||
return (detail::borrowed<T>*)p;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BORROWED_DWA2002614_HPP
|
||||
@@ -1,80 +0,0 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef CALL_DWA2002411_HPP
|
||||
# define CALL_DWA2002411_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
# include <boost/python/converter/return_from_python.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
|
||||
, converter::arg_to_python<A##n>(a##n).get()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# endif // CALL_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, call.hpp)
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <
|
||||
class R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
|
||||
>
|
||||
typename detail::returnable<R>::type
|
||||
call(PyObject* callable
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
|
||||
, boost::type<R>* = 0
|
||||
)
|
||||
{
|
||||
PyObject* const result =
|
||||
PyEval_CallFunction(
|
||||
callable
|
||||
, const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
|
||||
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
|
||||
);
|
||||
|
||||
// This conversion *must not* be done in the same expression as
|
||||
// the call, because, in the special case where the result is a
|
||||
// reference a Python object which was created by converting a C++
|
||||
// argument for passing to PyEval_CallFunction, its reference
|
||||
// count will be 2 until the end of the full expression containing
|
||||
// the conversion, and that interferes with dangling
|
||||
// pointer/reference detection.
|
||||
converter::return_from_python<R> converter;
|
||||
return converter(result);
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
@@ -1,80 +0,0 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
# ifndef CALL_METHOD_DWA2002411_HPP
|
||||
# define CALL_METHOD_DWA2002411_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
# include <boost/python/converter/return_from_python.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
|
||||
, converter::arg_to_python<A##n>(a##n).get()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call_method.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# endif // CALL_METHOD_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <
|
||||
class R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
|
||||
>
|
||||
typename detail::returnable<R>::type
|
||||
call_method(PyObject* self, char const* name
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
|
||||
, boost::type<R>* = 0
|
||||
)
|
||||
{
|
||||
PyObject* const result =
|
||||
PyEval_CallMethod(
|
||||
self
|
||||
, const_cast<char*>(name)
|
||||
, const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
|
||||
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
|
||||
);
|
||||
|
||||
// This conversion *must not* be done in the same expression as
|
||||
// the call, because, in the special case where the result is a
|
||||
// reference a Python object which was created by converting a C++
|
||||
// argument for passing to PyEval_CallFunction, its reference
|
||||
// count will be 2 until the end of the full expression containing
|
||||
// the conversion, and that interferes with dangling
|
||||
// pointer/reference detection.
|
||||
converter::return_from_python<R> converter;
|
||||
return converter(result);
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif // BOOST_PP_IS_ITERATING
|
||||
@@ -1,107 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CAST_DWA200269_HPP
|
||||
# define CAST_DWA200269_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/python/base_type_traits.hpp>
|
||||
# include <boost/python/detail/convertible.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Source, class Target> inline Target* upcast_impl(Source*, Target*);
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast(Source* p, yes_convertible, no_convertible, Target*)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast(Source* p, no_convertible, no_convertible, Target*)
|
||||
{
|
||||
typedef typename base_type_traits<Source>::type base;
|
||||
|
||||
return detail::upcast_impl((base*)p, (Target*)0);
|
||||
}
|
||||
|
||||
template <bool is_same = true>
|
||||
struct upcaster
|
||||
{
|
||||
template <class T>
|
||||
static inline T* execute(T* x, T*) { return x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct upcaster<false>
|
||||
{
|
||||
template <class Source, class Target>
|
||||
static inline Target* execute(Source* x, Target*)
|
||||
{
|
||||
return detail::upcast(
|
||||
x, detail::convertible<Target*>::check(x)
|
||||
, detail::convertible<Source*>::check((Target*)0)
|
||||
, (Target*)0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* p, yes_convertible)
|
||||
{
|
||||
return static_cast<Target*>(p);
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* p, no_convertible, boost::type<Target>* = 0)
|
||||
{
|
||||
typedef typename base_type_traits<Source>::type base;
|
||||
return (Target*)detail::downcast<base>(p, convertible<Source*>::check((base*)0));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void assert_castable(boost::type<T>* = 0)
|
||||
{
|
||||
typedef char must_be_a_complete_type[sizeof(T)];
|
||||
}
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast_impl(Source* x, Target*)
|
||||
{
|
||||
typedef typename add_cv<Source>::type src_t;
|
||||
typedef typename add_cv<Target>::type target_t;
|
||||
bool const same = is_same<src_t,target_t>::value;
|
||||
|
||||
return detail::upcaster<same>::execute(x, (Target*)0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* upcast(Source* x, Target* = 0)
|
||||
{
|
||||
detail::assert_castable<Source>();
|
||||
detail::assert_castable<Target>();
|
||||
return detail::upcast_impl(x, (Target*)0);
|
||||
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* x, Target* = 0)
|
||||
{
|
||||
detail::assert_castable<Source>();
|
||||
detail::assert_castable<Target>();
|
||||
return detail::downcast<Target>(x, detail::convertible<Source*>::check((Target*)0));
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CAST_DWA200269_HPP
|
||||
@@ -1,705 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA200216_HPP
|
||||
# define CLASS_DWA200216_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
|
||||
# include <boost/python/bases.hpp>
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/data_members.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/signature.hpp>
|
||||
# include <boost/python/init.hpp>
|
||||
# include <boost/python/args_fwd.hpp>
|
||||
|
||||
# include <boost/python/object/select_holder.hpp>
|
||||
# include <boost/python/object/class_wrapper.hpp>
|
||||
# include <boost/python/object/make_instance.hpp>
|
||||
# include <boost/python/object/pickle_support.hpp>
|
||||
# include <boost/python/object/add_to_namespace.hpp>
|
||||
# include <boost/python/object/class_converters.hpp>
|
||||
|
||||
# include <boost/python/detail/overloads_fwd.hpp>
|
||||
# include <boost/python/detail/operator_id.hpp>
|
||||
# include <boost/python/detail/def_helper.hpp>
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_member_function_pointer.hpp>
|
||||
# include <boost/type_traits/is_polymorphic.hpp>
|
||||
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/mpl/for_each.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/mpl/not.hpp>
|
||||
# include <boost/mpl/or.hpp>
|
||||
# include <boost/mpl/vector/vector10.hpp>
|
||||
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) \
|
||||
/* pro9 reintroduced the bug */ \
|
||||
|| (BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, < 3)
|
||||
|
||||
# define BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING 1
|
||||
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
|
||||
# include <boost/mpl/and.hpp>
|
||||
# include <boost/type_traits/is_member_pointer.hpp>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class DerivedVisitor> class def_visitor;
|
||||
|
||||
enum no_init_t { no_init };
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This function object is used with mpl::for_each to write the id
|
||||
// of the type a pointer to which is passed as its 2nd compile-time
|
||||
// argument. into the iterator pointed to by its runtime argument
|
||||
struct write_type_id
|
||||
{
|
||||
write_type_id(type_info**p) : p(p) {}
|
||||
|
||||
// Here's the runtime behavior
|
||||
template <class T>
|
||||
void operator()(T*) const
|
||||
{
|
||||
*(*p)++ = type_id<T>();
|
||||
}
|
||||
|
||||
type_info** p;
|
||||
};
|
||||
|
||||
template <class T, class Prev = detail::not_specified>
|
||||
struct select_held_type;
|
||||
|
||||
template <class T1, class T2, class T3>
|
||||
struct has_noncopyable;
|
||||
|
||||
// Register to_python converters for a class T. The first argument
|
||||
// will be mpl::true_ unless noncopyable was specified as a
|
||||
// class_<...> template parameter. The 2nd argument is a pointer to
|
||||
// the type of holder that must be created. The 3rd argument is a
|
||||
// reference to the Python type object to be created.
|
||||
template <class T, class SelectHolder>
|
||||
inline void register_class_to_python(mpl::true_, SelectHolder, T* = 0)
|
||||
{
|
||||
typedef typename SelectHolder::type holder;
|
||||
force_instantiate(objects::class_cref_wrapper<T, objects::make_instance<T,holder> >());
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
template <class T, class SelectHolder>
|
||||
inline void register_class_to_python(mpl::false_, SelectHolder, T* = 0)
|
||||
{
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
//
|
||||
// register_wrapper_class -- register the relationship between a
|
||||
// virtual function callback wrapper class and the class being
|
||||
// wrapped.
|
||||
//
|
||||
template <class T>
|
||||
inline void register_wrapper_class_impl(T*, T*, int) {}
|
||||
|
||||
template <class Wrapper, class T>
|
||||
inline void register_wrapper_class_impl(Wrapper*, T*, ...)
|
||||
{
|
||||
objects::register_class_from_python<Wrapper, mpl::vector1<T> >();
|
||||
objects::copy_class_object(type_id<T>(), type_id<Wrapper>());
|
||||
}
|
||||
|
||||
template <class Held, class T>
|
||||
inline void register_wrapper_class(Held* = 0, T* = 0)
|
||||
{
|
||||
register_wrapper_class_impl((Held*)0, (T*)0, 0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct is_data_member_pointer
|
||||
: mpl::and_<
|
||||
is_member_pointer<T>
|
||||
, mpl::not_<is_member_function_pointer<T> >
|
||||
>
|
||||
{};
|
||||
|
||||
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
|
||||
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D) , detail::is_data_member_pointer<D>()
|
||||
# define BOOST_PYTHON_YES_DATA_MEMBER , mpl::true_
|
||||
# define BOOST_PYTHON_NO_DATA_MEMBER , mpl::false_
|
||||
# elif defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D) , 0
|
||||
# define BOOST_PYTHON_YES_DATA_MEMBER , int
|
||||
# define BOOST_PYTHON_NO_DATA_MEMBER , ...
|
||||
# else
|
||||
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D)
|
||||
# define BOOST_PYTHON_YES_DATA_MEMBER
|
||||
# define BOOST_PYTHON_NO_DATA_MEMBER
|
||||
# endif
|
||||
|
||||
namespace error
|
||||
{
|
||||
//
|
||||
// A meta-assertion mechanism which prints nice error messages and
|
||||
// backtraces on lots of compilers. Usage:
|
||||
//
|
||||
// assertion<C>::failed
|
||||
//
|
||||
// where C is an MPL metafunction class
|
||||
//
|
||||
|
||||
template <class C> struct assertion_failed { };
|
||||
template <class C> struct assertion_ok { typedef C failed; };
|
||||
|
||||
template <class C>
|
||||
struct assertion
|
||||
: mpl::if_<C, assertion_ok<C>, assertion_failed<C> >::type
|
||||
{};
|
||||
|
||||
//
|
||||
// Checks for validity of arguments used to define virtual
|
||||
// functions with default implementations.
|
||||
//
|
||||
|
||||
template <class Default>
|
||||
void not_a_derived_class_member(Default) {}
|
||||
|
||||
template <class T, class Fn>
|
||||
struct virtual_function_default
|
||||
{
|
||||
template <class Default>
|
||||
static void
|
||||
must_be_derived_class_member(Default const&)
|
||||
{
|
||||
typedef typename assertion<mpl::not_<is_same<Default,Fn> > >::failed test0;
|
||||
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
typedef typename assertion<is_polymorphic<T> >::failed test1;
|
||||
# endif
|
||||
typedef typename assertion<is_member_function_pointer<Fn> >::failed test2;
|
||||
not_a_derived_class_member<Default>(Fn());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// This is the primary mechanism through which users will expose
|
||||
// C++ classes to Python.
|
||||
template <
|
||||
class T // class being wrapped
|
||||
, class X1 // = detail::not_specified
|
||||
, class X2 // = detail::not_specified
|
||||
, class X3 // = detail::not_specified
|
||||
>
|
||||
class class_ : public objects::class_base
|
||||
{
|
||||
public: // types
|
||||
typedef objects::class_base base;
|
||||
typedef T wrapped_type;
|
||||
|
||||
typedef class_<T,X1,X2,X3> self;
|
||||
BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value));
|
||||
|
||||
// held_type - either T, a class derived from T or a smart pointer
|
||||
// to a (class derived from) T.
|
||||
typedef typename detail::select_held_type<
|
||||
X1, typename detail::select_held_type<
|
||||
X2, typename detail::select_held_type<
|
||||
X3
|
||||
>::type>::type>::type held_type;
|
||||
|
||||
typedef objects::select_holder<T,held_type> select_holder;
|
||||
|
||||
private: // types
|
||||
|
||||
typedef typename detail::select_bases<X1
|
||||
, typename detail::select_bases<X2
|
||||
, typename boost::python::detail::select_bases<X3>::type
|
||||
>::type
|
||||
>::type bases;
|
||||
|
||||
|
||||
// A helper class which will contain an array of id objects to be
|
||||
// passed to the base class constructor
|
||||
struct id_vector
|
||||
{
|
||||
id_vector()
|
||||
{
|
||||
// Stick the derived class id into the first element of the array
|
||||
ids[0] = type_id<T>();
|
||||
|
||||
// Write the rest of the elements into succeeding positions.
|
||||
type_info* p = ids + 1;
|
||||
mpl::for_each(detail::write_type_id(&p), (bases*)0, (add_pointer<mpl::_>*)0);
|
||||
}
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, size = mpl::size<bases>::value + 1);
|
||||
type_info ids[size];
|
||||
};
|
||||
friend struct id_vector;
|
||||
|
||||
public: // constructors
|
||||
|
||||
// Construct with the class name, with or without docstring, and default __init__() function
|
||||
class_(char const* name, char const* doc = 0);
|
||||
|
||||
// Construct with class name, no docstring, and an uncallable __init__ function
|
||||
class_(char const* name, no_init_t);
|
||||
|
||||
// Construct with class name, docstring, and an uncallable __init__ function
|
||||
class_(char const* name, char const* doc, no_init_t);
|
||||
|
||||
// Construct with class name and init<> function
|
||||
template <class DerivedT>
|
||||
inline class_(char const* name, init_base<DerivedT> const& i)
|
||||
: base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_holder();
|
||||
this->def(i);
|
||||
}
|
||||
|
||||
// Construct with class name, docstring and init<> function
|
||||
template <class DerivedT>
|
||||
inline class_(char const* name, char const* doc, init_base<DerivedT> const& i)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_holder();
|
||||
this->def(i);
|
||||
}
|
||||
|
||||
public: // member functions
|
||||
|
||||
// Generic visitation
|
||||
template <class Derived>
|
||||
self& def(def_visitor<Derived> const& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Wrap a member function or a non-member function which can take
|
||||
// a T, T cv&, or T cv* as its first parameter, a callable
|
||||
// python object, or a generic visitor.
|
||||
template <class F>
|
||||
self& def(char const* name, F f)
|
||||
{
|
||||
this->def_impl(name, f, detail::def_helper<char const*>(0), &f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class A1, class A2>
|
||||
self& def(char const* name, A1 a1, A2 const& a2)
|
||||
{
|
||||
this->def_maybe_overloads(name, a1, a2, &a2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn, class A1, class A2>
|
||||
self& def(char const* name, Fn fn, A1 const& a1, A2 const& a2)
|
||||
{
|
||||
// The arguments are definitely:
|
||||
// def(name, function, policy, doc_string)
|
||||
// def(name, function, doc_string, policy)
|
||||
|
||||
this->def_impl(
|
||||
name, fn
|
||||
, detail::def_helper<A1,A2>(a1,a2)
|
||||
, &fn);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn, class A1, class A2, class A3>
|
||||
self& def(char const* name, Fn fn, A1 const& a1, A2 const& a2, A3 const& a3)
|
||||
{
|
||||
this->def_impl(
|
||||
name, fn
|
||||
, detail::def_helper<A1,A2,A3>(a1,a2,a3)
|
||||
, &fn);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// Data member access
|
||||
//
|
||||
template <class D>
|
||||
self& def_readonly(char const* name, D const& d)
|
||||
{
|
||||
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite(char const* name, D const& d)
|
||||
{
|
||||
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readonly(char const* name, D& d)
|
||||
{
|
||||
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite(char const* name, D& d)
|
||||
{
|
||||
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
|
||||
}
|
||||
|
||||
// Property creation
|
||||
template <class Get>
|
||||
self& add_property(char const* name, Get fget)
|
||||
{
|
||||
base::add_property(name, this->make_getter(fget));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Get, class Set>
|
||||
self& add_property(char const* name, Get fget, Set fset)
|
||||
{
|
||||
base::add_property(name, this->make_getter(fget), this->make_setter(fset));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Get>
|
||||
self& add_static_property(char const* name, Get fget)
|
||||
{
|
||||
base::add_static_property(name, object(fget));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Get, class Set>
|
||||
self& add_static_property(char const* name, Get fget, Set fset)
|
||||
{
|
||||
base::add_static_property(name, object(fget), object(fset));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
self& setattr(char const* name, U const& x)
|
||||
{
|
||||
this->base::setattr(name, object(x));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Pickle support
|
||||
template <typename PickleSuiteType>
|
||||
self& def_pickle(PickleSuiteType const& x)
|
||||
{
|
||||
error_messages::must_be_derived_from_pickle_suite(x);
|
||||
detail::pickle_suite_finalize<PickleSuiteType>::register_(
|
||||
*this,
|
||||
&PickleSuiteType::getinitargs,
|
||||
&PickleSuiteType::getstate,
|
||||
&PickleSuiteType::setstate,
|
||||
PickleSuiteType::getstate_manages_dict());
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& staticmethod(char const* name)
|
||||
{
|
||||
this->make_method_static(name);
|
||||
return *this;
|
||||
}
|
||||
private: // helper functions
|
||||
|
||||
// Builds a method for this class around the given [member]
|
||||
// function pointer or object, appropriately adjusting the type of
|
||||
// the first signature argument so that if f is a member of a
|
||||
// (possibly not wrapped) base class of T, an lvalue argument of
|
||||
// type T will be required.
|
||||
//
|
||||
// @group PropertyHelpers {
|
||||
template <class F>
|
||||
object make_getter(F f)
|
||||
{
|
||||
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
|
||||
|
||||
return this->make_fn_impl(
|
||||
f, is_obj_or_proxy(), (char*)0, detail::is_data_member_pointer<F>()
|
||||
);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
object make_setter(F f)
|
||||
{
|
||||
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
|
||||
|
||||
return this->make_fn_impl(
|
||||
f, is_obj_or_proxy(), (int*)0, detail::is_data_member_pointer<F>()
|
||||
);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
object make_fn_impl(F const& f, mpl::false_, void*, mpl::false_)
|
||||
{
|
||||
return python::make_function(f, default_call_policies(), detail::get_signature(f, (T*)0));
|
||||
}
|
||||
|
||||
template <class D, class B>
|
||||
object make_fn_impl(D B::*pm_, mpl::false_, char*, mpl::true_)
|
||||
{
|
||||
D T::*pm = pm_;
|
||||
return python::make_getter(pm);
|
||||
}
|
||||
|
||||
template <class D, class B>
|
||||
object make_fn_impl(D B::*pm_, mpl::false_, int*, mpl::true_)
|
||||
{
|
||||
D T::*pm = pm_;
|
||||
return python::make_setter(pm);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
object make_fn_impl(F const& x, mpl::true_, void*, mpl::false_)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
// }
|
||||
|
||||
template <class D, class B>
|
||||
self& def_readonly_impl(
|
||||
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
|
||||
{
|
||||
return this->add_property(name, pm_);
|
||||
}
|
||||
|
||||
template <class D, class B>
|
||||
self& def_readwrite_impl(
|
||||
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
|
||||
{
|
||||
return this->add_property(name, pm_, pm_);
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readonly_impl(
|
||||
char const* name, D& d BOOST_PYTHON_NO_DATA_MEMBER)
|
||||
{
|
||||
return this->add_static_property(name, python::make_getter(d));
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite_impl(
|
||||
char const* name, D& d BOOST_PYTHON_NO_DATA_MEMBER)
|
||||
{
|
||||
return this->add_static_property(name, python::make_getter(d), python::make_setter(d));
|
||||
}
|
||||
|
||||
inline void register_() const;
|
||||
inline void register_holder();
|
||||
|
||||
//
|
||||
// These two overloads discriminate between def() as applied to a
|
||||
// generic visitor and everything else.
|
||||
//
|
||||
// @group def_impl {
|
||||
template <class Helper, class LeafVisitor, class Visitor>
|
||||
inline void def_impl(
|
||||
char const* name
|
||||
, LeafVisitor
|
||||
, Helper const& helper
|
||||
, def_visitor<Visitor> const* v
|
||||
)
|
||||
{
|
||||
v->visit(*this, name, helper);
|
||||
}
|
||||
|
||||
template <class Fn, class Helper>
|
||||
inline void def_impl(
|
||||
char const* name
|
||||
, Fn fn
|
||||
, Helper const& helper
|
||||
, ...
|
||||
)
|
||||
{
|
||||
objects::add_to_namespace(
|
||||
*this
|
||||
, name
|
||||
, make_function(
|
||||
fn
|
||||
, helper.policies()
|
||||
, helper.keywords()
|
||||
, detail::get_signature(fn, (T*)0)
|
||||
)
|
||||
, helper.doc()
|
||||
);
|
||||
|
||||
this->def_default(name, fn, helper, mpl::bool_<Helper::has_default_implementation>());
|
||||
}
|
||||
// }
|
||||
|
||||
//
|
||||
// These two overloads handle the definition of default
|
||||
// implementation overloads for virtual functions. The second one
|
||||
// handles the case where no default implementation was specified.
|
||||
//
|
||||
// @group def_default {
|
||||
template <class Fn, class Helper>
|
||||
inline void def_default(
|
||||
char const* name
|
||||
, Fn fn
|
||||
, Helper const& helper
|
||||
, mpl::bool_<true>)
|
||||
{
|
||||
detail::error::virtual_function_default<T,Fn>::must_be_derived_class_member(
|
||||
helper.default_implementation());
|
||||
|
||||
objects::add_to_namespace(
|
||||
*this, name,
|
||||
make_function(
|
||||
helper.default_implementation(), helper.policies(), helper.keywords())
|
||||
);
|
||||
}
|
||||
|
||||
template <class Fn, class Helper>
|
||||
inline void def_default(char const*, Fn, Helper const&, mpl::bool_<false>)
|
||||
{ }
|
||||
// }
|
||||
|
||||
//
|
||||
// These two overloads discriminate between def() as applied to
|
||||
// regular functions and def() as applied to the result of
|
||||
// BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to
|
||||
// discriminate.
|
||||
//
|
||||
// @group def_maybe_overloads {
|
||||
template <class OverloadsT, class SigT>
|
||||
void def_maybe_overloads(
|
||||
char const* name
|
||||
, SigT sig
|
||||
, OverloadsT const& overloads
|
||||
, detail::overloads_base const*)
|
||||
|
||||
{
|
||||
// convert sig to a type_list (see detail::get_signature in signature.hpp)
|
||||
// before calling detail::define_with_defaults.
|
||||
detail::define_with_defaults(
|
||||
name, overloads, *this, detail::get_signature(sig));
|
||||
}
|
||||
|
||||
template <class Fn, class A1>
|
||||
void def_maybe_overloads(
|
||||
char const* name
|
||||
, Fn fn
|
||||
, A1 const& a1
|
||||
, ...)
|
||||
{
|
||||
this->def_impl(
|
||||
name
|
||||
, fn
|
||||
, detail::def_helper<A1>(a1)
|
||||
, &fn
|
||||
);
|
||||
|
||||
}
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
// register converters
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline void class_<T,X1,X2,X3>::register_() const
|
||||
{
|
||||
objects::register_class_from_python<T,bases>();
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME select_holder::held_type held_t;
|
||||
detail::register_wrapper_class<held_t,T>();
|
||||
|
||||
detail::register_class_to_python<T>(
|
||||
mpl::bool_<is_copyable>()
|
||||
, select_holder()
|
||||
);
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline void class_<T,X1,X2,X3>::register_holder()
|
||||
{
|
||||
this->register_();
|
||||
typedef typename select_holder::type holder;
|
||||
this->set_instance_size(
|
||||
objects::additional_instance_size<holder>::value
|
||||
);
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_holder();
|
||||
select_holder::assert_default_constructible();
|
||||
this->def(init<>());
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, no_init_t)
|
||||
: base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_();
|
||||
this->def_no_init();
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc, no_init_t)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_();
|
||||
this->def_no_init();
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T1, class T2, class T3>
|
||||
struct has_noncopyable
|
||||
: mpl::or_<
|
||||
is_same<T1,noncopyable>
|
||||
, is_same<T2,noncopyable>
|
||||
, is_same<T3,noncopyable>
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
template <class T, class Prev>
|
||||
struct select_held_type
|
||||
: mpl::if_<
|
||||
mpl::or_<
|
||||
specifies_bases<T>
|
||||
, is_same<T,noncopyable>
|
||||
>
|
||||
, Prev
|
||||
, T
|
||||
>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# undef BOOST_PYTHON_DATA_MEMBER_HELPER
|
||||
# undef BOOST_PYTHON_YES_DATA_MEMBER
|
||||
# undef BOOST_PYTHON_NO_DATA_MEMBER
|
||||
# undef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
|
||||
|
||||
#endif // CLASS_DWA200216_HPP
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_FWD_DWA200222_HPP
|
||||
# define CLASS_FWD_DWA200222_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <
|
||||
class T // class being wrapped
|
||||
// arbitrarily-ordered optional arguments. Full qualification needed for MSVC6
|
||||
, class X1 = ::boost::python::detail::not_specified
|
||||
, class X2 = ::boost::python::detail::not_specified
|
||||
, class X3 = ::boost::python::detail::not_specified
|
||||
>
|
||||
class class_;
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CLASS_FWD_DWA200222_HPP
|
||||
@@ -1,344 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
# define ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
# include <boost/python/back_reference.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/converter/obj_mgr_arg_from_python.hpp>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T> struct arg_from_python;
|
||||
}}
|
||||
|
||||
// This header defines Python->C++ function argument converters,
|
||||
// parametrized on the argument type.
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
//
|
||||
// lvalue converters
|
||||
//
|
||||
// These require that an lvalue of the type U is stored somewhere in
|
||||
// the Python object being converted.
|
||||
|
||||
// Used when T == U*const&
|
||||
template <class T>
|
||||
struct pointer_cref_arg_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
pointer_cref_arg_from_python(PyObject*);
|
||||
T operator()() const;
|
||||
bool convertible() const;
|
||||
|
||||
private: // storage for a U*
|
||||
// needed because not all compilers will let us declare U* as the
|
||||
// return type of operator() -- we return U*const& instead
|
||||
typename python::detail::referent_storage<T>::type m_result;
|
||||
};
|
||||
|
||||
// Base class for pointer and reference converters
|
||||
struct arg_lvalue_from_python_base
|
||||
{
|
||||
public: // member functions
|
||||
arg_lvalue_from_python_base(void* result);
|
||||
bool convertible() const;
|
||||
|
||||
protected: // member functions
|
||||
void*const& result() const;
|
||||
|
||||
private: // data members
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*
|
||||
template <class T>
|
||||
struct pointer_arg_from_python : arg_lvalue_from_python_base
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
pointer_arg_from_python(PyObject*);
|
||||
T operator()() const;
|
||||
};
|
||||
|
||||
// Used when T == U& and (T != V const& or T == W volatile&)
|
||||
template <class T>
|
||||
struct reference_arg_from_python : arg_lvalue_from_python_base
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
reference_arg_from_python(PyObject*);
|
||||
T operator()() const;
|
||||
};
|
||||
|
||||
// ===================
|
||||
|
||||
//
|
||||
// rvalue converters
|
||||
//
|
||||
// These require only that an object of type T can be created from
|
||||
// the given Python object, but not that the T object exist
|
||||
// somewhere in storage.
|
||||
//
|
||||
|
||||
// Used when T is a plain value (non-pointer, non-reference) type or
|
||||
// a (non-volatile) const reference to a plain value type.
|
||||
template <class T>
|
||||
struct arg_rvalue_from_python
|
||||
{
|
||||
typedef typename boost::add_reference<
|
||||
T
|
||||
// We can't add_const here, or it would be impossible to pass
|
||||
// auto_ptr<U> args from Python to C++
|
||||
>::type result_type;
|
||||
|
||||
arg_rvalue_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
|
||||
# if BOOST_MSVC < 1301 || _MSC_FULL_VER > 13102196
|
||||
typename arg_rvalue_from_python<T>::
|
||||
# endif
|
||||
result_type operator()();
|
||||
|
||||
private:
|
||||
rvalue_from_python_data<result_type> m_data;
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
|
||||
// ==================
|
||||
|
||||
// Converts to a (PyObject*,T) bundle, for when you need a reference
|
||||
// back to the Python object
|
||||
template <class T>
|
||||
struct back_reference_arg_from_python
|
||||
: boost::python::arg_from_python<typename T::type>
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
back_reference_arg_from_python(PyObject*);
|
||||
T operator()();
|
||||
private:
|
||||
typedef boost::python::arg_from_python<typename T::type> base;
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
|
||||
// ==================
|
||||
|
||||
// This metafunction selects the appropriate arg_from_python converter
|
||||
// type for an argument of type T.
|
||||
template <class T>
|
||||
struct select_arg_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr_ref = is_reference_to_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr_cref
|
||||
= boost::python::detail::is_reference_to_pointer<T>::value
|
||||
&& boost::python::detail::is_reference_to_const<T>::value
|
||||
&& !boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref =
|
||||
boost::python::detail::is_reference_to_non_const<T>::value
|
||||
|| boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, back_ref =
|
||||
boost::python::is_back_reference<T>::value);
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
obj_mgr
|
||||
, object_manager_value_arg_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
obj_mgr_ref
|
||||
, object_manager_ref_arg_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
ptr
|
||||
, pointer_arg_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
ptr_cref
|
||||
, pointer_cref_arg_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
ref
|
||||
, reference_arg_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
back_ref
|
||||
, back_reference_arg_from_python<T>
|
||||
, arg_rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
// ==================
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
// arg_lvalue_from_python_base
|
||||
//
|
||||
inline arg_lvalue_from_python_base::arg_lvalue_from_python_base(void* result)
|
||||
: m_result(result)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool arg_lvalue_from_python_base::convertible() const
|
||||
{
|
||||
return m_result != 0;
|
||||
}
|
||||
|
||||
inline void*const& arg_lvalue_from_python_base::result() const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
// pointer_cref_arg_from_python
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
// null_ptr_reference -- a function returning a reference to a null
|
||||
// pointer of type U. Needed so that extractors for T*const& can
|
||||
// convert Python's None.
|
||||
template <class T>
|
||||
struct null_ptr_owner
|
||||
{
|
||||
static T value;
|
||||
};
|
||||
template <class T> T null_ptr_owner<T>::value = 0;
|
||||
|
||||
template <class U>
|
||||
inline U& null_ptr_reference(U&(*)())
|
||||
{
|
||||
return null_ptr_owner<U>::value;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline pointer_cref_arg_from_python<T>::pointer_cref_arg_from_python(PyObject* p)
|
||||
{
|
||||
// T == U*const&: store a U* in the m_result storage. Nonzero
|
||||
// indicates success. If find returns nonzero, it's a pointer to
|
||||
// a U object.
|
||||
python::detail::write_void_ptr_reference(
|
||||
m_result.bytes
|
||||
, p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool pointer_cref_arg_from_python<T>::convertible() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0;
|
||||
}
|
||||
template <class T>
|
||||
inline T pointer_cref_arg_from_python<T>::operator()() const
|
||||
{
|
||||
return (*(void**)m_result.bytes == Py_None) // None ==> 0
|
||||
? detail::null_ptr_reference((T(*)())0)
|
||||
// Otherwise, return a U*const& to the m_result storage.
|
||||
: python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0);
|
||||
}
|
||||
|
||||
// pointer_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline pointer_arg_from_python<T>::pointer_arg_from_python(PyObject* p)
|
||||
: arg_lvalue_from_python_base(
|
||||
p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T pointer_arg_from_python<T>::operator()() const
|
||||
{
|
||||
return (result() == Py_None) ? 0 : T(result());
|
||||
}
|
||||
|
||||
// reference_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline reference_arg_from_python<T>::reference_arg_from_python(PyObject* p)
|
||||
: arg_lvalue_from_python_base(converter::get_lvalue_from_python(p,registered<T>::converters))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T reference_arg_from_python<T>::operator()() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(result(), (T(*)())0);
|
||||
}
|
||||
|
||||
|
||||
// arg_rvalue_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline arg_rvalue_from_python<T>::arg_rvalue_from_python(PyObject* obj)
|
||||
: m_data(converter::rvalue_from_python_stage1(obj, registered<T>::converters))
|
||||
, m_source(obj)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool arg_rvalue_from_python<T>::convertible() const
|
||||
{
|
||||
return m_data.stage1.convertible != 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename arg_rvalue_from_python<T>::result_type
|
||||
arg_rvalue_from_python<T>::operator()()
|
||||
{
|
||||
if (m_data.stage1.construct != 0)
|
||||
m_data.stage1.construct(m_source, &m_data.stage1);
|
||||
|
||||
return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0);
|
||||
}
|
||||
|
||||
// back_reference_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
back_reference_arg_from_python<T>::back_reference_arg_from_python(PyObject* x)
|
||||
: base(x), m_source(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T
|
||||
back_reference_arg_from_python<T>::operator()()
|
||||
{
|
||||
return T(m_source, base::operator()());
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
@@ -1,262 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_TO_PYTHON_DWA200265_HPP
|
||||
# define ARG_TO_PYTHON_DWA200265_HPP
|
||||
|
||||
# include <boost/python/ptr.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
# include <boost/python/to_python_indirect.hpp>
|
||||
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/converter/arg_to_python_base.hpp>
|
||||
# include <boost/python/converter/shared_ptr_to_python.hpp>
|
||||
// Bring in specializations
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
|
||||
# include <boost/python/object/function_handle.hpp>
|
||||
|
||||
# include <boost/python/base_type_traits.hpp>
|
||||
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/python/detail/convertible.hpp>
|
||||
# include <boost/python/detail/string_literal.hpp>
|
||||
# include <boost/python/detail/value_is_shared_ptr.hpp>
|
||||
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/function_traits.hpp>
|
||||
|
||||
|
||||
# include <boost/mpl/or.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct is_object_manager;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct function_arg_to_python : handle<>
|
||||
{
|
||||
function_arg_to_python(T const& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct reference_arg_to_python : handle<>
|
||||
{
|
||||
reference_arg_to_python(T& x);
|
||||
private:
|
||||
static PyObject* get_object(T& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct shared_ptr_arg_to_python : handle<>
|
||||
{
|
||||
shared_ptr_arg_to_python(T const& x);
|
||||
private:
|
||||
static PyObject* get_object(T& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct value_arg_to_python : arg_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
value_arg_to_python(T const&);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_deep_arg_to_python : arg_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_deep_arg_to_python(Ptr);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_shallow_arg_to_python : handle<>
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_shallow_arg_to_python(Ptr);
|
||||
private:
|
||||
static PyObject* get_object(Ptr p);
|
||||
};
|
||||
|
||||
// Convert types that manage a Python object to_python
|
||||
template <class T>
|
||||
struct object_manager_arg_to_python
|
||||
{
|
||||
object_manager_arg_to_python(T const& x) : m_src(x) {}
|
||||
|
||||
PyObject* get() const
|
||||
{
|
||||
return python::upcast<PyObject>(get_managed_object(m_src, tag));
|
||||
}
|
||||
|
||||
private:
|
||||
T const& m_src;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_arg_to_python
|
||||
{
|
||||
typedef typename unwrap_reference<T>::type unwrapped_referent;
|
||||
typedef typename unwrap_pointer<T>::type unwrapped_ptr;
|
||||
|
||||
typedef typename mpl::if_<
|
||||
// Special handling for char const[N]; interpret them as char
|
||||
// const* for the sake of conversion
|
||||
python::detail::is_string_literal<T const>
|
||||
, arg_to_python<char const*>
|
||||
|
||||
, typename mpl::if_<
|
||||
python::detail::value_is_shared_ptr<T>
|
||||
, shared_ptr_arg_to_python<T>
|
||||
|
||||
, typename mpl::if_<
|
||||
mpl::or_<
|
||||
is_function<T>
|
||||
, python::detail::is_pointer_to_function<T>
|
||||
, is_member_function_pointer<T>
|
||||
>
|
||||
, function_arg_to_python<T>
|
||||
|
||||
, typename mpl::if_<
|
||||
is_object_manager<T>
|
||||
, object_manager_arg_to_python<T>
|
||||
|
||||
, typename mpl::if_<
|
||||
is_pointer<T>
|
||||
, pointer_deep_arg_to_python<T>
|
||||
|
||||
, typename mpl::if_<
|
||||
is_pointer_wrapper<T>
|
||||
, pointer_shallow_arg_to_python<unwrapped_ptr>
|
||||
|
||||
, typename mpl::if_<
|
||||
is_reference_wrapper<T>
|
||||
, reference_arg_to_python<unwrapped_referent>
|
||||
, value_arg_to_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
|
||||
type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct arg_to_python
|
||||
: detail::select_arg_to_python<T>::type
|
||||
{
|
||||
typedef typename detail::select_arg_to_python<T>::type base;
|
||||
public: // member functions
|
||||
// Throw an exception if the conversion can't succeed
|
||||
arg_to_python(T const& x);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
// reject_raw_object_ptr -- cause a compile-time error if the user
|
||||
// should pass a raw Python object pointer
|
||||
using python::detail::yes_convertible;
|
||||
using python::detail::no_convertible;
|
||||
using python::detail::unspecialized;
|
||||
|
||||
template <class T> struct cannot_convert_raw_PyObject;
|
||||
|
||||
template <class T, class Convertibility>
|
||||
struct reject_raw_object_helper
|
||||
{
|
||||
static void error(Convertibility)
|
||||
{
|
||||
cannot_convert_raw_PyObject<T*>::to_python_use_handle_instead();
|
||||
}
|
||||
static void error(...) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline void reject_raw_object_ptr(T*)
|
||||
{
|
||||
reject_raw_object_helper<T,yes_convertible>::error(
|
||||
python::detail::convertible<PyObject const volatile*>::check((T*)0));
|
||||
|
||||
typedef typename remove_cv<T>::type value_type;
|
||||
|
||||
reject_raw_object_helper<T,no_convertible>::error(
|
||||
python::detail::convertible<unspecialized*>::check(
|
||||
(base_type_traits<value_type>*)0
|
||||
));
|
||||
}
|
||||
// ---------
|
||||
|
||||
template <class T>
|
||||
inline function_arg_to_python<T>::function_arg_to_python(T const& x)
|
||||
: handle<>(python::objects::make_function_handle(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline value_arg_to_python<T>::value_arg_to_python(T const& x)
|
||||
: arg_to_python_base(&x, registered<T>::converters)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_deep_arg_to_python<Ptr>::pointer_deep_arg_to_python(Ptr x)
|
||||
: arg_to_python_base(x, registered_pointee<Ptr>::converters)
|
||||
{
|
||||
detail::reject_raw_object_ptr((Ptr)0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline PyObject* reference_arg_to_python<T>::get_object(T& x)
|
||||
{
|
||||
to_python_indirect<T&,python::detail::make_reference_holder> convert;
|
||||
return convert(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline reference_arg_to_python<T>::reference_arg_to_python(T& x)
|
||||
: handle<>(reference_arg_to_python<T>::get_object(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline shared_ptr_arg_to_python<T>::shared_ptr_arg_to_python(T const& x)
|
||||
: handle<>(shared_ptr_to_python(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_shallow_arg_to_python<Ptr>::pointer_shallow_arg_to_python(Ptr x)
|
||||
: handle<>(pointer_shallow_arg_to_python<Ptr>::get_object(x))
|
||||
{
|
||||
detail::reject_raw_object_ptr((Ptr)0);
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline PyObject* pointer_shallow_arg_to_python<Ptr>::get_object(Ptr x)
|
||||
{
|
||||
to_python_indirect<Ptr,python::detail::make_reference_holder> convert;
|
||||
return convert(x);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline arg_to_python<T>::arg_to_python(T const& x)
|
||||
: base(x)
|
||||
{}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_TO_PYTHON_DWA200265_HPP
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# define ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# include <boost/python/handle.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct BOOST_PYTHON_DECL arg_to_python_base
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC <= 1300 || _MSC_FULL_VER > 13102179
|
||||
: handle<>
|
||||
# endif
|
||||
{
|
||||
arg_to_python_base(void const volatile* source, registration const&);
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC > 1300 && _MSC_FULL_VER <= 13102179
|
||||
PyObject* get() const { return m_ptr.get(); }
|
||||
PyObject* release() { return m_ptr.release(); }
|
||||
private:
|
||||
handle<> m_ptr;
|
||||
# endif
|
||||
};
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef AS_TO_PYTHON_FUNCTION_DWA2002121_HPP
|
||||
# define AS_TO_PYTHON_FUNCTION_DWA2002121_HPP
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Given a typesafe to_python conversion function, produces a
|
||||
// to_python_function_t which can be registered in the usual way.
|
||||
template <class T, class ToPython>
|
||||
struct as_to_python_function
|
||||
{
|
||||
// Assertion functions used to prevent wrapping of converters
|
||||
// which take non-const reference parameters. The T* argument in
|
||||
// the first overload ensures it isn't used in case T is a
|
||||
// reference.
|
||||
template <class U>
|
||||
static void convert_function_must_take_value_or_const_reference(U(*)(T), int, T* = 0) {}
|
||||
template <class U>
|
||||
static void convert_function_must_take_value_or_const_reference(U(*)(T const&), long ...) {}
|
||||
|
||||
static PyObject* convert(void const* x)
|
||||
{
|
||||
convert_function_must_take_value_or_const_reference(&ToPython::convert, 1L);
|
||||
|
||||
// Yes, the const_cast below opens a hole in const-correctness,
|
||||
// but it's needed to convert auto_ptr<U> to python.
|
||||
//
|
||||
// How big a hole is it? It allows ToPython::convert() to be
|
||||
// a function which modifies its argument. The upshot is that
|
||||
// client converters applied to const objects may invoke
|
||||
// undefined behavior. The damage, however, is limited by the
|
||||
// use of the assertion function. Thus, the only way this can
|
||||
// modify its argument is if T is an auto_ptr-like type. There
|
||||
// is still a const-correctness hole w.r.t. auto_ptr<U> const,
|
||||
// but c'est la vie.
|
||||
return ToPython::convert(*const_cast<T*>(static_cast<T const*>(x)));
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // AS_TO_PYTHON_FUNCTION_DWA2002121_HPP
|
||||
@@ -1,141 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# define BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/implicit_cast.hpp>
|
||||
# include <string>
|
||||
# include <complex>
|
||||
# include <boost/limits.hpp>
|
||||
|
||||
// Since all we can use to decide how to convert an object to_python
|
||||
// is its C++ type, there can be only one such converter for each
|
||||
// type. Therefore, for built-in conversions we can bypass registry
|
||||
// lookups using explicit specializations of arg_to_python and
|
||||
// result_to_python.
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct arg_to_python;
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(char);
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(char const*);
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(PyObject*);
|
||||
BOOST_PYTHON_DECL PyObject* do_arg_to_python(PyObject*);
|
||||
}
|
||||
|
||||
// Provide specializations of to_python_value
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Since there's no registry lookup, always report the existence of
|
||||
// a converter.
|
||||
struct builtin_to_python
|
||||
{
|
||||
// This information helps make_getter() decide whether to try to
|
||||
// return an internal reference or not. I don't like it much,
|
||||
// but it will have to serve for now.
|
||||
BOOST_STATIC_CONSTANT(bool, uses_registry = false);
|
||||
};
|
||||
}
|
||||
|
||||
// Use expr to create the PyObject corresponding to x
|
||||
# define BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
template <> struct to_python_value<T&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
inline PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
}; \
|
||||
template <> struct to_python_value<T const&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
inline PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
};
|
||||
|
||||
# define BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
namespace converter \
|
||||
{ \
|
||||
template <> struct arg_to_python< T > \
|
||||
: handle<> \
|
||||
{ \
|
||||
arg_to_python(T const& x) \
|
||||
: python::handle<>(expr) {} \
|
||||
}; \
|
||||
}
|
||||
|
||||
// Specialize argument and return value converters for T using expr
|
||||
# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T,expr) \
|
||||
BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr)
|
||||
|
||||
// Specialize converters for signed and unsigned T to Python Int
|
||||
# define BOOST_PYTHON_TO_INT(T) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyInt_FromLong(x)) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE( \
|
||||
unsigned T \
|
||||
, static_cast<unsigned long>(x) > static_cast<unsigned long>( \
|
||||
std::numeric_limits<long>::max()) \
|
||||
? ::PyLong_FromUnsignedLong(x) \
|
||||
: ::PyInt_FromLong(x))
|
||||
|
||||
// Bool is not signed.
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
|
||||
|
||||
// note: handles signed char and unsigned char, but not char (see below)
|
||||
BOOST_PYTHON_TO_INT(char)
|
||||
|
||||
BOOST_PYTHON_TO_INT(short)
|
||||
BOOST_PYTHON_TO_INT(int)
|
||||
BOOST_PYTHON_TO_INT(long)
|
||||
|
||||
// using Python's macro instead of Boost's - we don't seem to get the
|
||||
// config right all the time.
|
||||
# ifdef HAVE_LONG_LONG
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x))
|
||||
# endif
|
||||
|
||||
# undef BOOST_TO_PYTHON_INT
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyString_FromStringAndSize(x.data(),implicit_cast<int>(x.size())))
|
||||
# ifndef BOOST_NO_STD_WSTRING
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<int>(x.size())))
|
||||
# endif
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, ::PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, ::PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, ::PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(PyObject*, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<float>, ::PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<double>, ::PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<long double>, ::PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
|
||||
# undef BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE
|
||||
# undef BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE
|
||||
# undef BOOST_PYTHON_TO_PYTHON_BY_VALUE
|
||||
# undef BOOST_PYTHON_TO_INT
|
||||
|
||||
namespace converter
|
||||
{
|
||||
|
||||
void initialize_builtin_converters();
|
||||
|
||||
}
|
||||
|
||||
}} // namespace boost::python::converter
|
||||
|
||||
#endif // BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
# define CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Declares the type of functions used to construct C++ objects for
|
||||
// rvalue from_python conversions.
|
||||
struct rvalue_from_python_stage1_data;
|
||||
typedef void (*constructor_function)(PyObject* source, rvalue_from_python_stage1_data*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONTEXT_RESULT_CONVERTER_DWA2003917_HPP
|
||||
# define CONTEXT_RESULT_CONVERTER_DWA2003917_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// A ResultConverter base class used to indicate that this result
|
||||
// converter should be constructed with the original Python argument
|
||||
// list.
|
||||
struct context_result_converter {};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONTEXT_RESULT_CONVERTER_DWA2003917_HPP
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
# define CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
typedef void* (*convertible_function)(PyObject*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
# define FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
|
||||
BOOST_PYTHON_DECL void* get_lvalue_from_python(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL bool implicit_rvalue_convertible_from_python(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL rvalue_from_python_stage1_data rvalue_from_python_stage1(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void* rvalue_from_python_stage2(
|
||||
PyObject* source, rvalue_from_python_stage1_data&, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void* rvalue_result_from_python(
|
||||
PyObject*, rvalue_from_python_stage1_data&);
|
||||
|
||||
BOOST_PYTHON_DECL void* reference_result_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void* pointer_result_from_python(PyObject*, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void void_result_from_python(PyObject*);
|
||||
|
||||
BOOST_PYTHON_DECL void throw_no_pointer_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void throw_no_reference_from_python(PyObject*, registration const&);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef IMPLICIT_DWA2002326_HPP
|
||||
# define IMPLICIT_DWA2002326_HPP
|
||||
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registrations.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
|
||||
# include <boost/python/extract.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class Source, class Target>
|
||||
struct implicit
|
||||
{
|
||||
static void* convertible(PyObject* obj)
|
||||
{
|
||||
// Find a converter which can produce a Source instance from
|
||||
// obj. The user has told us that Source can be converted to
|
||||
// Target, and instantiating construct() below, ensures that
|
||||
// at compile-time.
|
||||
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
|
||||
? obj : 0;
|
||||
}
|
||||
|
||||
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
|
||||
|
||||
new (storage) Target(extract<Source>(obj)());
|
||||
|
||||
// record successful construction
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // IMPLICIT_DWA2002326_HPP
|
||||
@@ -1,122 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
# define OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/detail/destroy.hpp>
|
||||
# include <boost/python/detail/construct.hpp>
|
||||
# include <boost/python/converter/object_manager.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
|
||||
//
|
||||
// arg_from_python converters for Python type wrappers, to be used as
|
||||
// base classes for specializations.
|
||||
//
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T>
|
||||
struct object_manager_value_arg_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
object_manager_value_arg_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
T operator()() const;
|
||||
private:
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
// Used for converting reference-to-object-manager arguments from
|
||||
// python. The process used here is a little bit odd. Upon
|
||||
// construction, we build the object manager object in the m_result
|
||||
// object, *forcing* it to accept the source Python object by casting
|
||||
// its pointer to detail::borrowed_reference. This is supposed to
|
||||
// bypass any type checking of the source object. The convertible
|
||||
// check then extracts the owned object and checks it. If the check
|
||||
// fails, nothing else in the program ever gets to touch this strange
|
||||
// "forced" object.
|
||||
template <class Ref>
|
||||
struct object_manager_ref_arg_from_python
|
||||
{
|
||||
typedef Ref result_type;
|
||||
|
||||
object_manager_ref_arg_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
Ref operator()() const;
|
||||
~object_manager_ref_arg_from_python();
|
||||
private:
|
||||
typename python::detail::referent_storage<Ref>::type m_result;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
template <class T>
|
||||
inline object_manager_value_arg_from_python<T>::object_manager_value_arg_from_python(PyObject* x)
|
||||
: m_source(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool object_manager_value_arg_from_python<T>::convertible() const
|
||||
{
|
||||
return object_manager_traits<T>::check(m_source);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T object_manager_value_arg_from_python<T>::operator()() const
|
||||
{
|
||||
return T(python::detail::borrowed_reference(m_source));
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline object_manager_ref_arg_from_python<Ref>::object_manager_ref_arg_from_python(PyObject* x)
|
||||
{
|
||||
# if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 243
|
||||
// needed for warning suppression
|
||||
python::detail::borrowed_reference x_ = python::detail::borrowed_reference(x);
|
||||
python::detail::construct_referent<Ref>(&m_result.bytes, x_);
|
||||
# else
|
||||
python::detail::construct_referent<Ref>(&m_result.bytes, (python::detail::borrowed_reference)x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline object_manager_ref_arg_from_python<Ref>::~object_manager_ref_arg_from_python()
|
||||
{
|
||||
python::detail::destroy_referent<Ref>(this->m_result.bytes);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline bool object_manager_ref_check(T const& x)
|
||||
{
|
||||
return object_manager_traits<T>::check(get_managed_object(x, tag));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline bool object_manager_ref_arg_from_python<Ref>::convertible() const
|
||||
{
|
||||
return detail::object_manager_ref_check(
|
||||
python::detail::void_ptr_to_reference(this->m_result.bytes, (Ref(*)())0));
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline Ref object_manager_ref_arg_from_python<Ref>::operator()() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
this->m_result.bytes, (Ref(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
@@ -1,231 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_MANAGER_DWA2002614_HPP
|
||||
# define OBJECT_MANAGER_DWA2002614_HPP
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
# include <boost/python/converter/pyobject_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
|
||||
// Facilities for dealing with types which always manage Python
|
||||
// objects. Some examples are object, list, str, et. al. Different
|
||||
// to_python/from_python conversion rules apply here because in
|
||||
// contrast to other types which are typically embedded inside a
|
||||
// Python object, these are wrapped around a Python object. For most
|
||||
// object managers T, a C++ non-const T reference argument does not
|
||||
// imply the existence of a T lvalue embedded in the corresponding
|
||||
// Python argument, since mutating member functions on T actually only
|
||||
// modify the held Python object.
|
||||
//
|
||||
// handle<T> is an object manager, though strictly speaking it should
|
||||
// not be. In other words, even though mutating member functions of
|
||||
// hanlde<T> actually modify the handle<T> and not the T object,
|
||||
// handle<T>& arguments of wrapped functions will bind to "rvalues"
|
||||
// wrapping the actual Python argument, just as with other object
|
||||
// manager classes. Making an exception for handle<T> is simply not
|
||||
// worth the trouble.
|
||||
//
|
||||
// borrowed<T> cv* is an object manager so that we can use the general
|
||||
// to_python mechanisms to convert raw Python object pointers to
|
||||
// python, without the usual semantic problems of using raw pointers.
|
||||
|
||||
|
||||
// Object Manager Concept requirements:
|
||||
//
|
||||
// T is an Object Manager
|
||||
// p is a PyObject*
|
||||
// x is a T
|
||||
//
|
||||
// * object_manager_traits<T>::is_specialized == true
|
||||
//
|
||||
// * T(detail::borrowed_reference(p))
|
||||
// Manages p without checking its type
|
||||
//
|
||||
// * get_managed_object(x, boost::python::tag)
|
||||
// Convertible to PyObject*
|
||||
//
|
||||
// Additional requirements if T can be converted from_python:
|
||||
//
|
||||
// * T(object_manager_traits<T>::adopt(p))
|
||||
// steals a reference to p, or throws a TypeError exception if
|
||||
// p doesn't have an appropriate type. May assume p is non-null
|
||||
//
|
||||
// * X::check(p)
|
||||
// convertible to bool. True iff T(X::construct(p)) will not
|
||||
// throw.
|
||||
|
||||
// Forward declarations
|
||||
//
|
||||
namespace boost { namespace python
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
class object;
|
||||
}
|
||||
}}
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
|
||||
// Specializations for handle<T>
|
||||
template <class T>
|
||||
struct handle_object_manager_traits
|
||||
: pyobject_traits<typename T::element_type>
|
||||
{
|
||||
private:
|
||||
typedef pyobject_traits<typename T::element_type> base;
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
|
||||
|
||||
// Initialize with a null_ok pointer for efficiency, bypassing the
|
||||
// null check since the source is always non-null.
|
||||
static null_ok<typename T::element_type>* adopt(PyObject* p)
|
||||
{
|
||||
return python::allow_null(base::checked_downcast(p));
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct default_object_manager_traits
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, is_specialized = python::detail::is_borrowed_ptr<T>::value
|
||||
);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct object_manager_traits
|
||||
: mpl::if_c<
|
||||
is_handle<T>::value
|
||||
, handle_object_manager_traits<T>
|
||||
, default_object_manager_traits<T>
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// Traits for detecting whether a type is an object manager or a
|
||||
// (cv-qualified) reference to an object manager.
|
||||
//
|
||||
|
||||
template <class T>
|
||||
struct is_object_manager
|
||||
: mpl::bool_<object_manager_traits<T>::is_specialized>
|
||||
{
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager
|
||||
: mpl::false_
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T const&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T volatile&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T const volatile&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
# else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_reference_to_object_manager)[1];
|
||||
typedef char (&no_reference_to_object_manager)[2];
|
||||
|
||||
// A number of nastinesses go on here in order to work around MSVC6
|
||||
// bugs.
|
||||
template <class T>
|
||||
struct is_object_manager_help
|
||||
{
|
||||
typedef typename mpl::if_<
|
||||
is_object_manager<T>
|
||||
, yes_reference_to_object_manager
|
||||
, no_reference_to_object_manager
|
||||
>::type type;
|
||||
|
||||
// If we just use the type instead of the result of calling this
|
||||
// function, VC6 will ICE.
|
||||
static type call();
|
||||
};
|
||||
|
||||
// A set of overloads for each cv-qualification. The same argument
|
||||
// is passed twice: the first one is used to unwind the cv*, and the
|
||||
// second one is used to avoid relying on partial ordering for
|
||||
// overload resolution.
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U*, void*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U const*, void const*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U volatile*, void volatile*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U const volatile*, void const volatile*);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager_nonref
|
||||
: mpl::false_
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager_ref
|
||||
{
|
||||
static T sample_object;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (sizeof(is_object_manager_helper(&sample_object, &sample_object).call())
|
||||
== sizeof(detail::yes_reference_to_object_manager)
|
||||
)
|
||||
);
|
||||
typedef mpl::bool_<value> type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager
|
||||
: mpl::if_<
|
||||
is_reference<T>
|
||||
, detail::is_reference_to_object_manager_ref<T>
|
||||
, detail::is_reference_to_object_manager_nonref<T>
|
||||
>::type
|
||||
{
|
||||
};
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // OBJECT_MANAGER_DWA2002614_HPP
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef POINTER_TYPE_ID_DWA2002222_HPP
|
||||
# define POINTER_TYPE_ID_DWA2002222_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool is_ref = false>
|
||||
struct pointer_typeid_select
|
||||
{
|
||||
template <class T>
|
||||
static inline type_info execute(T*(*)() = 0)
|
||||
{
|
||||
return type_id<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pointer_typeid_select<true>
|
||||
{
|
||||
template <class T>
|
||||
static inline type_info execute(T* const volatile&(*)() = 0)
|
||||
{
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline type_info execute(T*volatile&(*)() = 0)
|
||||
{
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline type_info execute(T*const&(*)() = 0)
|
||||
{
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline type_info execute(T*&(*)() = 0)
|
||||
{
|
||||
return type_id<T>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Usage: pointer_type_id<T>()
|
||||
//
|
||||
// Returns a type_info associated with the type pointed
|
||||
// to by T, which may be a pointer or a reference to a pointer.
|
||||
template <class T>
|
||||
type_info pointer_type_id(T(*)() = 0)
|
||||
{
|
||||
return detail::pointer_typeid_select<
|
||||
is_reference<T>::value
|
||||
>::execute((T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // POINTER_TYPE_ID_DWA2002222_HPP
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
# define PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/converter/pyobject_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class> struct pyobject_traits;
|
||||
|
||||
template <>
|
||||
struct pyobject_traits<PyObject>
|
||||
{
|
||||
// All objects are convertible to PyObject
|
||||
static bool check(PyObject*) { return true; }
|
||||
static PyObject* checked_downcast(PyObject* x) { return x; }
|
||||
};
|
||||
|
||||
//
|
||||
// Specializations
|
||||
//
|
||||
|
||||
# define BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(T) \
|
||||
template <> struct pyobject_traits<Py##T##Object> \
|
||||
: pyobject_type<Py##T##Object, &Py##T##_Type> {}
|
||||
|
||||
// This is not an exhaustive list; should be expanded.
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYOBJECT_TYPE_DWA2002720_HPP
|
||||
# define PYOBJECT_TYPE_DWA2002720_HPP
|
||||
|
||||
# include <boost/python/cast.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* checked_downcast_impl(PyObject*, PyTypeObject*);
|
||||
|
||||
// Used as a base class for specializations which need to provide
|
||||
// Python type checking capability.
|
||||
template <class Object, PyTypeObject* pytype>
|
||||
struct pyobject_type
|
||||
{
|
||||
static bool check(PyObject* x)
|
||||
{
|
||||
return ::PyObject_IsInstance(x, (PyObject*)pytype);
|
||||
}
|
||||
|
||||
static Object* checked_downcast(PyObject* x)
|
||||
{
|
||||
return python::downcast<Object>(
|
||||
(checked_downcast_impl)(x, pytype)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYOBJECT_TYPE_DWA2002720_HPP
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
# define PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
# include <boost/python/converter/pyobject_type.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Provide a forward declaration as a convenience for clients, who all
|
||||
// need it.
|
||||
template <class T> struct object_manager_traits;
|
||||
|
||||
// Derive specializations of object_manager_traits from this class
|
||||
// when T is an object manager for a particular Python type hierarchy.
|
||||
//
|
||||
template <PyTypeObject* pytype, class T>
|
||||
struct pytype_object_manager_traits
|
||||
: pyobject_type<T, pytype> // provides check()
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
|
||||
static inline python::detail::new_reference adopt(PyObject*);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <PyTypeObject* pytype, class T>
|
||||
inline python::detail::new_reference pytype_object_manager_traits<pytype,T>::adopt(PyObject* x)
|
||||
{
|
||||
return python::detail::new_reference(python::pytype_check(pytype, x));
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTERED_DWA2002710_HPP
|
||||
# define REGISTERED_DWA2002710_HPP
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/registrations.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct registered_base
|
||||
{
|
||||
static registration const& converters;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct registered
|
||||
: detail::registered_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
&& !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
|
||||
// collapses a few more types to the same static instance. MSVC7.1
|
||||
// fails to strip cv-qualification from array types in typeid. For
|
||||
// some reason we can't use this collapse there or array converters
|
||||
// will not be found.
|
||||
template <class T>
|
||||
struct registered<T&>
|
||||
: registered<T> {};
|
||||
# endif
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
registration const& registered_base<T>::converters
|
||||
= registry::lookup(type_id<T>());
|
||||
}
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTERED_DWA2002710_HPP
|
||||
@@ -1,63 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTERED_POINTEE_DWA2002710_HPP
|
||||
# define REGISTERED_POINTEE_DWA2002710_HPP
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct registered_pointee
|
||||
: registered<
|
||||
typename remove_pointer<
|
||||
typename remove_cv<
|
||||
typename remove_reference<T>::type
|
||||
>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
# else
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct registered_pointee_base
|
||||
{
|
||||
static registration const& converters;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct registered_pointee
|
||||
: detail::registered_pointee_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
registration const& registered_pointee_base<T>::converters
|
||||
= registry::lookup(pointer_type_id<T>());
|
||||
}
|
||||
|
||||
# endif
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTERED_POINTEE_DWA2002710_HPP
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRATIONS_DWA2002223_HPP
|
||||
# define REGISTRATIONS_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
|
||||
# include <boost/python/converter/convertible_function.hpp>
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_chain
|
||||
{
|
||||
convertible_function convert;
|
||||
lvalue_from_python_chain* next;
|
||||
};
|
||||
|
||||
struct rvalue_from_python_chain
|
||||
{
|
||||
convertible_function convertible;
|
||||
constructor_function construct;
|
||||
rvalue_from_python_chain* next;
|
||||
};
|
||||
|
||||
struct BOOST_PYTHON_DECL registration
|
||||
{
|
||||
public: // member functions
|
||||
explicit registration(type_info);
|
||||
|
||||
// Convert the appropriately-typed data to Python
|
||||
PyObject* to_python(void const volatile*) const;
|
||||
|
||||
// Return the class object, or raise an appropriate Python
|
||||
// exception if no class has been registered.
|
||||
PyTypeObject* get_class_object() const;
|
||||
|
||||
public: // data members. So sue me.
|
||||
const python::type_info target_type;
|
||||
|
||||
// The chain of eligible from_python converters when an lvalue is required
|
||||
lvalue_from_python_chain* lvalue_chain;
|
||||
|
||||
// The chain of eligible from_python converters when an rvalue is acceptable
|
||||
rvalue_from_python_chain* rvalue_chain;
|
||||
|
||||
// The class object associated with this type
|
||||
PyTypeObject* m_class_object;
|
||||
|
||||
// The unique to_python converter for the associated C++ type.
|
||||
to_python_function_t m_to_python;
|
||||
|
||||
# if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
||||
private:
|
||||
void operator=(registration); // This is not defined, and just keeps MWCW happy.
|
||||
# endif
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline registration::registration(type_info target_type)
|
||||
: target_type(target_type)
|
||||
, lvalue_chain(0)
|
||||
, rvalue_chain(0)
|
||||
, m_class_object(0)
|
||||
, m_to_python(0)
|
||||
{}
|
||||
|
||||
inline bool operator<(registration const& lhs, registration const& rhs)
|
||||
{
|
||||
return lhs.target_type < rhs.target_type;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRATIONS_DWA2002223_HPP
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRY_DWA20011127_HPP
|
||||
# define REGISTRY_DWA20011127_HPP
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/converter/convertible_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
// Get the registration corresponding to the type, creating it if neccessary
|
||||
BOOST_PYTHON_DECL registration const& lookup(type_info);
|
||||
|
||||
// Return a pointer to the corresponding registration, if one exists
|
||||
BOOST_PYTHON_DECL registration const* query(type_info);
|
||||
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, type_info);
|
||||
|
||||
// Insert an lvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), type_info);
|
||||
|
||||
// Insert an rvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(
|
||||
convertible_function
|
||||
, constructor_function
|
||||
, type_info
|
||||
);
|
||||
|
||||
// Insert an rvalue from_python converter at the tail of the
|
||||
// chain. Used for implicit conversions
|
||||
BOOST_PYTHON_DECL void push_back(
|
||||
convertible_function
|
||||
, constructor_function
|
||||
, type_info
|
||||
);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRY_DWA20011127_HPP
|
||||
@@ -1,161 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
# define RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/type_traits/has_trivial_copy.hpp>
|
||||
# include <boost/mpl/and.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct is_object_manager;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct return_pointer_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_reference_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_rvalue_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
return_rvalue_from_python();
|
||||
result_type operator()(PyObject*);
|
||||
private:
|
||||
rvalue_from_python_data<T> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_object_manager_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
result_type operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_return_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref = is_reference<T>::value);
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
obj_mgr
|
||||
, return_object_manager_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
ptr
|
||||
, return_pointer_from_python<T>
|
||||
, typename mpl::if_c<
|
||||
ref
|
||||
, return_reference_from_python<T>
|
||||
, return_rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct return_from_python
|
||||
: detail::select_return_from_python<T>::type
|
||||
{
|
||||
};
|
||||
|
||||
// Specialization as a convenience for call and call_method
|
||||
template <>
|
||||
struct return_from_python<void>
|
||||
{
|
||||
typedef python::detail::returnable<void>::type result_type;
|
||||
|
||||
result_type operator()(PyObject* x) const
|
||||
{
|
||||
(void_result_from_python)(x);
|
||||
# ifdef BOOST_NO_VOID_RETURNS
|
||||
return result_type();
|
||||
# endif
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline return_rvalue_from_python<T>::return_rvalue_from_python()
|
||||
: m_data(
|
||||
const_cast<registration*>(®istered<T>::converters)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename return_rvalue_from_python<T>::result_type
|
||||
return_rvalue_from_python<T>::operator()(PyObject* obj)
|
||||
{
|
||||
// Take possession of the source object here. If the result is in
|
||||
// fact going to be a copy of an lvalue embedded in the object,
|
||||
// and we take possession inside rvalue_result_from_python, it
|
||||
// will be destroyed too early.
|
||||
handle<> holder(obj);
|
||||
|
||||
return *(T*)
|
||||
(rvalue_result_from_python)(obj, m_data.stage1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_reference_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
(reference_result_from_python)(obj, registered<T>::converters)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_pointer_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(
|
||||
(pointer_result_from_python)(obj, registered_pointee<T>::converters)
|
||||
);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_object_manager_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(
|
||||
object_manager_traits<T>::adopt(expect_non_null(obj))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
@@ -1,141 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
# define FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/detail/destroy.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/add_cv.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
// Data management for potential rvalue conversions from Python to C++
|
||||
// types. When a client requests a conversion to T* or T&, we
|
||||
// generally require that an object of type T exists in the source
|
||||
// Python object, and the code here does not apply**. This implements
|
||||
// conversions which may create new temporaries of type T. The classic
|
||||
// example is a conversion which converts a Python tuple to a
|
||||
// std::vector. Since no std::vector lvalue exists in the Python
|
||||
// object -- it must be created "on-the-fly" by the converter, and
|
||||
// which must manage the lifetime of the created object.
|
||||
//
|
||||
// Note that the client is not precluded from using a registered
|
||||
// lvalue conversion to T in this case. In other words, we will
|
||||
// happily accept a Python object which /does/ contain a std::vector
|
||||
// lvalue, provided an appropriate converter is registered. So, while
|
||||
// this is an rvalue conversion from the client's point-of-view, the
|
||||
// converter registry may serve up lvalue or rvalue conversions for
|
||||
// the target type.
|
||||
//
|
||||
// ** C++ argument from_python conversions to T const& are an
|
||||
// exception to the rule for references: since in C++, const
|
||||
// references can bind to temporary rvalues, we allow rvalue
|
||||
// converters to be chosen when the target type is T const& for some
|
||||
// T.
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Conversions begin by filling in and returning a copy of this
|
||||
// structure. The process looks up a converter in the rvalue converter
|
||||
// registry for the target type. It calls the convertible() function
|
||||
// of each registered converter, passing the source PyObject* as an
|
||||
// argument, until a non-null result is returned. This result goes in
|
||||
// the convertible field, and the converter's construct() function is
|
||||
// stored in the construct field.
|
||||
//
|
||||
// If no appropriate converter is found, conversion fails and the
|
||||
// convertible field is null. When used in argument conversion for
|
||||
// wrapped C++ functions, it causes overload resolution to reject the
|
||||
// current function but not to fail completely. If an exception is
|
||||
// thrown, overload resolution stops and the exception propagates back
|
||||
// through the caller.
|
||||
//
|
||||
// If an lvalue converter is matched, its convertible() function is
|
||||
// expected to return a pointer to the stored T object; its
|
||||
// construct() function will be NULL. The convertible() function of
|
||||
// rvalue converters may return any non-singular pointer; the actual
|
||||
// target object will only be available once the converter's
|
||||
// construct() function is called.
|
||||
struct rvalue_from_python_stage1_data
|
||||
{
|
||||
void* convertible;
|
||||
constructor_function construct;
|
||||
};
|
||||
|
||||
// Augments rvalue_from_python_stage1_data by adding storage for
|
||||
// constructing an object of remove_reference<T>::type. The
|
||||
// construct() function of rvalue converters (stored in m_construct
|
||||
// above) will cast the rvalue_from_python_stage1_data to an
|
||||
// appropriate instantiation of this template in order to access that
|
||||
// storage.
|
||||
template <class T>
|
||||
struct rvalue_from_python_storage
|
||||
{
|
||||
rvalue_from_python_stage1_data stage1;
|
||||
|
||||
// Storage for the result, in case an rvalue must be constructed
|
||||
typename python::detail::referent_storage<
|
||||
typename add_reference<T>::type
|
||||
>::type storage;
|
||||
};
|
||||
|
||||
// Augments rvalue_from_python_storage<T> with a destructor. If
|
||||
// stage1.convertible == storage.bytes, it indicates that an object of
|
||||
// remove_reference<T>::type has been constructed in storage and
|
||||
// should will be destroyed in ~rvalue_from_python_data(). It is
|
||||
// crucial that successful rvalue conversions establish this equality
|
||||
// and that unsuccessful ones do not.
|
||||
template <class T>
|
||||
struct rvalue_from_python_data : rvalue_from_python_storage<T>
|
||||
{
|
||||
# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
|
||||
&& (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \
|
||||
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) \
|
||||
&& !defined(BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing this */
|
||||
// This must always be a POD struct with m_data its first member.
|
||||
BOOST_STATIC_ASSERT(BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,stage1) == 0);
|
||||
# endif
|
||||
|
||||
// The usual constructor
|
||||
rvalue_from_python_data(rvalue_from_python_stage1_data const&);
|
||||
|
||||
// This constructor just sets m_convertible -- used by
|
||||
// implicitly_convertible<> to perform the final step of the
|
||||
// conversion, where the construct() function is already known.
|
||||
rvalue_from_python_data(void* convertible);
|
||||
|
||||
// Destroys any object constructed in the storage.
|
||||
~rvalue_from_python_data();
|
||||
private:
|
||||
typedef typename add_reference<typename add_cv<T>::type>::type ref_type;
|
||||
};
|
||||
|
||||
//
|
||||
// Implementataions
|
||||
//
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(rvalue_from_python_stage1_data const& stage1)
|
||||
{
|
||||
this->stage1 = stage1;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(void* convertible)
|
||||
{
|
||||
this->stage1.convertible = convertible;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::~rvalue_from_python_data()
|
||||
{
|
||||
if (this->stage1.convertible == this->storage.bytes)
|
||||
python::detail::destroy_referent<ref_type>(this->storage.bytes);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SHARED_PTR_DELETER_DWA2002121_HPP
|
||||
# define SHARED_PTR_DELETER_DWA2002121_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_DECL shared_ptr_deleter
|
||||
{
|
||||
shared_ptr_deleter(handle<> owner);
|
||||
~shared_ptr_deleter();
|
||||
|
||||
void operator()(void const*);
|
||||
|
||||
handle<> owner;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SHARED_PTR_DELETER_DWA2002121_HPP
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SHARED_PTR_FROM_PYTHON_DWA20021130_HPP
|
||||
# define SHARED_PTR_FROM_PYTHON_DWA20021130_HPP
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/converter/shared_ptr_deleter.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T>
|
||||
struct shared_ptr_from_python
|
||||
{
|
||||
shared_ptr_from_python()
|
||||
{
|
||||
converter::registry::insert(&convertible, &construct, type_id<shared_ptr<T> >());
|
||||
}
|
||||
|
||||
private:
|
||||
static void* convertible(PyObject* p)
|
||||
{
|
||||
if (p == Py_None)
|
||||
return p;
|
||||
|
||||
return converter::get_lvalue_from_python(p, registered<T>::converters);
|
||||
}
|
||||
|
||||
static void construct(PyObject* source, rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
void* const storage = ((converter::rvalue_from_python_storage<shared_ptr<T> >*)data)->storage.bytes;
|
||||
// Deal with the "None" case.
|
||||
if (data->convertible == source)
|
||||
new (storage) shared_ptr<T>();
|
||||
else
|
||||
new (storage) shared_ptr<T>(
|
||||
static_cast<T*>(data->convertible),
|
||||
shared_ptr_deleter(handle<>(borrowed(source)))
|
||||
);
|
||||
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SHARED_PTR_FROM_PYTHON_DWA20021130_HPP
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SHARED_PTR_TO_PYTHON_DWA2003224_HPP
|
||||
# define SHARED_PTR_TO_PYTHON_DWA2003224_HPP
|
||||
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <boost/python/converter/shared_ptr_deleter.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <boost/get_pointer.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T>
|
||||
PyObject* shared_ptr_to_python(shared_ptr<T> const& x)
|
||||
{
|
||||
if (!x)
|
||||
return python::detail::none();
|
||||
else if (shared_ptr_deleter* d = boost::get_deleter<shared_ptr_deleter>(x))
|
||||
return incref( get_pointer( d->owner ) );
|
||||
else
|
||||
return converter::registered<shared_ptr<T> const&>::converters.to_python(&x);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SHARED_PTR_TO_PYTHON_DWA2003224_HPP
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
# define TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// The type of stored function pointers which actually do conversion
|
||||
// by-value. The void* points to the object to be converted, and
|
||||
// type-safety is preserved through runtime registration.
|
||||
typedef PyObject* (*to_python_function_t)(void const*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
# define COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R>
|
||||
struct copy_const_reference_expects_a_const_reference_return_type
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
struct copy_const_reference
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::if_c<
|
||||
detail::is_reference_to_const<T>::value
|
||||
, to_python_value<T>
|
||||
, detail::copy_const_reference_expects_a_const_reference_return_type<T>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
# define COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R>
|
||||
struct copy_non_const_reference_expects_a_non_const_reference_return_type
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
struct copy_non_const_reference
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::if_c<
|
||||
boost::python::detail::is_reference_to_non_const<T>::value
|
||||
, to_python_value<T>
|
||||
, detail::copy_non_const_reference_expects_a_non_const_reference_return_type<T>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
@@ -1,324 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DATA_MEMBERS_DWA2002328_HPP
|
||||
# define DATA_MEMBERS_DWA2002328_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
|
||||
# include <boost/python/return_value_policy.hpp>
|
||||
# include <boost/python/return_by_value.hpp>
|
||||
# include <boost/python/return_internal_reference.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/is_member_pointer.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
# endif
|
||||
|
||||
# include <boost/mpl/apply_if.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/vector/vector10.hpp>
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
//
|
||||
// This file defines the make_getter and make_setter function
|
||||
// families, which are responsible for turning pointers, references,
|
||||
// and pointers-to-data-members into callable Python objects which
|
||||
// can be used for attribute access on wrapped classes.
|
||||
//
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// A small function object which handles the getting and setting of
|
||||
// data members.
|
||||
template <class Data, class Class>
|
||||
struct member
|
||||
{
|
||||
private:
|
||||
typedef typename add_const<Data>::type data_const;
|
||||
typedef typename add_reference<data_const>::type data_cref;
|
||||
|
||||
public:
|
||||
member(Data Class::*which) : m_which(which) {}
|
||||
|
||||
Data& operator()(Class& c) const
|
||||
{
|
||||
return c.*m_which;
|
||||
}
|
||||
|
||||
void operator()(Class& c, data_cref d) const
|
||||
{
|
||||
c.*m_which = d;
|
||||
}
|
||||
private:
|
||||
Data Class::*m_which;
|
||||
};
|
||||
|
||||
// A small function object which handles the getting and setting of
|
||||
// non-member objects.
|
||||
template <class Data>
|
||||
struct datum
|
||||
{
|
||||
private:
|
||||
typedef typename add_const<Data>::type data_const;
|
||||
typedef typename add_reference<data_const>::type data_cref;
|
||||
|
||||
public:
|
||||
datum(Data *which) : m_which(which) {}
|
||||
|
||||
Data& operator()() const
|
||||
{
|
||||
return *m_which;
|
||||
}
|
||||
|
||||
void operator()(data_cref d) const
|
||||
{
|
||||
*m_which = d;
|
||||
}
|
||||
private:
|
||||
Data *m_which;
|
||||
};
|
||||
|
||||
//
|
||||
// Helper metafunction for determining the default CallPolicy to use
|
||||
// for attribute access. If T is a [reference to a] class type X
|
||||
// whose conversion to python would normally produce a new copy of X
|
||||
// in a wrapped X class instance (as opposed to types such as
|
||||
// std::string, which are converted to native Python types, and
|
||||
// smart pointer types which produce a wrapped class instance of the
|
||||
// pointee type), to-python conversions will attempt to produce an
|
||||
// object which refers to the original C++ object, rather than a
|
||||
// copy. See default_member_getter_policy for rationale.
|
||||
//
|
||||
template <class T>
|
||||
struct default_getter_by_ref
|
||||
: mpl::and_<
|
||||
mpl::bool_<
|
||||
to_python_value<
|
||||
typename add_reference<typename add_const<T>::type>::type
|
||||
>::uses_registry
|
||||
>
|
||||
, is_reference_to_class<
|
||||
typename add_reference<typename add_const<T>::type>::type
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
// Metafunction computing the default CallPolicy to use for reading
|
||||
// data members
|
||||
//
|
||||
// If it's a regular class type (not an object manager or other
|
||||
// type for which we have to_python specializations, use
|
||||
// return_internal_reference so that we can do things like
|
||||
// x.y.z = 1
|
||||
// and get the right result.
|
||||
template <class T>
|
||||
struct default_member_getter_policy
|
||||
: mpl::if_<
|
||||
default_getter_by_ref<T>
|
||||
, return_internal_reference<>
|
||||
, return_value_policy<return_by_value>
|
||||
>
|
||||
{};
|
||||
|
||||
// Metafunction computing the default CallPolicy to use for reading
|
||||
// non-member data.
|
||||
template <class T>
|
||||
struct default_datum_getter_policy
|
||||
: mpl::if_<
|
||||
default_getter_by_ref<T>
|
||||
, return_value_policy<reference_existing_object>
|
||||
, return_value_policy<return_by_value>
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// make_getter helper function family -- These helpers to
|
||||
// boost::python::make_getter are used to dispatch behavior. The
|
||||
// third argument is a workaround for a CWPro8 partial ordering bug
|
||||
// with pointers to data members. It should be convertible to
|
||||
// mpl::true_ iff the first argument is a pointer-to-member, and
|
||||
// mpl::false_ otherwise. The fourth argument is for compilers
|
||||
// which don't support partial ordering at all and should always be
|
||||
// passed 0L.
|
||||
//
|
||||
|
||||
#if BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
|
||||
template <class D, class P>
|
||||
inline object make_getter(D& d, P& p, mpl::false_, ...);
|
||||
#endif
|
||||
|
||||
// Handle non-member pointers with policies
|
||||
template <class D, class Policies>
|
||||
inline object make_getter(D* d, Policies const& policies, mpl::false_, int)
|
||||
{
|
||||
return python::make_function(
|
||||
detail::datum<D>(d), policies, mpl::vector1<D&>()
|
||||
);
|
||||
}
|
||||
|
||||
// Handle non-member pointers without policies
|
||||
template <class D>
|
||||
inline object make_getter(D* d, not_specified, mpl::false_, long)
|
||||
{
|
||||
typedef typename default_datum_getter_policy<D>::type policies;
|
||||
return detail::make_getter(d, policies(), mpl::false_(), 0);
|
||||
}
|
||||
|
||||
// Handle pointers-to-members with policies
|
||||
template <class C, class D, class Policies>
|
||||
inline object make_getter(D C::*pm, Policies const& policies, mpl::true_, int)
|
||||
{
|
||||
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
||||
typedef typename remove_cv<C>::type Class;
|
||||
#else
|
||||
typedef C Class;
|
||||
#endif
|
||||
return python::make_function(
|
||||
detail::member<D,Class>(pm)
|
||||
, policies
|
||||
, mpl::vector2<D&,Class&>()
|
||||
);
|
||||
}
|
||||
|
||||
// Handle pointers-to-members without policies
|
||||
template <class C, class D>
|
||||
inline object make_getter(D C::*pm, not_specified, mpl::true_, long)
|
||||
{
|
||||
typedef typename default_member_getter_policy<D>::type policies;
|
||||
return detail::make_getter(pm, policies(), mpl::true_(), 0);
|
||||
}
|
||||
|
||||
// Handle references
|
||||
template <class D, class P>
|
||||
inline object make_getter(D& d, P& p, mpl::false_, ...)
|
||||
{
|
||||
// Just dispatch to the handler for pointer types.
|
||||
return detail::make_getter(&d, p, mpl::false_(), 0L);
|
||||
}
|
||||
|
||||
//
|
||||
// make_setter helper function family -- These helpers to
|
||||
// boost::python::make_setter are used to dispatch behavior. The
|
||||
// third argument is for compilers which don't support partial
|
||||
// ordering at all and should always be passed 0.
|
||||
//
|
||||
|
||||
|
||||
// Handle non-member pointers
|
||||
template <class D, class Policies>
|
||||
inline object make_setter(D* p, Policies const& policies, mpl::false_, int)
|
||||
{
|
||||
return python::make_function(
|
||||
detail::datum<D>(p), policies, mpl::vector2<void,D const&>()
|
||||
);
|
||||
}
|
||||
|
||||
// Handle pointers-to-members
|
||||
template <class C, class D, class Policies>
|
||||
inline object make_setter(D C::*pm, Policies const& policies, mpl::true_, int)
|
||||
{
|
||||
return python::make_function(
|
||||
detail::member<D,C>(pm)
|
||||
, policies
|
||||
, mpl::vector3<void, C&, D const&>()
|
||||
);
|
||||
}
|
||||
|
||||
// Handle references
|
||||
template <class D, class Policies>
|
||||
inline object make_setter(D& x, Policies const& policies, mpl::false_, ...)
|
||||
{
|
||||
return detail::make_setter(&x, policies, mpl::false_(), 0L);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// make_getter function family -- build a callable object which
|
||||
// retrieves data through the first argument and is appropriate for
|
||||
// use as the `get' function in Python properties . The second,
|
||||
// policies argument, is optional. We need both D& and D const&
|
||||
// overloads in order be able to handle rvalues.
|
||||
//
|
||||
template <class D, class Policies>
|
||||
inline object make_getter(D& d, Policies const& policies)
|
||||
{
|
||||
return detail::make_getter(d, policies, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
|
||||
template <class D, class Policies>
|
||||
inline object make_getter(D const& d, Policies const& policies)
|
||||
{
|
||||
return detail::make_getter(d, policies, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
|
||||
template <class D>
|
||||
inline object make_getter(D& x)
|
||||
{
|
||||
detail::not_specified policy;
|
||||
return detail::make_getter(x, policy, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
|
||||
# if !BOOST_WORKAROUND(__EDG_VERSION__, <= 238) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
template <class D>
|
||||
inline object make_getter(D const& d)
|
||||
{
|
||||
detail::not_specified policy;
|
||||
return detail::make_getter(d, policy, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
# endif
|
||||
|
||||
//
|
||||
// make_setter function family -- build a callable object which
|
||||
// writes data through the first argument and is appropriate for
|
||||
// use as the `set' function in Python properties . The second,
|
||||
// policies argument, is optional. We need both D& and D const&
|
||||
// overloads in order be able to handle rvalues.
|
||||
//
|
||||
template <class D, class Policies>
|
||||
inline object make_setter(D& x, Policies const& policies)
|
||||
{
|
||||
return detail::make_setter(x, policies, is_member_pointer<D>(), 0);
|
||||
}
|
||||
|
||||
template <class D, class Policies>
|
||||
inline object make_setter(D const& x, Policies const& policies)
|
||||
{
|
||||
return detail::make_setter(x, policies, is_member_pointer<D>(), 0);
|
||||
}
|
||||
|
||||
template <class D>
|
||||
inline object make_setter(D& x)
|
||||
{
|
||||
return detail::make_setter(x, default_call_policies(), is_member_pointer<D>(), 0);
|
||||
}
|
||||
|
||||
# if !(BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(__EDG_VERSION__, <= 238))
|
||||
template <class D>
|
||||
inline object make_setter(D const& x)
|
||||
{
|
||||
return detail::make_setter(x, default_call_policies(), is_member_pointer<D>(), 0);
|
||||
}
|
||||
# endif
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DATA_MEMBERS_DWA2002328_HPP
|
||||
@@ -1,115 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_DWA200292_HPP
|
||||
# define DEF_DWA200292_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/detail/def_helper.hpp>
|
||||
# include <boost/python/detail/overloads_fwd.hpp>
|
||||
# include <boost/python/scope.hpp>
|
||||
# include <boost/python/signature.hpp>
|
||||
# include <boost/python/detail/scope.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace error
|
||||
{
|
||||
// Compile-time error messages
|
||||
template <bool> struct multiple_functions_passed_to_def;
|
||||
template <> struct multiple_functions_passed_to_def<false> { typedef char type; };
|
||||
}
|
||||
|
||||
//
|
||||
// def_from_helper --
|
||||
//
|
||||
// Use a def_helper to define a regular wrapped function in the current scope.
|
||||
template <class F, class Helper>
|
||||
void def_from_helper(
|
||||
char const* name, F const& fn, Helper const& helper)
|
||||
{
|
||||
// Must not try to use default implementations except with method definitions.
|
||||
typedef typename error::multiple_functions_passed_to_def<
|
||||
Helper::has_default_implementation
|
||||
>::type assertion;
|
||||
|
||||
detail::scope_setattr_doc(
|
||||
name, boost::python::make_function(
|
||||
fn
|
||||
, helper.policies()
|
||||
, helper.keywords())
|
||||
, helper.doc()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// These two overloads discriminate between def() as applied to
|
||||
// regular functions and def() as applied to the result of
|
||||
// BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to
|
||||
// discriminate.
|
||||
//
|
||||
template <class Fn, class A1>
|
||||
void
|
||||
def_maybe_overloads(
|
||||
char const* name
|
||||
, Fn fn
|
||||
, A1 const& a1
|
||||
, ...)
|
||||
{
|
||||
detail::def_from_helper(name, fn, def_helper<A1>(a1));
|
||||
}
|
||||
|
||||
template <class StubsT, class SigT>
|
||||
void def_maybe_overloads(
|
||||
char const* name
|
||||
, SigT sig
|
||||
, StubsT const& stubs
|
||||
, detail::overloads_base const*)
|
||||
{
|
||||
scope current;
|
||||
|
||||
detail::define_with_defaults(
|
||||
name, stubs, current, detail::get_signature(sig));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
object make_function1(T fn, ...) { return make_function(fn); }
|
||||
|
||||
inline
|
||||
object make_function1(object const& x, object const*) { return x; }
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
void def(char const* name, Fn fn)
|
||||
{
|
||||
detail::scope_setattr_doc(name, detail::make_function1(fn, &fn), 0);
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T>
|
||||
void def(char const* name, Arg1T arg1, Arg2T const& arg2)
|
||||
{
|
||||
detail::def_maybe_overloads(name, arg1, arg2, &arg2);
|
||||
}
|
||||
|
||||
template <class F, class A1, class A2>
|
||||
void def(char const* name, F f, A1 const& a1, A2 const& a2)
|
||||
{
|
||||
detail::def_from_helper(name, f, detail::def_helper<A1,A2>(a1,a2));
|
||||
}
|
||||
|
||||
template <class F, class A1, class A2, class A3>
|
||||
void def(char const* name, F f, A1 const& a1, A2 const& a2, A3 const& a3)
|
||||
{
|
||||
detail::def_from_helper(name, f, detail::def_helper<A1,A2,A3>(a1,a2,a3));
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEF_DWA200292_HPP
|
||||
@@ -1,87 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_VISITOR_DWA2003810_HPP
|
||||
# define DEF_VISITOR_DWA2003810_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class DerivedVisitor> class def_visitor;
|
||||
template <class T, class X1, class X2, class X3> class class_;
|
||||
|
||||
class def_visitor_access
|
||||
{
|
||||
# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
// Tasteless as this may seem, making all members public allows member templates
|
||||
// to work in the absence of member template friends.
|
||||
public:
|
||||
# else
|
||||
template <class Derived> friend class def_visitor;
|
||||
# endif
|
||||
|
||||
// unnamed visit, c.f. init<...>, container suites
|
||||
template <class V, class classT>
|
||||
static void visit(V const& v, classT& c)
|
||||
{
|
||||
v.derived_visitor().visit(c);
|
||||
}
|
||||
|
||||
// named visit, c.f. object, pure_virtual
|
||||
template <class V, class classT, class OptionalArgs>
|
||||
static void visit(
|
||||
V const& v
|
||||
, classT& c
|
||||
, char const* name
|
||||
, OptionalArgs const& options
|
||||
)
|
||||
{
|
||||
v.derived_visitor().visit(c, name, options);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class DerivedVisitor>
|
||||
class def_visitor
|
||||
{
|
||||
friend class def_visitor_access;
|
||||
|
||||
# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
// Tasteless as this may seem, making all members public allows member templates
|
||||
// to work in the absence of member template friends.
|
||||
public:
|
||||
# else
|
||||
template <class T, class X1, class X2, class X3> friend class class_;
|
||||
# endif
|
||||
|
||||
// unnamed visit, c.f. init<...>, container suites
|
||||
template <class classT>
|
||||
void visit(classT& c) const
|
||||
{
|
||||
def_visitor_access::visit(*this, c);
|
||||
}
|
||||
|
||||
// named visit, c.f. object, pure_virtual
|
||||
template <class classT, class OptionalArgs>
|
||||
void visit(classT& c, char const* name, OptionalArgs const& options) const
|
||||
{
|
||||
def_visitor_access::visit(*this, c, name, options);
|
||||
}
|
||||
|
||||
protected:
|
||||
DerivedVisitor const& derived_visitor() const
|
||||
{
|
||||
return static_cast<DerivedVisitor const&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEF_VISITOR_DWA2003810_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
# define DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// for "readable" error messages
|
||||
template <class T> struct specify_a_return_value_policy_to_wrap_functions_returning
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
struct default_result_converter;
|
||||
|
||||
struct default_call_policies
|
||||
{
|
||||
// Ownership of this argument tuple will ultimately be adopted by
|
||||
// the caller.
|
||||
template <class ArgumentPackage>
|
||||
static bool precall(ArgumentPackage const&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pass the result through
|
||||
template <class ArgumentPackage>
|
||||
static PyObject* postcall(ArgumentPackage const&, PyObject* result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef default_result_converter result_converter;
|
||||
typedef PyObject* argument_package;
|
||||
};
|
||||
|
||||
struct default_result_converter
|
||||
{
|
||||
template <class R>
|
||||
struct apply
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_illegal = is_reference<R>::value || is_pointer<R>::value);
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
is_illegal
|
||||
, detail::specify_a_return_value_policy_to_wrap_functions_returning<R>
|
||||
, boost::python::to_python_value<
|
||||
typename add_reference<typename add_const<R>::type>::type
|
||||
>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
// Exceptions for c strings an PyObject*s
|
||||
template <>
|
||||
struct default_result_converter::apply<char const*>
|
||||
{
|
||||
typedef boost::python::to_python_value<char const*const&> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct default_result_converter::apply<PyObject*>
|
||||
{
|
||||
typedef boost::python::to_python_value<PyObject*const&> type;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef AIX_INIT_MODULE_DWA2002529_HPP
|
||||
# define AIX_INIT_MODULE_DWA2002529_HPP
|
||||
# ifdef _AIX
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <cstdio>
|
||||
# ifdef __KCC
|
||||
# include <iostream> // this works around a problem in KCC 4.0f
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef PyObject* (*so_load_function)(char*,char*,FILE*);
|
||||
}
|
||||
|
||||
void aix_init_module(so_load_function, char const* name, void (*init_module)());
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
# endif
|
||||
|
||||
#endif // AIX_INIT_MODULE_DWA2002529_HPP
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
#define BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
inline long len(object const& obj)
|
||||
{
|
||||
long result = PyObject_Length(obj.ptr());
|
||||
if (PyErr_Occurred()) throw_error_already_set();
|
||||
return result;
|
||||
}
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
@@ -1,112 +0,0 @@
|
||||
#ifndef BORROWED_PTR_DWA20020601_HPP
|
||||
# define BORROWED_PTR_DWA20020601_HPP
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template<class T> class borrowed
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x3000
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T>*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> const*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> volatile*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> const volatile*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
template<typename T>
|
||||
struct is_borrowed
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
template<typename T>
|
||||
struct is_borrowed<borrowed<T> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<T*>
|
||||
: is_borrowed<typename remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
|
||||
# else // no partial specialization
|
||||
|
||||
typedef char (&yes_borrowed_ptr_t)[1];
|
||||
typedef char (&no_borrowed_ptr_t)[2];
|
||||
|
||||
no_borrowed_ptr_t is_borrowed_ptr_test(...);
|
||||
|
||||
template <class T>
|
||||
typename mpl::if_c<
|
||||
is_pointer<T>::value
|
||||
, T
|
||||
, int
|
||||
>::type
|
||||
is_borrowed_ptr_test1(boost::type<T>);
|
||||
|
||||
template<typename T>
|
||||
yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed<T> const volatile*);
|
||||
|
||||
template<typename T>
|
||||
class is_borrowed_ptr
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type<T>())))
|
||||
== sizeof(detail::yes_borrowed_ptr_t)));
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
|
||||
{
|
||||
return (T*)p;
|
||||
}
|
||||
|
||||
}} // namespace boost::python::detail
|
||||
|
||||
#endif // #ifndef BORROWED_PTR_DWA20020601_HPP
|
||||
@@ -1,220 +0,0 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef CALLER_DWA20021121_HPP
|
||||
# define CALLER_DWA20021121_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
|
||||
# include <boost/python/detail/invoke.hpp>
|
||||
# include <boost/python/detail/signature.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/python/arg_from_python.hpp>
|
||||
# include <boost/python/converter/context_result_converter.hpp>
|
||||
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/dec.hpp>
|
||||
# include <boost/preprocessor/if.hpp>
|
||||
# include <boost/preprocessor/iteration/local.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||
# include <boost/preprocessor/repetition/repeat.hpp>
|
||||
|
||||
# include <boost/compressed_pair.hpp>
|
||||
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
# include <boost/mpl/apply.hpp>
|
||||
# include <boost/mpl/apply_if.hpp>
|
||||
# include <boost/mpl/identity.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/mpl/at.hpp>
|
||||
# include <boost/mpl/int.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <int N>
|
||||
inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
|
||||
{
|
||||
return PyTuple_GET_ITEM(args_,N);
|
||||
}
|
||||
|
||||
inline unsigned arity(PyObject* const& args_)
|
||||
{
|
||||
return PyTuple_GET_SIZE(args_);
|
||||
}
|
||||
|
||||
// This "result converter" is really just used as
|
||||
// a dispatch tag to invoke(...), selecting the appropriate
|
||||
// implementation
|
||||
typedef int void_result_to_python;
|
||||
|
||||
// Given a model of CallPolicies and a C++ result type, this
|
||||
// metafunction selects the appropriate converter to use for
|
||||
// converting the result to python.
|
||||
template <class Policies, class Result>
|
||||
struct select_result_converter
|
||||
: mpl::apply_if<
|
||||
is_same<Result,void>
|
||||
, mpl::identity<void_result_to_python>
|
||||
, mpl::apply1<typename Policies::result_converter,Result>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <class ArgPackage, class ResultConverter>
|
||||
inline ResultConverter create_result_converter(
|
||||
ArgPackage const& args_
|
||||
, ResultConverter*
|
||||
, converter::context_result_converter*
|
||||
)
|
||||
{
|
||||
return ResultConverter(args_);
|
||||
}
|
||||
|
||||
template <class ArgPackage, class ResultConverter>
|
||||
inline ResultConverter create_result_converter(
|
||||
ArgPackage const& args_
|
||||
, ResultConverter*
|
||||
, ...
|
||||
)
|
||||
{
|
||||
return ResultConverter();
|
||||
}
|
||||
|
||||
template <unsigned> struct caller_arity;
|
||||
|
||||
template <class F, class CallPolicies, class Sig>
|
||||
struct caller;
|
||||
|
||||
# define BOOST_PYTHON_NEXT(init,name,n) \
|
||||
typedef BOOST_PP_IF(n,typename BOOST_PP_CAT(name,BOOST_PP_DEC(n)) ::next, init) name##n;
|
||||
|
||||
# define BOOST_PYTHON_ARG_CONVERTER(n) \
|
||||
BOOST_PYTHON_NEXT(typename first::next, arg_iter,n) \
|
||||
typedef arg_from_python<BOOST_DEDUCED_TYPENAME arg_iter##n::type> c_t##n; \
|
||||
c_t##n c##n(get(mpl::int_<n>(), inner_args)); \
|
||||
if (!c##n.convertible()) \
|
||||
return 0;
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY + 1, <boost/python/detail/caller.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_ARG_CONVERTER
|
||||
# undef BOOST_PYTHON_NEXT
|
||||
|
||||
// A metafunction returning the base class used for caller<class F,
|
||||
// class ConverterGenerators, class CallPolicies, class Sig>.
|
||||
template <class F, class CallPolicies, class Sig>
|
||||
struct caller_base_select
|
||||
{
|
||||
enum { arity = mpl::size<Sig>::value - 1 };
|
||||
typedef typename caller_arity<arity>::template impl<F,CallPolicies,Sig> type;
|
||||
};
|
||||
|
||||
// A function object type which wraps C++ objects as Python callable
|
||||
// objects.
|
||||
//
|
||||
// Template Arguments:
|
||||
//
|
||||
// F -
|
||||
// the C++ `function object' that will be called. Might
|
||||
// actually be any data for which an appropriate invoke_tag() can
|
||||
// be generated. invoke(...) takes care of the actual invocation syntax.
|
||||
//
|
||||
// CallPolicies -
|
||||
// The precall, postcall, and what kind of resultconverter to
|
||||
// generate for mpl::front<Sig>::type
|
||||
//
|
||||
// Sig -
|
||||
// The `intended signature' of the function. An MPL sequence
|
||||
// beginning with a result type and continuing with a list of
|
||||
// argument types.
|
||||
template <class F, class CallPolicies, class Sig>
|
||||
struct caller
|
||||
: caller_base_select<F,CallPolicies,Sig>::type
|
||||
{
|
||||
typedef typename caller_base_select<
|
||||
F,CallPolicies,Sig
|
||||
>::type base;
|
||||
|
||||
typedef PyObject* result_type;
|
||||
|
||||
caller(F f, CallPolicies p) : base(f,p) {}
|
||||
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // CALLER_DWA20021121_HPP
|
||||
|
||||
#else
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <>
|
||||
struct caller_arity<N>
|
||||
{
|
||||
template <class F, class Policies, class Sig>
|
||||
struct impl
|
||||
{
|
||||
impl(F f, Policies p) : m_data(f,p) {}
|
||||
|
||||
PyObject* operator()(PyObject* args_, PyObject*) // eliminate
|
||||
// this
|
||||
// trailing
|
||||
// keyword dict
|
||||
{
|
||||
typedef typename mpl::begin<Sig>::type first;
|
||||
typedef typename first::type result_t;
|
||||
typedef typename select_result_converter<Policies, result_t>::type result_converter;
|
||||
typedef typename Policies::argument_package argument_package;
|
||||
|
||||
argument_package inner_args(args_);
|
||||
|
||||
# if N
|
||||
# define BOOST_PP_LOCAL_MACRO(i) BOOST_PYTHON_ARG_CONVERTER(i)
|
||||
# define BOOST_PP_LOCAL_LIMITS (0, N-1)
|
||||
# include BOOST_PP_LOCAL_ITERATE()
|
||||
# endif
|
||||
// all converters have been checked. Now we can do the
|
||||
// precall part of the policy
|
||||
if (!m_data.second().precall(inner_args))
|
||||
return 0;
|
||||
|
||||
PyObject* result = detail::invoke(
|
||||
detail::invoke_tag<result_t,F>()
|
||||
, create_result_converter(args_, (result_converter*)0, (result_converter*)0)
|
||||
, m_data.first()
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(N, c)
|
||||
);
|
||||
|
||||
return m_data.second().postcall(inner_args, result);
|
||||
}
|
||||
|
||||
static unsigned min_arity() { return N; }
|
||||
|
||||
static signature_element const* signature()
|
||||
{
|
||||
return detail::signature<Sig>::elements();
|
||||
}
|
||||
|
||||
private:
|
||||
compressed_pair<F,Policies> m_data;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_PP_IS_ITERATING
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CHAR_ARRAY_DWA2002129_HPP
|
||||
# define CHAR_ARRAY_DWA2002129_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// This little package is used to transmit the number of arguments
|
||||
// from the helper functions below to the sizeof() expression below.
|
||||
// Because we can never have an array of fewer than 1 element, we
|
||||
// add 1 to n and then subtract 1 from the result of sizeof() below.
|
||||
template <int n>
|
||||
struct char_array
|
||||
{
|
||||
char elements[n+1];
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CHAR_ARRAY_DWA2002129_HPP
|
||||
@@ -1,111 +0,0 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// The author gratefully acknowleges the support of Dragon Systems, Inc., in
|
||||
// producing this work.
|
||||
|
||||
// Revision History:
|
||||
// 04 Mar 01 Some fixes so it will compile with Intel C++ (Dave Abrahams)
|
||||
|
||||
#ifndef CONFIG_DWA052200_H_
|
||||
# define CONFIG_DWA052200_H_
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
# ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
// A gcc bug forces some symbols into the global namespace
|
||||
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
|
||||
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE
|
||||
# define BOOST_PYTHON_CONVERSION
|
||||
# define BOOST_PYTHON_IMPORT_CONVERSION(x) using ::x
|
||||
# else
|
||||
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE namespace boost { namespace python {
|
||||
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE }} // namespace boost::python
|
||||
# define BOOST_PYTHON_CONVERSION boost::python
|
||||
# define BOOST_PYTHON_IMPORT_CONVERSION(x) void never_defined() // so we can follow the macro with a ';'
|
||||
# endif
|
||||
|
||||
# if defined(BOOST_MSVC)
|
||||
# if _MSC_VER <= 1200
|
||||
# define BOOST_MSVC6_OR_EARLIER 1
|
||||
# endif
|
||||
|
||||
# pragma warning (disable : 4786) // disable truncated debug symbols
|
||||
# pragma warning (disable : 4251) // disable exported dll function
|
||||
# pragma warning (disable : 4800) //'int' : forcing value to bool 'true' or 'false'
|
||||
# pragma warning (disable : 4275) // non dll-interface class
|
||||
|
||||
# elif defined(__ICL) && __ICL < 600 // Intel C++ 5
|
||||
|
||||
# pragma warning(disable: 985) // identifier was truncated in debug information
|
||||
|
||||
# endif
|
||||
|
||||
// The STLport puts all of the standard 'C' library names in std (as far as the
|
||||
// user is concerned), but without it you need a fix if you're using MSVC or
|
||||
// Intel C++
|
||||
# if defined(BOOST_MSVC_STD_ITERATOR)
|
||||
# define BOOST_CSTD_
|
||||
# else
|
||||
# define BOOST_CSTD_ std
|
||||
# endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Set up dll import/export options:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// backwards compatibility:
|
||||
#ifdef BOOST_PYTHON_STATIC_LIB
|
||||
# define BOOST_PYTHON_STATIC_LINK
|
||||
# elif !defined(BOOST_PYTHON_DYNAMIC_LIB)
|
||||
# define BOOST_PYTHON_DYNAMIC_LIB
|
||||
#endif
|
||||
|
||||
#if defined(__MWERKS__) \
|
||||
|| (defined(__DECCXX_VER) && __DECCXX_VER <= 60590002) \
|
||||
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
|
||||
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_PYTHON_DYNAMIC_LIB) && (defined(_WIN32) || defined(__CYGWIN__))
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __declspec(dllexport)
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL __declspec(dllimport)
|
||||
# endif
|
||||
|
||||
// MinGW, at least, has some problems exporting template instantiations
|
||||
# if defined(__GNUC__) && __GNUC__ < 3 && !defined(__CYGWIN__)
|
||||
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL
|
||||
# define BOOST_PYTHON_DECL
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_EXPORT
|
||||
# define BOOST_PYTHON_EXPORT extern
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_PYTHON_NO_TEMPLATE_EXPORT)
|
||||
# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) BOOST_PYTHON_EXPORT template class BOOST_PYTHON_DECL instantiation
|
||||
#else
|
||||
# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) struct ThIsTyPeNeVeRuSeD
|
||||
#endif
|
||||
|
||||
#if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590031)
|
||||
// Replace broken Tru64/cxx offsetof macro
|
||||
# define BOOST_PYTHON_OFFSETOF(s_name, s_member) \
|
||||
((size_t)__INTADDR__(&(((s_name *)0)->s_member)))
|
||||
#else
|
||||
# define BOOST_PYTHON_OFFSETOF offsetof
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_DWA052200_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
# define CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_pointee(void* storage, Arg& x
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
, T const volatile*
|
||||
# else
|
||||
, T const*
|
||||
# endif
|
||||
)
|
||||
{
|
||||
new (storage) T(x);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent_impl(void* storage, Arg& x, T&(*)())
|
||||
{
|
||||
construct_pointee(storage, x, (T*)0);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent(void* storage, Arg const& x, T(*tag)() = 0)
|
||||
{
|
||||
construct_referent_impl(storage, x, tag);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent(void* storage, Arg& x, T(*tag)() = 0)
|
||||
{
|
||||
construct_referent_impl(storage, x, tag);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONVERTIBLE_DWA2002614_HPP
|
||||
# define CONVERTIBLE_DWA2002614_HPP
|
||||
|
||||
# if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 241
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/type_traits/conversion_traits.hpp>
|
||||
# endif
|
||||
|
||||
// Supplies a runtime is_convertible check which can be used with tag
|
||||
// dispatching to work around the Metrowerks Pro7 limitation with boost::is_convertible
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
typedef char* yes_convertible;
|
||||
typedef int* no_convertible;
|
||||
|
||||
template <class Target>
|
||||
struct convertible
|
||||
{
|
||||
# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 241 || __EDG_VERSION__ == 238
|
||||
static inline no_convertible check(...) { return 0; }
|
||||
static inline yes_convertible check(Target) { return 0; }
|
||||
# else
|
||||
template <class X>
|
||||
static inline typename mpl::if_c<
|
||||
is_convertible<X,Target>::value
|
||||
, yes_convertible
|
||||
, no_convertible
|
||||
>::type check(X const&) { return 0; }
|
||||
# endif
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CONVERTIBLE_DWA2002614_HPP
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef COPY_CTOR_MUTATES_RHS_DWA2003219_HPP
|
||||
# define COPY_CTOR_MUTATES_RHS_DWA2003219_HPP
|
||||
|
||||
#include <boost/python/detail/is_auto_ptr.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class T>
|
||||
struct copy_ctor_mutates_rhs
|
||||
: is_auto_ptr<T>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // COPY_CTOR_MUTATES_RHS_DWA2003219_HPP
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CV_CATEGORY_DWA200222_HPP
|
||||
# define CV_CATEGORY_DWA200222_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool is_const_, bool is_volatile_>
|
||||
struct cv_tag
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_const = is_const_);
|
||||
BOOST_STATIC_CONSTANT(bool, is_volatile = is_const_);
|
||||
};
|
||||
|
||||
typedef cv_tag<false,false> cv_unqualified;
|
||||
typedef cv_tag<true,false> const_;
|
||||
typedef cv_tag<false,true> volatile_;
|
||||
typedef cv_tag<true,true> const_volatile_;
|
||||
|
||||
template <class T>
|
||||
struct cv_category
|
||||
{
|
||||
// BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
|
||||
// BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
|
||||
typedef cv_tag<
|
||||
::boost::is_const<T>::value
|
||||
, ::boost::is_volatile<T>::value
|
||||
> type;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CV_CATEGORY_DWA200222_HPP
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright Gottfried Ganßauge 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef BOOST_PYTHON_DETAIL_DEALLOC_HPP_
|
||||
# define BOOST_PYTHON_DETAIL_DEALLOC_HPP_
|
||||
namespace boost { namespace python { namespace detail {
|
||||
extern "C"
|
||||
{
|
||||
inline void dealloc(PyObject* self)
|
||||
{
|
||||
PyObject_Del(self);
|
||||
}
|
||||
}
|
||||
}}} // namespace boost::python::detail
|
||||
# endif // BOOST_PYTHON_DETAIL_DEALLOC_HPP_
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
# define DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct decorated_type_info : totally_ordered<decorated_type_info>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
decorated_type_info(type_info, decoration = decoration());
|
||||
|
||||
inline bool operator<(decorated_type_info const& rhs) const;
|
||||
inline bool operator==(decorated_type_info const& rhs) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
operator type_info const&() const;
|
||||
private: // type
|
||||
typedef type_info base_id_t;
|
||||
|
||||
private: // data members
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline decorated_type_info decorated_type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return decorated_type_info(
|
||||
type_id<T>()
|
||||
, decorated_type_info::decoration(
|
||||
(is_const<T>::value || python::detail::is_reference_to_const<T>::value
|
||||
? decorated_type_info::const_ : 0)
|
||||
| (is_volatile<T>::value || python::detail::is_reference_to_volatile<T>::value
|
||||
? decorated_type_info::volatile_ : 0)
|
||||
| (is_reference<T>::value ? decorated_type_info::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline decorated_type_info::decorated_type_info(type_info base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline decorated_type_info::operator type_info const&() const
|
||||
{
|
||||
return m_base_type;
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DECREF_GUARD_DWA20021220_HPP
|
||||
# define DECREF_GUARD_DWA20021220_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct decref_guard
|
||||
{
|
||||
decref_guard(PyObject* o) : obj(o) {}
|
||||
~decref_guard() { Py_XDECREF(obj); }
|
||||
void cancel() { obj = 0; }
|
||||
private:
|
||||
PyObject* obj;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DECREF_GUARD_DWA20021220_HPP
|
||||
@@ -1,213 +0,0 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_HELPER_DWA200287_HPP
|
||||
# define DEF_HELPER_DWA200287_HPP
|
||||
|
||||
# include <boost/python/args.hpp>
|
||||
# include <boost/type_traits/ice.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/not.hpp>
|
||||
# include <boost/mpl/and.hpp>
|
||||
# include <boost/mpl/or.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/mpl/lambda.hpp>
|
||||
# include <boost/mpl/apply.hpp>
|
||||
# include <boost/tuple/tuple.hpp>
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
# include <boost/python/detail/def_helper_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct default_call_policies;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// tuple_extract<Tuple,Predicate>::extract(t) returns the first
|
||||
// element of a Tuple whose type E satisfies the given Predicate
|
||||
// applied to add_reference<E>. The Predicate must be an MPL
|
||||
// metafunction class.
|
||||
template <class Tuple, class Predicate>
|
||||
struct tuple_extract;
|
||||
|
||||
// Implementation class for when the tuple's head type does not
|
||||
// satisfy the Predicate
|
||||
template <bool matched>
|
||||
struct tuple_extract_impl
|
||||
{
|
||||
template <class Tuple, class Predicate>
|
||||
struct apply
|
||||
{
|
||||
typedef typename Tuple::head_type result_type;
|
||||
|
||||
static typename Tuple::head_type extract(Tuple const& x)
|
||||
{
|
||||
return x.get_head();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Implementation specialization for when the tuple's head type
|
||||
// satisfies the predicate
|
||||
template <>
|
||||
struct tuple_extract_impl<false>
|
||||
{
|
||||
template <class Tuple, class Predicate>
|
||||
struct apply
|
||||
{
|
||||
// recursive application of tuple_extract on the tail of the tuple
|
||||
typedef tuple_extract<typename Tuple::tail_type, Predicate> next;
|
||||
typedef typename next::result_type result_type;
|
||||
|
||||
static result_type extract(Tuple const& x)
|
||||
{
|
||||
return next::extract(x.get_tail());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// A metafunction which selects a version of tuple_extract_impl to
|
||||
// use for the implementation of tuple_extract
|
||||
template <class Tuple, class Predicate>
|
||||
struct tuple_extract_base_select
|
||||
{
|
||||
typedef typename Tuple::head_type head_type;
|
||||
typedef typename mpl::apply1<Predicate, typename add_reference<head_type>::type>::type match_t;
|
||||
BOOST_STATIC_CONSTANT(bool, match = match_t::value);
|
||||
typedef typename tuple_extract_impl<match>::template apply<Tuple,Predicate> type;
|
||||
};
|
||||
|
||||
template <class Tuple, class Predicate>
|
||||
struct tuple_extract
|
||||
: tuple_extract_base_select<
|
||||
Tuple
|
||||
, typename mpl::lambda<Predicate>::type
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Specialized extractors for the docstring, keywords, CallPolicies,
|
||||
// and default implementation of virtual functions
|
||||
//
|
||||
|
||||
template <class Tuple>
|
||||
struct doc_extract
|
||||
: tuple_extract<
|
||||
Tuple
|
||||
, mpl::not_<
|
||||
mpl::or_<
|
||||
is_reference_to_class<mpl::_1>
|
||||
, is_reference_to_member_function_pointer<mpl::_1 >
|
||||
>
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <class Tuple>
|
||||
struct keyword_extract
|
||||
: tuple_extract<Tuple, is_reference_to_keywords<mpl::_1 > >
|
||||
{
|
||||
};
|
||||
|
||||
template <class Tuple>
|
||||
struct policy_extract
|
||||
: tuple_extract<
|
||||
Tuple
|
||||
, mpl::and_<
|
||||
mpl::not_<is_same<not_specified const&,mpl::_1> >
|
||||
, is_reference_to_class<mpl::_1 >
|
||||
, mpl::not_<is_reference_to_keywords<mpl::_1 > >
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <class Tuple>
|
||||
struct default_implementation_extract
|
||||
: tuple_extract<
|
||||
Tuple
|
||||
, is_reference_to_member_function_pointer<mpl::_1 >
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// A helper class for decoding the optional arguments to def()
|
||||
// invocations, which can be supplied in any order and are
|
||||
// discriminated by their type properties. The template parameters
|
||||
// are expected to be the types of the actual (optional) arguments
|
||||
// passed to def().
|
||||
//
|
||||
template <class T1, class T2, class T3, class T4>
|
||||
struct def_helper
|
||||
{
|
||||
// A tuple type which begins with references to the supplied
|
||||
// arguments and ends with actual representatives of the default
|
||||
// types.
|
||||
typedef boost::tuples::tuple<
|
||||
T1 const&
|
||||
, T2 const&
|
||||
, T3 const&
|
||||
, T4 const&
|
||||
, default_call_policies
|
||||
, keywords<0>
|
||||
, char const*
|
||||
, void(not_specified::*)() // A function pointer type which is never an
|
||||
// appropriate default implementation
|
||||
> all_t;
|
||||
|
||||
// Constructors; these initialize an member of the tuple type
|
||||
// shown above.
|
||||
def_helper(T1 const& a1) : m_all(a1,m_nil,m_nil,m_nil) {}
|
||||
def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2,m_nil,m_nil) {}
|
||||
def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3,m_nil) {}
|
||||
def_helper(T1 const& a1, T2 const& a2, T3 const& a3, T4 const& a4) : m_all(a1,a2,a3,a4) {}
|
||||
|
||||
private: // types
|
||||
typedef typename default_implementation_extract<all_t>::result_type default_implementation_t;
|
||||
|
||||
public: // Constants which can be used for static assertions.
|
||||
|
||||
// Users must not supply a default implementation for non-class
|
||||
// methods.
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, has_default_implementation = (
|
||||
!is_same<default_implementation_t, void(not_specified::*)()>::value));
|
||||
|
||||
public: // Extractor functions which pull the appropriate value out
|
||||
// of the tuple
|
||||
char const* doc() const
|
||||
{
|
||||
return doc_extract<all_t>::extract(m_all);
|
||||
}
|
||||
|
||||
typename keyword_extract<all_t>::result_type keywords() const
|
||||
{
|
||||
return keyword_extract<all_t>::extract(m_all);
|
||||
}
|
||||
|
||||
typename policy_extract<all_t>::result_type policies() const
|
||||
{
|
||||
return policy_extract<all_t>::extract(m_all);
|
||||
}
|
||||
|
||||
default_implementation_t default_implementation() const
|
||||
{
|
||||
return default_implementation_extract<all_t>::extract(m_all);
|
||||
}
|
||||
|
||||
private: // data members
|
||||
all_t m_all;
|
||||
not_specified m_nil; // for filling in not_specified slots
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python::detail
|
||||
|
||||
#endif // DEF_HELPER_DWA200287_HPP
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_HELPER_FWD_DWA2003810_HPP
|
||||
# define DEF_HELPER_FWD_DWA2003810_HPP
|
||||
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class T1, class T2 = not_specified, class T3 = not_specified, class T4 = not_specified>
|
||||
struct def_helper;
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DEF_HELPER_FWD_DWA2003810_HPP
|
||||
@@ -1,292 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy,
|
||||
// use, modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided "as is"
|
||||
// without express or implied warranty, and with no claim as to its
|
||||
// suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#ifndef DEFAULTS_DEF_JDG20020811_HPP
|
||||
#define DEFAULTS_DEF_JDG20020811_HPP
|
||||
|
||||
#include <boost/python/detail/defaults_gen.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/preprocessor/iterate.hpp>
|
||||
#include <boost/python/class_fwd.hpp>
|
||||
#include <boost/python/scope.hpp>
|
||||
#include <boost/preprocessor/debug/line.hpp>
|
||||
#include <boost/python/detail/scope.hpp>
|
||||
#include <boost/python/detail/make_keyword_range_fn.hpp>
|
||||
#include <boost/python/object/add_to_namespace.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct module;
|
||||
|
||||
namespace objects
|
||||
{
|
||||
struct class_base;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Called as::
|
||||
//
|
||||
// name_space_def(ns, "func", func, kw, policies, docstring, &ns)
|
||||
//
|
||||
// Dispatch to properly add f to namespace ns.
|
||||
//
|
||||
// @group define_stub_function helpers {
|
||||
template <class Func, class CallPolicies, class NameSpaceT>
|
||||
static void name_space_def(
|
||||
NameSpaceT& name_space
|
||||
, char const* name
|
||||
, Func f
|
||||
, keyword_range const& kw
|
||||
, CallPolicies const& policies
|
||||
, char const* doc
|
||||
, objects::class_base*
|
||||
)
|
||||
{
|
||||
typedef typename NameSpaceT::wrapped_type wrapped_type;
|
||||
|
||||
objects::add_to_namespace(
|
||||
name_space, name,
|
||||
detail::make_keyword_range_function(
|
||||
f, policies, kw, get_signature(f, (wrapped_type*)0))
|
||||
, doc
|
||||
);
|
||||
}
|
||||
|
||||
template <class Func, class CallPolicies>
|
||||
static void name_space_def(
|
||||
object& name_space
|
||||
, char const* name
|
||||
, Func f
|
||||
, keyword_range const& kw
|
||||
, CallPolicies const& policies
|
||||
, char const* doc
|
||||
, ...
|
||||
)
|
||||
{
|
||||
scope within(name_space);
|
||||
|
||||
detail::scope_setattr_doc(
|
||||
name
|
||||
, detail::make_keyword_range_function(f, policies, kw)
|
||||
, doc);
|
||||
}
|
||||
|
||||
// For backward compatibility -- is this obsolete?
|
||||
template <class Func, class CallPolicies, class NameSpaceT>
|
||||
static void name_space_def(
|
||||
NameSpaceT& name_space
|
||||
, char const* name
|
||||
, Func f
|
||||
, keyword_range const& kw // ignored
|
||||
, CallPolicies const& policies
|
||||
, char const* doc
|
||||
, module*
|
||||
)
|
||||
{
|
||||
name_space.def(name, f, policies, doc);
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
// Expansions of ::
|
||||
//
|
||||
// template <typename OverloadsT, typename NameSpaceT>
|
||||
// inline void
|
||||
// define_stub_function(
|
||||
// char const* name, OverloadsT s, NameSpaceT& name_space, mpl::int_<N>)
|
||||
// {
|
||||
// name_space.def(name, &OverloadsT::func_N);
|
||||
// }
|
||||
//
|
||||
// where N runs from 0 to BOOST_PYTHON_MAX_ARITY.
|
||||
//
|
||||
// The set of overloaded functions (define_stub_function) expects:
|
||||
//
|
||||
// 1. char const* name: function name that will be visible to python
|
||||
// 2. OverloadsT: a function overloads struct (see defaults_gen.hpp)
|
||||
// 3. NameSpaceT& name_space: a python::class_ or python::module instance
|
||||
// 4. int_t<N>: the Nth overloaded function (OverloadsT::func_N)
|
||||
// (see defaults_gen.hpp)
|
||||
// 5. char const* name: doc string
|
||||
//
|
||||
// @group define_stub_function<N> {
|
||||
template <int N>
|
||||
struct define_stub_function {};
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/defaults_def.hpp>))
|
||||
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
// }
|
||||
|
||||
// This helper template struct does the actual recursive
|
||||
// definition. There's a generic version
|
||||
// define_with_defaults_helper<N> and a terminal case
|
||||
// define_with_defaults_helper<0>. The struct and its
|
||||
// specialization has a sole static member function def that
|
||||
// expects:
|
||||
//
|
||||
// 1. char const* name: function name that will be
|
||||
// visible to python
|
||||
//
|
||||
// 2. OverloadsT: a function overloads struct
|
||||
// (see defaults_gen.hpp)
|
||||
//
|
||||
// 3. NameSpaceT& name_space: a python::class_ or
|
||||
// python::module instance
|
||||
//
|
||||
// 4. char const* name: doc string
|
||||
//
|
||||
// The def static member function calls a corresponding
|
||||
// define_stub_function<N>. The general case recursively calls
|
||||
// define_with_defaults_helper<N-1>::def until it reaches the
|
||||
// terminal case case define_with_defaults_helper<0>.
|
||||
template <int N>
|
||||
struct define_with_defaults_helper {
|
||||
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void
|
||||
def(
|
||||
char const* name,
|
||||
StubsT stubs,
|
||||
keyword_range kw,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
char const* doc)
|
||||
{
|
||||
// define the NTH stub function of stubs
|
||||
define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
|
||||
|
||||
if (kw.second > kw.first)
|
||||
--kw.second;
|
||||
|
||||
// call the next define_with_defaults_helper
|
||||
define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct define_with_defaults_helper<0> {
|
||||
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void
|
||||
def(
|
||||
char const* name,
|
||||
StubsT stubs,
|
||||
keyword_range const& kw,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
char const* doc)
|
||||
{
|
||||
// define the Oth stub function of stubs
|
||||
define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc);
|
||||
// return
|
||||
}
|
||||
};
|
||||
|
||||
// define_with_defaults
|
||||
//
|
||||
// 1. char const* name: function name that will be
|
||||
// visible to python
|
||||
//
|
||||
// 2. OverloadsT: a function overloads struct
|
||||
// (see defaults_gen.hpp)
|
||||
//
|
||||
// 3. CallPolicies& policies: Call policies
|
||||
// 4. NameSpaceT& name_space: a python::class_ or
|
||||
// python::module instance
|
||||
//
|
||||
// 5. SigT sig: Function signature typelist
|
||||
// (see defaults_gen.hpp)
|
||||
//
|
||||
// 6. char const* name: doc string
|
||||
//
|
||||
// This is the main entry point. This function recursively
|
||||
// defines all stub functions of StubT (see defaults_gen.hpp) in
|
||||
// NameSpaceT name_space which can be either a python::class_ or
|
||||
// a python::module. The sig argument is a typelist that
|
||||
// specifies the return type, the class (for member functions,
|
||||
// and the arguments. Here are some SigT examples:
|
||||
//
|
||||
// int foo(int) mpl::vector<int, int>
|
||||
// void bar(int, int) mpl::vector<void, int, int>
|
||||
// void C::foo(int) mpl::vector<void, C, int>
|
||||
//
|
||||
template <class OverloadsT, class NameSpaceT, class SigT>
|
||||
inline void
|
||||
define_with_defaults(
|
||||
char const* name,
|
||||
OverloadsT const& overloads,
|
||||
NameSpaceT& name_space,
|
||||
SigT const&)
|
||||
{
|
||||
typedef typename mpl::front<SigT>::type return_type;
|
||||
typedef typename OverloadsT::void_return_type void_return_type;
|
||||
typedef typename OverloadsT::non_void_return_type non_void_return_type;
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
boost::is_same<void, return_type>::value
|
||||
, void_return_type
|
||||
, non_void_return_type
|
||||
>::type stubs_type;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
(stubs_type::max_args) <= mpl::size<SigT>::value);
|
||||
|
||||
typedef typename stubs_type::template gen<SigT> gen_type;
|
||||
define_with_defaults_helper<stubs_type::n_funcs-1>::def(
|
||||
name
|
||||
, gen_type()
|
||||
, overloads.keywords()
|
||||
, overloads.call_policies()
|
||||
, name_space
|
||||
, overloads.doc_string());
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEFAULTS_DEF_JDG20020811_HPP
|
||||
|
||||
#else // defined(BOOST_PP_IS_ITERATING)
|
||||
// PP vertical iteration code
|
||||
|
||||
|
||||
template <>
|
||||
struct define_stub_function<BOOST_PP_ITERATION()> {
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void define(
|
||||
char const* name
|
||||
, StubsT const&
|
||||
, keyword_range const& kw
|
||||
, CallPolicies const& policies
|
||||
, NameSpaceT& name_space
|
||||
, char const* doc)
|
||||
{
|
||||
detail::name_space_def(
|
||||
name_space
|
||||
, name
|
||||
, &StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION())
|
||||
, kw
|
||||
, policies
|
||||
, doc
|
||||
, &name_space);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(BOOST_PP_IS_ITERATING)
|
||||
@@ -1,389 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy,
|
||||
// use, modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided "as is"
|
||||
// without express or implied warranty, and with no claim as to its
|
||||
// suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef DEFAULTS_GEN_JDG20020807_HPP
|
||||
#define DEFAULTS_GEN_JDG20020807_HPP
|
||||
|
||||
#include <boost/python/detail/preprocessor.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/enum.hpp>
|
||||
#include <boost/preprocessor/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/tuple.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/arithmetic/sub.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/inc.hpp>
|
||||
#include <boost/preprocessor/empty.hpp>
|
||||
#include <boost/preprocessor/comma_if.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/begin_end.hpp>
|
||||
#include <boost/mpl/next.hpp>
|
||||
#include <boost/mpl/apply.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// overloads_base is used as a base class for all function
|
||||
// stubs. This class holds the doc_string of the stubs.
|
||||
struct overloads_base
|
||||
{
|
||||
overloads_base(char const* doc_)
|
||||
: m_doc(doc_) {}
|
||||
|
||||
overloads_base(char const* doc_, detail::keyword_range const& kw)
|
||||
: m_doc(doc_), m_keywords(kw) {}
|
||||
|
||||
char const* doc_string() const
|
||||
{
|
||||
return m_doc;
|
||||
}
|
||||
|
||||
detail::keyword_range const& keywords() const
|
||||
{
|
||||
return m_keywords;
|
||||
}
|
||||
|
||||
private:
|
||||
char const* m_doc;
|
||||
detail::keyword_range m_keywords;
|
||||
};
|
||||
|
||||
// overloads_proxy is generated by the overloads_common operator[] (see
|
||||
// below). This class holds a user defined call policies of the stubs.
|
||||
template <class CallPoliciesT, class OverloadsT>
|
||||
struct overloads_proxy
|
||||
: public overloads_base
|
||||
{
|
||||
typedef typename OverloadsT::non_void_return_type non_void_return_type;
|
||||
typedef typename OverloadsT::void_return_type void_return_type;
|
||||
|
||||
overloads_proxy(
|
||||
CallPoliciesT const& policies_
|
||||
, char const* doc
|
||||
, keyword_range const& kw
|
||||
)
|
||||
: overloads_base(doc, kw)
|
||||
, policies(policies_)
|
||||
{}
|
||||
|
||||
CallPoliciesT
|
||||
call_policies() const
|
||||
{
|
||||
return policies;
|
||||
}
|
||||
|
||||
CallPoliciesT policies;
|
||||
};
|
||||
|
||||
// overloads_common is our default function stubs base class. This
|
||||
// class returns the default_call_policies in its call_policies()
|
||||
// member function. It can generate a overloads_proxy however through
|
||||
// its operator[]
|
||||
template <class DerivedT>
|
||||
struct overloads_common
|
||||
: public overloads_base
|
||||
{
|
||||
overloads_common(char const* doc)
|
||||
: overloads_base(doc) {}
|
||||
|
||||
overloads_common(char const* doc, keyword_range const& kw)
|
||||
: overloads_base(doc, kw) {}
|
||||
|
||||
default_call_policies
|
||||
call_policies() const
|
||||
{
|
||||
return default_call_policies();
|
||||
}
|
||||
|
||||
template <class CallPoliciesT>
|
||||
overloads_proxy<CallPoliciesT, DerivedT>
|
||||
operator[](CallPoliciesT const& policies) const
|
||||
{
|
||||
return overloads_proxy<CallPoliciesT, DerivedT>(
|
||||
policies, this->doc_string(), this->keywords());
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
|
||||
#define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \
|
||||
typedef typename ::boost::mpl::next<BOOST_PP_CAT(iter, index)>::type \
|
||||
BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \
|
||||
typedef typename ::boost::mpl::apply0<BOOST_PP_CAT(iter, index)>::type \
|
||||
BOOST_PP_CAT(T, index);
|
||||
|
||||
#define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
|
||||
static RT BOOST_PP_CAT(func_, \
|
||||
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS_Z( \
|
||||
1, index, T, arg)) \
|
||||
{ \
|
||||
BOOST_PP_TUPLE_ELEM(3, 2, data) \
|
||||
BOOST_PP_TUPLE_ELEM(3, 0, data)( \
|
||||
BOOST_PP_ENUM_PARAMS( \
|
||||
index, \
|
||||
arg)); \
|
||||
}
|
||||
|
||||
#define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
|
||||
struct fstubs_name \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
|
||||
BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \
|
||||
\
|
||||
template <typename SigT> \
|
||||
struct gen \
|
||||
{ \
|
||||
typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
|
||||
typedef typename ::boost::mpl::apply0<rt_iter>::type RT; \
|
||||
typedef typename ::boost::mpl::next<rt_iter>::type iter0; \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND( \
|
||||
n_args, \
|
||||
BOOST_PYTHON_TYPEDEF_GEN, \
|
||||
0) \
|
||||
\
|
||||
BOOST_PP_REPEAT_FROM_TO_2( \
|
||||
BOOST_PP_SUB_D(1, n_args, n_dflts), \
|
||||
BOOST_PP_INC(n_args), \
|
||||
BOOST_PYTHON_FUNC_WRAPPER_GEN, \
|
||||
(fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
|
||||
}; \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \
|
||||
static RT BOOST_PP_CAT(func_, \
|
||||
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
|
||||
ClassT obj BOOST_PP_COMMA_IF(index) \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
|
||||
) \
|
||||
{ \
|
||||
BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \
|
||||
BOOST_PP_ENUM_PARAMS(index, arg) \
|
||||
); \
|
||||
}
|
||||
|
||||
#define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
|
||||
struct fstubs_name \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
|
||||
BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \
|
||||
\
|
||||
template <typename SigT> \
|
||||
struct gen \
|
||||
{ \
|
||||
typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
|
||||
typedef typename ::boost::mpl::apply0<rt_iter>::type RT; \
|
||||
\
|
||||
typedef typename ::boost::mpl::next<rt_iter>::type class_iter; \
|
||||
typedef typename ::boost::mpl::apply0<class_iter>::type ClassT; \
|
||||
typedef typename ::boost::mpl::next<class_iter>::type iter0; \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND( \
|
||||
n_args, \
|
||||
BOOST_PYTHON_TYPEDEF_GEN, \
|
||||
0) \
|
||||
\
|
||||
BOOST_PP_REPEAT_FROM_TO_2( \
|
||||
BOOST_PP_SUB_D(1, n_args, n_dflts), \
|
||||
BOOST_PP_INC(n_args), \
|
||||
BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN, \
|
||||
(fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
|
||||
}; \
|
||||
};
|
||||
|
||||
#define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
|
||||
fstubs_name(char const* doc = 0) \
|
||||
: ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
|
||||
template <std::size_t N> \
|
||||
fstubs_name(char const* doc, ::boost::python::detail::keywords<N> const& keywords) \
|
||||
: ::boost::python::detail::overloads_common<fstubs_name>( \
|
||||
doc, keywords.range()) \
|
||||
{ \
|
||||
typedef typename ::boost::python::detail:: \
|
||||
error::more_keywords_than_function_arguments< \
|
||||
N,n_args>::too_many_keywords assertion; \
|
||||
} \
|
||||
template <std::size_t N> \
|
||||
fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
|
||||
: ::boost::python::detail::overloads_common<fstubs_name>( \
|
||||
doc, keywords.range()) \
|
||||
{ \
|
||||
typedef typename ::boost::python::detail:: \
|
||||
error::more_keywords_than_function_arguments< \
|
||||
N,n_args>::too_many_keywords assertion; \
|
||||
}
|
||||
|
||||
# if defined(BOOST_NO_VOID_RETURNS)
|
||||
|
||||
# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
struct fstubs_name \
|
||||
: public ::boost::python::detail::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
BOOST_PYTHON_GEN_FUNCTION( \
|
||||
fname, non_void_return_type, n_args, n_dflts, return) \
|
||||
BOOST_PYTHON_GEN_FUNCTION( \
|
||||
fname, void_return_type, n_args, n_dflts, ;) \
|
||||
\
|
||||
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
|
||||
};
|
||||
|
||||
# define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
struct fstubs_name \
|
||||
: public ::boost::python::detail::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION( \
|
||||
fname, non_void_return_type, n_args, n_dflts, return) \
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION( \
|
||||
fname, void_return_type, n_args, n_dflts, ;) \
|
||||
\
|
||||
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
|
||||
};
|
||||
|
||||
# else // !defined(BOOST_NO_VOID_RETURNS)
|
||||
|
||||
# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
struct fstubs_name \
|
||||
: public ::boost::python::detail::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
BOOST_PYTHON_GEN_FUNCTION( \
|
||||
fname, non_void_return_type, n_args, n_dflts, return) \
|
||||
\
|
||||
typedef non_void_return_type void_return_type; \
|
||||
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
|
||||
};
|
||||
|
||||
|
||||
# define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
|
||||
struct fstubs_name \
|
||||
: public ::boost::python::detail::overloads_common<fstubs_name> \
|
||||
{ \
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION( \
|
||||
fname, non_void_return_type, n_args, n_dflts, return) \
|
||||
\
|
||||
typedef non_void_return_type void_return_type; \
|
||||
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
|
||||
};
|
||||
|
||||
# endif // !defined(BOOST_NO_VOID_RETURNS)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MAIN MACROS
|
||||
//
|
||||
// Given generator_name, fname, min_args and max_args, These macros
|
||||
// generate function stubs that forward to a function or member function
|
||||
// named fname. max_args is the arity of the function or member function
|
||||
// fname. fname can have default arguments. min_args is the minimum
|
||||
// arity that fname can accept.
|
||||
//
|
||||
// There are two versions:
|
||||
//
|
||||
// 1. BOOST_PYTHON_FUNCTION_OVERLOADS for free functions
|
||||
// 2. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS for member functions.
|
||||
//
|
||||
// For instance, given a function:
|
||||
//
|
||||
// int
|
||||
// foo(int a, char b = 1, unsigned c = 2, double d = 3)
|
||||
// {
|
||||
// return a + b + c + int(d);
|
||||
// }
|
||||
//
|
||||
// The macro invocation:
|
||||
//
|
||||
// BOOST_PYTHON_FUNCTION_OVERLOADS(foo_stubs, foo, 1, 4)
|
||||
//
|
||||
// Generates this code:
|
||||
//
|
||||
// struct foo_stubsNonVoid
|
||||
// {
|
||||
// static const int n_funcs = 4;
|
||||
// static const int max_args = n_funcs;
|
||||
//
|
||||
// template <typename SigT>
|
||||
// struct gen
|
||||
// {
|
||||
// typedef typename ::boost::mpl::begin<SigT>::type rt_iter;
|
||||
// typedef typename rt_iter::type RT;
|
||||
// typedef typename rt_iter::next iter0;
|
||||
// typedef typename iter0::type T0;
|
||||
// typedef typename iter0::next iter1;
|
||||
// typedef typename iter1::type T1;
|
||||
// typedef typename iter1::next iter2;
|
||||
// typedef typename iter2::type T2;
|
||||
// typedef typename iter2::next iter3;
|
||||
// typedef typename iter3::type T3;
|
||||
// typedef typename iter3::next iter4;
|
||||
//
|
||||
// static RT func_0(T0 arg0)
|
||||
// { return foo(arg0); }
|
||||
//
|
||||
// static RT func_1(T0 arg0, T1 arg1)
|
||||
// { return foo(arg0, arg1); }
|
||||
//
|
||||
// static RT func_2(T0 arg0, T1 arg1, T2 arg2)
|
||||
// { return foo(arg0, arg1, arg2); }
|
||||
//
|
||||
// static RT func_3(T0 arg0, T1 arg1, T2 arg2, T3 arg3)
|
||||
// { return foo(arg0, arg1, arg2, arg3); }
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// struct foo_overloads
|
||||
// : public boost::python::detail::overloads_common<foo_overloads>
|
||||
// {
|
||||
// typedef foo_overloadsNonVoid non_void_return_type;
|
||||
// typedef foo_overloadsNonVoid void_return_type;
|
||||
//
|
||||
// foo_overloads(char const* doc = 0)
|
||||
// : boost::python::detail::overloads_common<foo_overloads>(doc) {}
|
||||
// };
|
||||
//
|
||||
// The typedefs non_void_return_type and void_return_type are
|
||||
// used to handle compilers that do not support void returns. The
|
||||
// example above typedefs non_void_return_type and
|
||||
// void_return_type to foo_overloadsNonVoid. On compilers that do
|
||||
// not support void returns, there are two versions:
|
||||
// foo_overloadsNonVoid and foo_overloadsVoid. The "Void"
|
||||
// version is almost identical to the "NonVoid" version except
|
||||
// for the return type (void) and the lack of the return keyword.
|
||||
//
|
||||
// See the overloads_common above for a description of the
|
||||
// foo_overloads' base class.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
|
||||
BOOST_PYTHON_GEN_FUNCTION_STUB( \
|
||||
fname, \
|
||||
generator_name, \
|
||||
max_args, \
|
||||
BOOST_PP_SUB_D(1, max_args, min_args))
|
||||
|
||||
#define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
|
||||
BOOST_PYTHON_GEN_MEM_FUNCTION_STUB( \
|
||||
fname, \
|
||||
generator_name, \
|
||||
max_args, \
|
||||
BOOST_PP_SUB_D(1, max_args, min_args))
|
||||
|
||||
// deprecated macro names (to be removed)
|
||||
#define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS
|
||||
#define BOOST_PYTHON_MEM_FUN_GENERATOR BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#endif // DEFAULTS_GEN_JDG20020807_HPP
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user