mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Compare commits
32 Commits
boost-1.31
...
svn-tags/m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e04cd704 | ||
|
|
a9c2a95366 | ||
|
|
29f3891a68 | ||
|
|
7b602ef607 | ||
|
|
15e555c7f1 | ||
|
|
f4fb49d32f | ||
|
|
89be2fb736 | ||
|
|
62f0885852 | ||
|
|
355e155e69 | ||
|
|
ae1584ff3c | ||
|
|
4a7686cd33 | ||
|
|
799eeb0cb8 | ||
|
|
8452e275d0 | ||
|
|
53268000e7 | ||
|
|
52febfe3fc | ||
|
|
8fcfed495a | ||
|
|
2dfe76b082 | ||
|
|
11d8751d29 | ||
|
|
b03c3a29e0 | ||
|
|
53e8982e05 | ||
|
|
4a30841ad8 | ||
|
|
234ebadb8d | ||
|
|
11ee20fa36 | ||
|
|
440599545f | ||
|
|
44ba088cb4 | ||
|
|
08d3798722 | ||
|
|
56ff8e438e | ||
|
|
3590a3589d | ||
|
|
7674c82e1f | ||
|
|
b93b21a7f2 | ||
|
|
f53925848c | ||
|
|
eedc88b56a |
@@ -34,6 +34,7 @@ if [ check-python-config ]
|
||||
dict.cpp
|
||||
tuple.cpp
|
||||
str.cpp
|
||||
slice.cpp
|
||||
|
||||
aix_init_module.cpp
|
||||
converter/from_python.cpp
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
.. |(logo)| image:: ../../../c++boost.gif
|
||||
:alt: Boost
|
||||
:class: boost-logo
|
||||
|
||||
__ ../../../index.htm
|
||||
|
||||
|
||||
@@ -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_FUNCTION_OVERLOADS</tt>
|
||||
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt>BOOST_PYTHON_MEMBER_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>
|
||||
|
||||
@@ -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_FUNCTION_OVERLOADS</tt> may be used to automatically create
|
||||
<tt>BOOST_PYTHON_MEMBER_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
|
||||
|
||||
@@ -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_FUNCTION_OVERLOADS] may be used to automatically create
|
||||
[^BOOST_PYTHON_MEMBER_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_FUNCTION_OVERLOADS]
|
||||
[^BOOST_PYTHON_FUNCTION_OVERLOADS] and [^BOOST_PYTHON_MEMBER_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.]
|
||||
|
||||
|
||||
@@ -281,6 +281,7 @@ namespace boost { namespace python
|
||||
// pickle support
|
||||
template <typename PickleSuite>
|
||||
self& def_pickle(PickleSuite const&);
|
||||
self& enable_pickling();
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
@@ -709,6 +710,21 @@ class_& def_pickle(PickleSuite const&);
|
||||
checks.</dt>
|
||||
</dl>
|
||||
<br>
|
||||
<pre>
|
||||
class_& enable_pickling();
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Effects:</b> Defines the <code>__reduce__</code> method and
|
||||
the <code>__safe_for_unpickling__</code> attribute.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code></dt>
|
||||
|
||||
<dt><b>Rationale:</b> Light-weight alternative to
|
||||
<code>def_pickle()</code>. Enables implementation of
|
||||
<a href="pickle.html">pickle support</a> from Python.</dt>
|
||||
</dl>
|
||||
<br>
|
||||
|
||||
|
||||
<h3><a name="bases-spec"></a>Class template
|
||||
|
||||
@@ -442,10 +442,10 @@ Breakpoint 1, 0x1e04eff0 in python22!PyOS_Readline ()
|
||||
If you are launching your extension module tests with <a href=
|
||||
"../../../../tools/build/v1/build_system.htm">Boost.Build</a> using the
|
||||
<code>boost-python-runtest</code> rule, you can ask it to launch your
|
||||
debugger for you by adding "-sPYTHON_LAUNCH=<i>debugger</i>" to your bjam
|
||||
debugger for you by adding "--debugger=<i>debugger</i>" to your bjam
|
||||
command-line:
|
||||
<pre>
|
||||
bjam -sTOOLS=metrowerks "-sPYTHON_LAUNCH=devenv /debugexe" test
|
||||
bjam -sTOOLS=vc7.1 "--debugger=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
|
||||
@@ -873,7 +873,7 @@ BOOST_PYTHON_MODULE(custom_string)
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
10 November, 2003
|
||||
28 January, 2004
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
|
||||
@@ -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>
|
||||
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>
|
||||
<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>
|
||||
<table width="100%" border="1">
|
||||
<tr>
|
||||
|
||||
@@ -208,16 +208,19 @@
|
||||
|
||||
<p><a name="slice_nil-spec"></a></p>
|
||||
<pre>
|
||||
enum slice_nil { _ };
|
||||
class slice_nil;
|
||||
static const _ = slice_nil();
|
||||
</pre>
|
||||
A type that can be used to get the effect of leaving out an index in a
|
||||
Python slice expression:
|
||||
<pre>
|
||||
>>> x[:-1]
|
||||
>>> x[::-1]
|
||||
</pre>
|
||||
C++ equivalent:
|
||||
<pre>
|
||||
x.slice(_,-1)
|
||||
x[slice(_,_,-1)]
|
||||
</pre>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
@@ -281,13 +281,51 @@ is not empty.
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
<h2>Light-weight alternative: pickle support implemented in Python</h2>
|
||||
|
||||
© Copyright Ralf W. Grosse-Kunstleve 20012-2002. Permission to copy,
|
||||
<h3><a href="../../test/pickle4.cpp"><tt>pickle4.cpp</tt></a></h3>
|
||||
|
||||
The <tt>pickle4.cpp</tt> example demonstrates an alternative technique
|
||||
for implementing pickle support. First we direct Boost.Python via
|
||||
the <tt>class_::enable_pickling()</tt> member function to define only
|
||||
the basic attributes required for pickling:
|
||||
|
||||
<pre>
|
||||
class_<world>("world", args<const std::string&>())
|
||||
// ...
|
||||
.enable_pickling()
|
||||
// ...
|
||||
</pre>
|
||||
|
||||
This enables the standard Python pickle interface as described
|
||||
in the Python documentation. By "injecting" a
|
||||
<tt>__getinitargs__</tt> method into the definition of the wrapped
|
||||
class we make all instances pickleable:
|
||||
|
||||
<pre>
|
||||
# import the wrapped world class
|
||||
from pickle4_ext import world
|
||||
|
||||
# definition of __getinitargs__
|
||||
def world_getinitargs(self):
|
||||
return (self.get_country(),)
|
||||
|
||||
# now inject __getinitargs__ (Python is a dynamic language!)
|
||||
world.__getinitargs__ = world_getinitargs
|
||||
</pre>
|
||||
|
||||
See also the
|
||||
<a href="../tutorial/doc/extending_wrapped_objects_in_python.html"
|
||||
>tutorial section</a> on injecting additional methods from Python.
|
||||
|
||||
<hr>
|
||||
|
||||
© Copyright Ralf W. Grosse-Kunstleve 2001-2004. 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.
|
||||
|
||||
<p>
|
||||
Updated: Aug 2002.
|
||||
Updated: Feb 2004.
|
||||
</div>
|
||||
|
||||
@@ -27,8 +27,15 @@
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<b>Boost.Python</b> has been successfully tested on the following
|
||||
platforms and compilers:
|
||||
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.
|
||||
|
||||
<dl class="page-index">
|
||||
<dt>Unix Platforms:</dt>
|
||||
|
||||
@@ -357,6 +357,19 @@
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="slice.html">slice.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="slice.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="slice.html#slice-spec">slice</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h2><a name="invocation">Function Invocation and Creation</a></h2>
|
||||
|
||||
241
doc/v2/slice.html
Normal file
241
doc/v2/slice.html
Normal file
@@ -0,0 +1,241 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="generator"
|
||||
content="HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - <boost/python/slice.hpp></title>
|
||||
</head>
|
||||
<body>
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%"
|
||||
summary="header">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277"
|
||||
alt="C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
|
||||
<h2 align="center">Header <boost/python/slice.hpp></h2>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr>
|
||||
<h2>Contents</h2>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
<dt><a href="#classes">Classes</a></dt>
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#slice-spec">Class <code>slice</code></a></dt>
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#slice-spec-synopsis">Class <code>slice</code>
|
||||
synopsis</a></dt>
|
||||
<dt><a href="#slice-spec-ctors">Class <code>slice</code>
|
||||
constructors</a></dt>
|
||||
<dt><a href="#slice-spec-observers">Class <code>slice</code>
|
||||
observer functions</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="#examples">Example(s)</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
<p>Exposes a <a href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a>
|
||||
for the Python <a
|
||||
href="http://www.python.org/doc/2.3.3/api/slice-objects.html">slice</a>
|
||||
type.</p>
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
<h3><a name="class-spec"></a>Class <code>slice</code></h3>
|
||||
<p>Exposes the extended slicing protocol by wrapping the built-in slice
|
||||
type. The semantics of the constructors and member functions defined
|
||||
below can be fully understood by reading the <a
|
||||
href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
|
||||
definition. Since <code>slice</code> is publicly derived from <code><a
|
||||
href="object.html#object-spec">object</a></code>, the public object
|
||||
interface applies to <code>slice</code> instances as well.<br>
|
||||
</p>
|
||||
<h4><a name="slice-spec-synopsis"></a>Class <code>slice</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
class slice : public object
|
||||
{
|
||||
public:
|
||||
slice(); // create an empty slice, equivalent to [::]
|
||||
|
||||
template <typename Int1, typename Int2>
|
||||
slice(Int1 start, Int2 stop);
|
||||
|
||||
template <typename Int1, typename Int2, typename Int3>
|
||||
slice(Int1 start, Int2 stop, Int3 step);
|
||||
|
||||
// Access the parameters this slice was created with.
|
||||
object start();
|
||||
object stop();
|
||||
object step();
|
||||
|
||||
// The return type of slice::get_indicies()
|
||||
template <typename RandomAccessIterator>
|
||||
struct range
|
||||
{
|
||||
RandomAccessIterator start;
|
||||
RandomAccessIterator stop;
|
||||
int step;
|
||||
};
|
||||
|
||||
template <typename RandomAccessIterator>
|
||||
range<RandomAccessIterator>
|
||||
get_indicies(
|
||||
RandomAccessIterator const& begin,
|
||||
RandomAccessIterator const& end);
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
<h4><a name="slice-spec-ctors"></a>Class <code>slice</code>
|
||||
constructors<br>
|
||||
</h4>
|
||||
<pre>slice();<br></pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Effects:</b> constructs a <code>slice</code> with default stop, start, and
|
||||
step values. Equivalent to the slice object created by the Python
|
||||
expression <code>base[::].</code></dt>
|
||||
<dt><b>Throws:</b> nothing.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
template <typename Int1, typename Int2>
|
||||
slice(Int1 start, Int2 stop);
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>start</code>, <code>stop</code>, and <code>step</code>
|
||||
are of type <code>slice_nil</code> or convertible to type <code>object</code>.</dt>
|
||||
<dt><b>Effects:</b> constructs a new slice with default step value
|
||||
and the provided start and stop values. Equivalent to the slice
|
||||
object
|
||||
created by the built-in Python function <code><a
|
||||
href="http://www.python.org/doc/current/lib/built-in-funcs.html#12h-62">slice(start,stop)</a></code>,
|
||||
or the Python expression <code>base[start:stop]</code>.</dt>
|
||||
<dt><b>Throws:</b> <code>error_already_set</code> and sets a Python <code>TypeError</code>
|
||||
exception if no conversion is possible from the arguments to type <code>object</code>.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
template <typename Int1, typename Int2, typename Int3>
|
||||
slice(Int1 start, Int2 stop, Int3 step);
|
||||
</pre>
|
||||
<dt><b>Requires:</b> <code>start</code>, <code>stop</code>, and <code>step</code> are integers, <code>slice_nil</code>, or convertible to type <code>object</code>.</dt>
|
||||
<dt><b>Effects:</b> constructs a new slice with start stop and step
|
||||
values. Equivalent to the slice object created
|
||||
by the built-in Python function <code><a
|
||||
href="http://www.python.org/doc/current/lib/built-in-functions.html#12h-62">slice(start,stop,step)</a></code>,
|
||||
or the Python expression <code>base[start:stop:step]</code>.</dt>
|
||||
<dt><b>Throws:</b> <code>error_already_set</code> and sets a Python <code>TypeError</code>
|
||||
exception if no conversion is possible from the arguments to type
|
||||
object.</dt>
|
||||
<h4><a name="slice-spec-observers"></a>Class <code>slice</code>
|
||||
observer functions<br>
|
||||
</h4>
|
||||
<pre>
|
||||
object slice::start();
|
||||
object slice::stop();
|
||||
object slice::step();
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Effects:</b> None.</dt>
|
||||
<dt><b>Throws:</b> nothing.</dt>
|
||||
<dt><b>Returns:</b>the parameter that
|
||||
the slice was created with. If the parameter was omitted or
|
||||
slice_nil was used when the slice was created, than that parameter will
|
||||
be a reference to PyNone and compare equal to a default-constructed
|
||||
object. In principal, any object may be used when creating a
|
||||
slice object, but in practice they are usually integers.</dt>
|
||||
</dl>
|
||||
<br>
|
||||
<pre>
|
||||
template <typename RandomAccessIterator>
|
||||
slice::range<RandomAccessIterator>
|
||||
slice::get_indicies(
|
||||
RandomAccessIterator const& begin, RandomAccessIterator const& end);
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Arguments:</b> A pair of STL-conforming Random Access
|
||||
Iterators that form a half-open range.</dt>
|
||||
<dt><b>Effects:</b> Create a RandomAccessIterator pair that defines a
|
||||
fully-closed range within the [begin,end) range of its arguments.
|
||||
This function translates this slice's indicies while accounting for the
|
||||
effects of any PyNone or negative indicies, and non-singular step sizes.</dt>
|
||||
<dt><b>Returns:</b> a slice::range
|
||||
that has been initialized with a non-zero value of step and a pair of
|
||||
RandomAccessIterators that point within the range of this functions
|
||||
arguments and define a closed interval.</dt>
|
||||
<dt><b>Throws:</b> <a href="definitions.html#raise">Raises</a> a Python <code>TypeError</code> exception if any of this slice's arguments
|
||||
are neither references to <code>PyNone</code> nor convertible to <code>int</code>. Throws
|
||||
<code>std::invalid_argument</code> if the resulting range would be empty. You
|
||||
should always wrap calls to <code>slice::get_indicies()</code>
|
||||
within <code>try { ...; } catch (std::invalid_argument) {}</code> to
|
||||
handle this case and take appropriate action.</dt>
|
||||
<dt><b>Rationale</b>: closed-interval: If
|
||||
an open interval were used, then for step
|
||||
size other than 1, the required state for the end iterator would point
|
||||
beyond the one-past-the-end position or before the beginning of the
|
||||
specified range.<br>
|
||||
exceptions on empty slice: It is impossible to define a closed interval
|
||||
over an empty range, so some other form of error checking would have to
|
||||
be used to prevent undefined behavior. In the case where the
|
||||
exception is not caught, it will simply be translated to Python by the
|
||||
default exception handling mechanisms. </dt>
|
||||
</dl>
|
||||
<h2><a name="examples"></a><b>Examples</b></h2>
|
||||
<pre>
|
||||
using namespace boost::python;
|
||||
|
||||
// Perform an extended slice of a Python list.
|
||||
// Warning: extended slicing was not supported for built-in types prior
|
||||
// to Python 2.3
|
||||
list odd_elements(list l)
|
||||
{
|
||||
return l[slice(_,_,2)];
|
||||
}
|
||||
|
||||
// Perform a multidimensional rich slice of a Numeric.array
|
||||
numeric::array even_columns(numeric::array arr)
|
||||
{
|
||||
// select every other column, starting with the second, of a 2-D array.
|
||||
// Equivalent to "return arr[:, 1::2]" in Python.
|
||||
return arr[make_tuple( slice(), slice(1,_,2))];
|
||||
}
|
||||
|
||||
// Perform a summation over a slice of a std::vector.
|
||||
double partial_sum(std::vector<double> const& Foo, slice index)
|
||||
{
|
||||
slice::range<std::vector<double>::const_iterator> bounds;
|
||||
try {
|
||||
bounds = index.get_indicies<>(Foo.begin(), Foo.end());
|
||||
}
|
||||
catch (std::invalid_argument) {
|
||||
return 0.0;
|
||||
}
|
||||
double sum = 0.0;
|
||||
while (bounds.start != bounds.end) {
|
||||
sum += *bounds.start;
|
||||
std::advance( bounds.start, bounds.step);
|
||||
}
|
||||
sum += *bounds.start;
|
||||
return sum;
|
||||
}
|
||||
</pre>
|
||||
<p>Revised 07 Febuary, 2004</p>
|
||||
<p><i>© Copyright <a
|
||||
href="mailto:jbrandmeyer@users.sourceforge.net">Jonathan Brandmeyer</a>,
|
||||
2004. Modification, copying and redistribution of this document
|
||||
is permitted under the terms and conditions of the Boost Software
|
||||
License, version 1.0.<br>
|
||||
</i></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -47,6 +47,12 @@ namespace detail
|
||||
}
|
||||
|
||||
keyword elements[nkeywords];
|
||||
|
||||
keywords<nkeywords+1>
|
||||
operator,(arg const &k) const;
|
||||
|
||||
keywords<nkeywords + 1>
|
||||
operator,(char const *name) const;
|
||||
};
|
||||
|
||||
template <std::size_t nkeywords>
|
||||
@@ -77,14 +83,25 @@ namespace detail
|
||||
};
|
||||
|
||||
template <std::size_t nkeywords>
|
||||
keywords<nkeywords+1> operator,(keywords<nkeywords> const& l, const keywords<1> &k)
|
||||
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
|
||||
@@ -136,16 +153,6 @@ namespace detail
|
||||
# endif
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <std::size_t nkeywords>
|
||||
inline keywords<nkeywords + 1>
|
||||
operator,(keywords<nkeywords> const& l, char *name)
|
||||
{
|
||||
return l.operator,(arg(name));
|
||||
}
|
||||
}
|
||||
|
||||
inline detail::keywords<1> args(char const* name)
|
||||
{
|
||||
return detail::keywords<1>(name);
|
||||
|
||||
@@ -40,7 +40,10 @@ namespace boost { namespace python {
|
||||
# endif // CALL_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, call.hpp)
|
||||
# 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()
|
||||
|
||||
|
||||
@@ -39,7 +39,10 @@ namespace boost { namespace python {
|
||||
# endif // CALL_METHOD_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
|
||||
# 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()
|
||||
|
||||
|
||||
@@ -47,8 +47,14 @@
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) || BOOST_WORKAROUND(__GNUC__, < 3)
|
||||
# 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
|
||||
@@ -127,7 +133,6 @@ namespace detail
|
||||
register_wrapper_class_impl((Held*)0, (T*)0, 0);
|
||||
}
|
||||
|
||||
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
|
||||
template <class T>
|
||||
struct is_data_member_pointer
|
||||
: mpl::and_<
|
||||
@@ -135,15 +140,17 @@ namespace detail
|
||||
, mpl::not_<is_member_function_pointer<T> >
|
||||
>
|
||||
{};
|
||||
# define BOOST_PYTHON_DATA_MEMBER_HELPER , detail::is_data_member_pointer<D>()
|
||||
|
||||
# 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 , 0
|
||||
# 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
|
||||
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D)
|
||||
# define BOOST_PYTHON_YES_DATA_MEMBER
|
||||
# define BOOST_PYTHON_NO_DATA_MEMBER
|
||||
# endif
|
||||
@@ -337,39 +344,39 @@ class class_ : public objects::class_base
|
||||
template <class D>
|
||||
self& def_readonly(char const* name, D const& d)
|
||||
{
|
||||
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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, make_fn(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, make_fn(fget), make_fn(fset));
|
||||
base::add_property(name, this->make_getter(fget), this->make_setter(fset));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -408,6 +415,12 @@ class class_ : public objects::class_base
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& enable_pickling()
|
||||
{
|
||||
this->base::enable_pickling_(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& staticmethod(char const* name)
|
||||
{
|
||||
this->make_method_static(name);
|
||||
@@ -415,25 +428,55 @@ class class_ : public objects::class_base
|
||||
}
|
||||
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 make_fn {
|
||||
// @group PropertyHelpers {
|
||||
template <class F>
|
||||
object make_fn(F const& f)
|
||||
object make_getter(F f)
|
||||
{
|
||||
return make_function(f, default_call_policies(), detail::get_signature(f, (T*)0));
|
||||
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));
|
||||
}
|
||||
|
||||
object
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
const&
|
||||
# endif
|
||||
make_fn(object const& x)
|
||||
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;
|
||||
}
|
||||
@@ -443,30 +486,28 @@ class class_ : public objects::class_base
|
||||
self& def_readonly_impl(
|
||||
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
|
||||
{
|
||||
D T::*pm = pm_;
|
||||
return this->add_property(name, make_getter(pm));
|
||||
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)
|
||||
{
|
||||
D T::*pm = pm_;
|
||||
return this->add_property(name, make_getter(pm), make_setter(pm));
|
||||
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, make_getter(d));
|
||||
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, make_getter(d), make_setter(d));
|
||||
return this->add_static_property(name, python::make_getter(d), python::make_setter(d));
|
||||
}
|
||||
|
||||
inline void register_() const;
|
||||
|
||||
@@ -41,19 +41,11 @@
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# if 0 // argpkg
|
||||
template <class N>
|
||||
inline PyObject* get(N, PyObject* const& args_)
|
||||
{
|
||||
return PyTuple_GET_ITEM(args_,N::value);
|
||||
}
|
||||
# else
|
||||
template <unsigned N>
|
||||
inline PyObject* get(PyObject* const& args_ BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(unsigned,N))
|
||||
template <int N>
|
||||
inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
|
||||
{
|
||||
return PyTuple_GET_ITEM(args_,N);
|
||||
}
|
||||
# endif
|
||||
|
||||
inline unsigned arity(PyObject* const& args_)
|
||||
{
|
||||
@@ -106,21 +98,12 @@ 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;
|
||||
|
||||
# if 0 // argpkg
|
||||
# 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;
|
||||
# else
|
||||
# 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<n>(inner_args)); \
|
||||
if (!c##n.convertible()) \
|
||||
return 0;
|
||||
# endif
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY + 1, <boost/python/detail/caller.hpp>))
|
||||
|
||||
@@ -14,36 +14,39 @@
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
|
||||
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
|
||||
template <class X_> \
|
||||
struct is_##name \
|
||||
{ \
|
||||
typedef char yes; \
|
||||
typedef char (&no)[2]; \
|
||||
\
|
||||
static typename add_reference<X_>::type dummy; \
|
||||
\
|
||||
template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
|
||||
static yes test( \
|
||||
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \
|
||||
); \
|
||||
\
|
||||
template <class U> \
|
||||
static no test(U&, ...); \
|
||||
\
|
||||
BOOST_STATIC_CONSTANT( \
|
||||
bool, value \
|
||||
= !is_reference<X_>::value \
|
||||
& (sizeof(test(dummy, 0)) == sizeof(yes))); \
|
||||
\
|
||||
typedef mpl::bool_<value> type; \
|
||||
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
|
||||
template <class X_> \
|
||||
struct is_##name \
|
||||
{ \
|
||||
typedef char yes; \
|
||||
typedef char (&no)[2]; \
|
||||
\
|
||||
static typename add_reference<X_>::type dummy; \
|
||||
\
|
||||
struct helpers \
|
||||
{ \
|
||||
template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
|
||||
static yes test( \
|
||||
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \
|
||||
); \
|
||||
\
|
||||
template <class U> \
|
||||
static no test(U&, ...); \
|
||||
}; \
|
||||
\
|
||||
BOOST_STATIC_CONSTANT( \
|
||||
bool, value \
|
||||
= !is_reference<X_>::value \
|
||||
& (sizeof(helpers::test(dummy, 0)) == sizeof(yes))); \
|
||||
\
|
||||
typedef mpl::bool_<value> type; \
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
|
||||
template <class T> \
|
||||
struct is_##name : mpl::false_ \
|
||||
struct is_##name : mpl::false_ \
|
||||
{ \
|
||||
}; \
|
||||
\
|
||||
@@ -51,7 +54,7 @@ template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class T) > \
|
||||
struct is_##name< \
|
||||
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, T) > \
|
||||
> \
|
||||
: mpl::true_ \
|
||||
: mpl::true_ \
|
||||
{ \
|
||||
};
|
||||
|
||||
|
||||
@@ -88,7 +88,10 @@ result(X const&, short = 0) { return 0; }
|
||||
|
||||
/* --------------- function pointers --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -108,7 +111,10 @@ boost::type<R>* result(R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)), int = 0)
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
|
||||
# endif
|
||||
// Inner over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -39,7 +39,10 @@ T& (* target(R (T::*)) )() { return 0; }
|
||||
|
||||
/* --------------- function pointers --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers))
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -59,7 +62,10 @@ BOOST_PP_IF(N, A0, void)(* target(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))) )()
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members))
|
||||
# endif
|
||||
// Inner over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -38,13 +38,13 @@ class long_ : public detail::long_base
|
||||
|
||||
template <class T>
|
||||
explicit long_(T const& rhs)
|
||||
: base(object(rhs))
|
||||
: detail::long_base(object(rhs))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
explicit long_(T const& rhs, U const& base)
|
||||
: base(object(rhs), object(base))
|
||||
: detail::long_base(object(rhs), object(base))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -85,19 +85,11 @@ namespace detail
|
||||
BaseArgs base;
|
||||
};
|
||||
|
||||
# if 0
|
||||
template <class N, class BaseArgs, class Offset>
|
||||
inline PyObject* get(N, offset_args<BaseArgs,Offset> const& args_)
|
||||
template <int N, class BaseArgs, class Offset>
|
||||
inline PyObject* get(mpl::int_<N>, offset_args<BaseArgs,Offset> const& args_)
|
||||
{
|
||||
return get(mpl::int_<(N::value+Offset::value)>(), args_.base);
|
||||
return get(mpl::int_<(N+Offset::value)>(), args_.base);
|
||||
}
|
||||
# else
|
||||
template <unsigned N, class BaseArgs, class Offset>
|
||||
inline PyObject* get(offset_args<BaseArgs,Offset> const& args_ BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(unsigned,N))
|
||||
{
|
||||
return get<(N + Offset::value)>(args_.base);
|
||||
}
|
||||
# endif
|
||||
|
||||
template <class BaseArgs, class Offset>
|
||||
inline unsigned arity(offset_args<BaseArgs,Offset> const& args_)
|
||||
|
||||
@@ -32,7 +32,7 @@ struct BOOST_PYTHON_DECL class_base : python::api::object
|
||||
|
||||
// Implementation detail. Hiding this in the private section would
|
||||
// require use of template friend declarations.
|
||||
void enable_pickling(bool getstate_manages_dict);
|
||||
void enable_pickling_(bool getstate_manages_dict);
|
||||
|
||||
protected:
|
||||
void add_property(char const* name, object const& fget);
|
||||
|
||||
@@ -45,7 +45,10 @@ template <int nargs> struct make_holder;
|
||||
# endif // MAKE_HOLDER_DWA20011215_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, make_holder.hpp)
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, make_holder.hpp)
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace detail {
|
||||
inaccessible* (*setstate_fn)(),
|
||||
bool)
|
||||
{
|
||||
cl.enable_pickling(false);
|
||||
cl.enable_pickling_(false);
|
||||
cl.def("__getinitargs__", getinitargs_fn);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace detail {
|
||||
void (*setstate_fn)(Tsetstate, Ttuple),
|
||||
bool getstate_manages_dict)
|
||||
{
|
||||
cl.enable_pickling(getstate_manages_dict);
|
||||
cl.enable_pickling_(getstate_manages_dict);
|
||||
cl.def("__getstate__", getstate_fn);
|
||||
cl.def("__setstate__", setstate_fn);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace detail {
|
||||
void (*setstate_fn)(Tsetstate, Ttuple),
|
||||
bool getstate_manages_dict)
|
||||
{
|
||||
cl.enable_pickling(getstate_manages_dict);
|
||||
cl.enable_pickling_(getstate_manages_dict);
|
||||
cl.def("__getinitargs__", getinitargs_fn);
|
||||
cl.def("__getstate__", getstate_fn);
|
||||
cl.def("__setstate__", setstate_fn);
|
||||
|
||||
@@ -136,7 +136,10 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
|
||||
/* --------------- pointer_holder --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -153,7 +156,10 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
|
||||
/* --------------- pointer_holder_back_reference --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
|
||||
@@ -103,7 +103,10 @@ void* value_holder_back_reference<Value,Held>::holds(
|
||||
// --------------- value_holder ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -122,7 +125,10 @@ void* value_holder_back_reference<Value,Held>::holds(
|
||||
// --------------- value_holder_back_reference ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
|
||||
# endif
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
# include <boost/python/call.hpp>
|
||||
# include <boost/python/handle_fwd.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/slice_nil.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
@@ -63,6 +62,7 @@ namespace api
|
||||
struct item_policies;
|
||||
struct const_slice_policies;
|
||||
struct slice_policies;
|
||||
class slice_nil;
|
||||
|
||||
typedef proxy<const_attribute_policies> const_object_attribute;
|
||||
typedef proxy<attribute_policies> object_attribute;
|
||||
@@ -146,6 +146,9 @@ namespace api
|
||||
const_object_slice slice(object_cref, slice_nil) const;
|
||||
object_slice slice(object_cref, slice_nil);
|
||||
|
||||
const_object_slice slice(slice_nil, slice_nil) const;
|
||||
object_slice slice(slice_nil, slice_nil);
|
||||
|
||||
template <class T, class V>
|
||||
const_object_slice
|
||||
slice(T const& start, V const& end) const
|
||||
@@ -468,4 +471,6 @@ inline PyObject* get_managed_object(object const& x, tag_t)
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# include <boost/python/slice_nil.hpp>
|
||||
|
||||
#endif // OBJECT_CORE_DWA2002615_HPP
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
# if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
|
||||
|
||||
template <class X>
|
||||
char is_object_operators_helper(object_operators<X> const*);
|
||||
|
||||
@@ -27,7 +25,7 @@ no_type is_object_operators_helper(...);
|
||||
|
||||
template <class X> X* make_ptr();
|
||||
|
||||
template <class L, class R>
|
||||
template <class L, class R = L>
|
||||
struct is_object_operators
|
||||
{
|
||||
enum {
|
||||
@@ -40,6 +38,7 @@ struct is_object_operators
|
||||
typedef mpl::bool_<value> type;
|
||||
};
|
||||
|
||||
# if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
|
||||
template <class L, class R, class T>
|
||||
struct enable_binary
|
||||
: boost::iterators::enable_if<is_object_operators<L,R>, T>
|
||||
|
||||
@@ -63,6 +63,22 @@ object_operators<U>::slice(slice_nil, object_cref finish) const
|
||||
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
object_slice
|
||||
object_operators<U>::slice(slice_nil, slice_nil)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
const_object_slice
|
||||
object_operators<U>::slice(slice_nil, slice_nil) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
object_slice
|
||||
object_operators<U>::slice(object_cref start, slice_nil)
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
|
||||
# if 0 // argpkg
|
||||
# include <boost/mpl/int.hpp>
|
||||
# endif
|
||||
# include <boost/mpl/int.hpp>
|
||||
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
@@ -86,11 +84,7 @@ struct return_arg : Base
|
||||
if (!result)
|
||||
return 0;
|
||||
Py_DECREF(result);
|
||||
# if 0 // argpkg
|
||||
return incref( detail::get(mpl::int_<arg_pos-1>(),args) );
|
||||
# else
|
||||
return incref( detail::get<(arg_pos-1)>(args) );
|
||||
# endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
252
include/boost/python/slice.hpp
Normal file
252
include/boost/python/slice.hpp
Normal file
@@ -0,0 +1,252 @@
|
||||
#ifndef BOOST_PYTHON_SLICE_JDB20040105_HPP
|
||||
#define BOOST_PYTHON_SLICE_JDB20040105_HPP
|
||||
|
||||
// Copyright (c) 2004 Jonathan Brandmeyer
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/python/object.hpp>
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/converter/pytype_object_mgr_traits.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class slice : public object
|
||||
{
|
||||
public:
|
||||
// Equivalent to slice(::)
|
||||
slice();
|
||||
|
||||
// Each argument must be int, slice_nil, or implicitly convertable to int
|
||||
template<typename Integer1, typename Integer2>
|
||||
slice( Integer1 start, Integer2 stop)
|
||||
: object( boost::python::detail::new_reference(
|
||||
PySlice_New( object(start).ptr(), object(stop).ptr(), NULL)))
|
||||
{}
|
||||
|
||||
template<typename Integer1, typename Integer2, typename Integer3>
|
||||
slice( Integer1 start, Integer2 stop, Integer3 stride)
|
||||
: object( boost::python::detail::new_reference(
|
||||
PySlice_New( object(start).ptr(), object(stop).ptr(),
|
||||
object(stride).ptr())))
|
||||
{}
|
||||
|
||||
// Get the Python objects associated with the slice. In principle, these
|
||||
// may be any arbitrary Python type, but in practice they are usually
|
||||
// integers. If one or more parameter is ommited in the Python expression
|
||||
// that created this slice, than that parameter is None here, and compares
|
||||
// equal to a default-constructed boost::python::object.
|
||||
// If a user-defined type wishes to support slicing, then support for the
|
||||
// special meaning associated with negative indicies is up to the user.
|
||||
object start();
|
||||
object stop();
|
||||
object step();
|
||||
|
||||
// The following algorithm is intended to automate the process of
|
||||
// determining a slice range when you want to fully support negative
|
||||
// indicies and non-singular step sizes. Its functionallity is simmilar to
|
||||
// PySlice_GetIndicesEx() in the Python/C API, but tailored for C++ users.
|
||||
// This template returns a slice::range struct that, when used in the
|
||||
// following iterative loop, will traverse a slice of the function's
|
||||
// arguments.
|
||||
// while (start != end) {
|
||||
// do_foo(...);
|
||||
// std::advance( start, step);
|
||||
// }
|
||||
// do_foo(...); // repeat exactly once more.
|
||||
|
||||
// Arguments: a [begin, end) pair of STL-conforming random-access iterators.
|
||||
|
||||
// Return: slice::range, where start and stop define a _closed_ interval
|
||||
// that covers at most [begin, end-1] of the provided arguments, and a step
|
||||
// that is non-zero.
|
||||
|
||||
// Throws: error_already_set() if any of the indices are neither None nor
|
||||
// integers, or the slice has a step value of zero.
|
||||
// std::invalid_argument if the resulting range would be empty. Normally,
|
||||
// you should catch this exception and return an empty sequence of the
|
||||
// appropriate type.
|
||||
|
||||
// Performance: constant time for random-access iterators.
|
||||
|
||||
// Rationale:
|
||||
// closed-interval: If an open interval were used, then for a non-singular
|
||||
// value for step, the required state for the end iterator could be
|
||||
// beyond the one-past-the-end postion of the specified range. While
|
||||
// probably harmless, the behavior of STL-conforming iterators is
|
||||
// undefined in this case.
|
||||
// exceptions on zero-length range: It is impossible to define a closed
|
||||
// interval over an empty range, so some other form of error checking
|
||||
// would have to be used by the user to prevent undefined behavior. In
|
||||
// the case where the user fails to catch the exception, it will simply
|
||||
// be translated to Python by the default exception handling mechanisms.
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATES
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
struct range
|
||||
{
|
||||
RandomAccessIterator start;
|
||||
RandomAccessIterator stop;
|
||||
int step;
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
range<RandomAccessIterator>
|
||||
get_indicies( const RandomAccessIterator& begin,
|
||||
const RandomAccessIterator& end)
|
||||
{
|
||||
// This is based loosely on PySlice_GetIndicesEx(), but it has been
|
||||
// carefully crafted to ensure that these iterators never fall out of
|
||||
// the range of the container.
|
||||
slice::range<RandomAccessIterator> ret;
|
||||
typename RandomAccessIterator::difference_type max_dist =
|
||||
std::distance( begin, end);
|
||||
|
||||
object slice_start = this->start();
|
||||
object slice_stop = this->stop();
|
||||
object slice_step = this->step();
|
||||
|
||||
// Extract the step.
|
||||
if (slice_step == object()) {
|
||||
ret.step = 1;
|
||||
}
|
||||
else {
|
||||
ret.step = extract<int>( slice_step);
|
||||
if (ret.step == 0) {
|
||||
PyErr_SetString( PyExc_IndexError, "step size cannot be zero.");
|
||||
throw_error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the start iterator.
|
||||
if (slice_start == object()) {
|
||||
if (ret.step < 0) {
|
||||
ret.start = end;
|
||||
--ret.start;
|
||||
}
|
||||
else
|
||||
ret.start = begin;
|
||||
}
|
||||
else {
|
||||
int i = extract<int>( slice_start);
|
||||
if (i >= max_dist && ret.step > 0)
|
||||
throw std::invalid_argument( "Zero-length slice");
|
||||
if (i >= 0) {
|
||||
ret.start = begin;
|
||||
std::advance( ret.start, std::min(i, max_dist-1));
|
||||
}
|
||||
else {
|
||||
if (i < -max_dist && ret.step < 0)
|
||||
throw std::invalid_argument( "Zero-length slice");
|
||||
ret.start = end;
|
||||
// Advance start (towards begin) not farther than begin.
|
||||
std::advance( ret.start, (-i < max_dist) ? i : -max_dist );
|
||||
}
|
||||
}
|
||||
|
||||
// Set up the stop iterator. This one is a little trickier since slices
|
||||
// define a [) range, and we are returning a [] range.
|
||||
if (slice_stop == object()) {
|
||||
if (ret.step < 0) {
|
||||
ret.stop = begin;
|
||||
}
|
||||
else {
|
||||
ret.stop = end;
|
||||
std::advance( ret.stop, -1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int i = extract<int>( slice_stop);
|
||||
// First, branch on which direction we are going with this.
|
||||
if (ret.step < 0) {
|
||||
if (i+1 >= max_dist || i == -1)
|
||||
throw std::invalid_argument( "Zero-length slice");
|
||||
|
||||
if (i >= 0) {
|
||||
ret.stop = begin;
|
||||
std::advance( ret.stop, i+1);
|
||||
}
|
||||
else { // i is negative, but more negative than -1.
|
||||
ret.stop = end;
|
||||
std::advance( ret.stop, (-i < max_dist) ? i : -max_dist);
|
||||
}
|
||||
}
|
||||
else { // stepping forward
|
||||
if (i == 0 || -i >= max_dist)
|
||||
throw std::invalid_argument( "Zero-length slice");
|
||||
|
||||
if (i > 0) {
|
||||
ret.stop = begin;
|
||||
std::advance( ret.stop, std::min( i-1, max_dist-1));
|
||||
}
|
||||
else { // i is negative, but not more negative than -max_dist
|
||||
ret.stop = end;
|
||||
std::advance( ret.stop, i-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now the fun part, handling the possibilites surrounding step.
|
||||
// At this point, step has been initialized, ret.stop, and ret.step
|
||||
// represent the widest possible range that could be traveled
|
||||
// (inclusive), and final_dist is the maximum distance covered by the
|
||||
// slice.
|
||||
typename RandomAccessIterator::difference_type final_dist =
|
||||
std::distance( ret.start, ret.stop);
|
||||
|
||||
// First case, if both ret.start and ret.stop are equal, then step
|
||||
// is irrelevant and we can return here.
|
||||
if (final_dist == 0)
|
||||
return ret;
|
||||
|
||||
// Second, if there is a sign mismatch, than the resulting range and
|
||||
// step size conflict: std::advance( ret.start, ret.step) goes away from
|
||||
// ret.stop.
|
||||
if ((final_dist > 0) != (ret.step > 0))
|
||||
throw std::invalid_argument( "Zero-length slice.");
|
||||
|
||||
// Finally, if the last step puts us past the end, we move ret.stop
|
||||
// towards ret.start in the amount of the remainder.
|
||||
// I don't remember all of the oolies surrounding negative modulii,
|
||||
// so I am handling each of these cases separately.
|
||||
if (final_dist < 0) {
|
||||
int remainder = -final_dist % -ret.step;
|
||||
std::advance( ret.stop, remainder);
|
||||
}
|
||||
else {
|
||||
int remainder = final_dist % ret.step;
|
||||
std::advance( ret.stop, -remainder);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif // !defined BOOST_NO_MEMBER_TEMPLATES
|
||||
|
||||
public:
|
||||
// This declaration, in conjunction with the specialization of
|
||||
// object_manager_traits<> below, allows C++ functions accepting slice
|
||||
// arguments to be called from from Python. These constructors should never
|
||||
// be used in client code.
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, object)
|
||||
};
|
||||
|
||||
|
||||
namespace converter {
|
||||
|
||||
template<>
|
||||
struct object_manager_traits<slice>
|
||||
: pytype_object_manager_traits<&PySlice_Type, slice>
|
||||
{
|
||||
};
|
||||
|
||||
} // !namesapce converter
|
||||
|
||||
} } // !namespace ::boost::python
|
||||
|
||||
|
||||
#endif // !defined BOOST_PYTHON_SLICE_JDB20040105_HPP
|
||||
@@ -7,18 +7,20 @@
|
||||
# define SLICE_NIL_DWA2002620_HPP
|
||||
|
||||
# include <boost/python/detail/prefix.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
class object;
|
||||
|
||||
enum slice_nil
|
||||
class slice_nil : public object
|
||||
{
|
||||
# ifndef _ // Watch out for GNU gettext users, who #define _(x)
|
||||
_
|
||||
# endif
|
||||
public:
|
||||
slice_nil() : object() {}
|
||||
};
|
||||
|
||||
# ifndef _ // Watch out for GNU gettext users, who #define _(x)
|
||||
static const slice_nil _ = slice_nil();
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
struct slice_bound
|
||||
{
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
# ifndef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# if defined(__GNUC__) \
|
||||
&& ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
||||
# if defined(__GNUC__) \
|
||||
&& ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) \
|
||||
&& !defined(__EDG_VERSION__)
|
||||
# define BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# endif
|
||||
# endif
|
||||
|
||||
@@ -16,13 +16,14 @@ namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <unsigned N>
|
||||
template <std::size_t N>
|
||||
struct get_prev
|
||||
{
|
||||
template <class ArgumentPackage>
|
||||
static PyObject* execute(ArgumentPackage const& args, PyObject*)
|
||||
static PyObject* execute(ArgumentPackage const& args, PyObject* = 0)
|
||||
{
|
||||
return get<(N-1)>(args);
|
||||
int const pre_n = static_cast<int>(N) - 1; // separate line is gcc-2.96 workaround
|
||||
return detail::get(mpl::int_<pre_n>(), args);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
@@ -59,13 +60,9 @@ struct with_custodian_and_ward : BasePolicy_
|
||||
return false;
|
||||
}
|
||||
|
||||
# if 0 // argpkg
|
||||
PyObject* patient = detail::get(mpl::int_<(ward-1)>(), args_);
|
||||
PyObject* nurse = detail::get(mpl::int_<(custodian-1)>(), args_);
|
||||
# else
|
||||
PyObject* patient = detail::get<(ward-1)>(args_);
|
||||
PyObject* nurse = detail::get<(custodian-1)>(args_);
|
||||
# endif
|
||||
PyObject* patient = detail::get_prev<ward>::execute(args_);
|
||||
PyObject* nurse = detail::get_prev<custodian>::execute(args_);
|
||||
|
||||
PyObject* life_support = python::objects::make_nurse_and_patient(nurse, patient);
|
||||
if (life_support == 0)
|
||||
return false;
|
||||
@@ -97,13 +94,9 @@ struct with_custodian_and_ward_postcall : BasePolicy_
|
||||
return 0;
|
||||
}
|
||||
|
||||
# if 0 // argpkg
|
||||
PyObject* patient = ward > 0 ? detail::get(mpl::int_<(ward-1)>(),args_) : result;
|
||||
PyObject* nurse = custodian > 0 ? detail::get(mpl::int_<(custodian-1)>(),args_) : result;
|
||||
# else
|
||||
PyObject* patient = detail::get_prev<ward>::execute(args_, result);
|
||||
PyObject* nurse = detail::get_prev<custodian>::execute(args_, result);
|
||||
# endif
|
||||
|
||||
if (nurse == 0) return 0;
|
||||
|
||||
result = BasePolicy_::postcall(args_, result);
|
||||
|
||||
@@ -253,12 +253,13 @@ class ClassExporter(Exporter):
|
||||
|
||||
constructors = [x for x in self.public_members if isinstance(x, Constructor)]
|
||||
self.constructors = constructors[:]
|
||||
# don't export the copy constructor if the class is abstract
|
||||
# don't export constructors if the class is abstract
|
||||
if self.class_.abstract:
|
||||
for cons in constructors:
|
||||
if cons.IsCopy():
|
||||
constructors.remove(cons)
|
||||
break
|
||||
|
||||
if not constructors:
|
||||
# declare no_init
|
||||
self.Add('constructor', py_ns + 'no_init')
|
||||
|
||||
@@ -24,8 +24,6 @@ class EnumExporter(Exporter):
|
||||
else:
|
||||
self.enum = None
|
||||
|
||||
TYPE_COUNT = 0
|
||||
|
||||
def Export(self, codeunit, exported_names):
|
||||
if not self.info.exclude:
|
||||
indent = self.INDENT
|
||||
@@ -34,10 +32,10 @@ class EnumExporter(Exporter):
|
||||
full_name = self.enum.FullName()
|
||||
unnamed_enum = False
|
||||
if rename.startswith('$_') or rename.startswith('._'):
|
||||
unique_number = hash(self.info.include)
|
||||
unnamed_enum = True
|
||||
self.ExportUniqueInt(codeunit)
|
||||
full_name = namespaces.pyste + 'UniqueInt<%d>' % EnumExporter.TYPE_COUNT
|
||||
EnumExporter.TYPE_COUNT += 1
|
||||
full_name = namespaces.pyste + 'UniqueInt<%d>' % unique_number
|
||||
rename = "unnamed"
|
||||
code = indent + namespaces.python
|
||||
code += 'enum_< %s >("%s")\n' % (full_name, rename)
|
||||
|
||||
@@ -14,7 +14,7 @@ from VarExporter import VarExporter
|
||||
from CodeExporter import CodeExporter
|
||||
from exporterutils import FunctionWrapper
|
||||
from utils import makeid
|
||||
|
||||
import warnings
|
||||
|
||||
#==============================================================================
|
||||
# DeclarationInfo
|
||||
@@ -149,6 +149,7 @@ class EnumInfo(DeclarationInfo):
|
||||
class HeaderInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, include, exporter_class = HeaderExporter):
|
||||
warnings.warn('AllFromHeader is not working in all cases in the current version.')
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('include', include)
|
||||
exporter = exporter_class(InfoWrapper(self))
|
||||
|
||||
@@ -51,7 +51,7 @@ from CppParser import CppParser, CppParserError
|
||||
import time
|
||||
import declarations
|
||||
|
||||
__version__ = '0.9.28'
|
||||
__version__ = '0.9.29'
|
||||
|
||||
def RecursiveIncludes(include):
|
||||
'Return a list containg the include dir and all its subdirectories'
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__) && defined(__GNUC__) \
|
||||
&& __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__APPLE_CC__)
|
||||
&& __GNUC__ == 3 && __GNUC_MINOR__ <= 4 && !defined(__APPLE_CC__)
|
||||
# define BOOST_PYTHON_CONVERTER_REGISTRY_APPLE_MACH_WORKAROUND
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 3 || __SGI_STL_PORT
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 3 || __SGI_STL_PORT || __EDG_VERSION__
|
||||
# include <ostream>
|
||||
#else
|
||||
# include <ostream.h>
|
||||
@@ -33,10 +33,19 @@ namespace boost { namespace python {
|
||||
# if __GNUC__ < 3
|
||||
|
||||
namespace cxxabi = :: ;
|
||||
# else
|
||||
extern "C" char* __cxa_demangle(char const*, char*, std::size_t*, int*);
|
||||
# else
|
||||
|
||||
namespace cxxabi = ::abi; // GCC 3.1 and later
|
||||
|
||||
# if __GNUC__ == 3 && __GNUC_MINOR__ == 0
|
||||
namespace abi
|
||||
{
|
||||
extern "C" char* __cxa_demangle(char const*, char*, std::size_t*, int*);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -33,11 +33,8 @@ BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)())
|
||||
if (m != 0)
|
||||
{
|
||||
// Create the current module scope
|
||||
scope current_module(
|
||||
(object(
|
||||
((borrowed_reference_t*)m)
|
||||
))
|
||||
);
|
||||
object m_obj(((borrowed_reference_t*)m));
|
||||
scope current_module(m_obj);
|
||||
|
||||
handle_exception(init_function);
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ namespace objects
|
||||
this->setattr("__init__", object(f));
|
||||
}
|
||||
|
||||
void class_base::enable_pickling(bool getstate_manages_dict)
|
||||
void class_base::enable_pickling_(bool getstate_manages_dict)
|
||||
{
|
||||
setattr("__reduce__", object(make_instance_reduce_function()));
|
||||
setattr("__safe_for_unpickling__", object(true));
|
||||
|
||||
@@ -32,7 +32,7 @@ extern "C"
|
||||
((life_support*)self)->patient = 0;
|
||||
// Let the weak reference die. This probably kills us.
|
||||
Py_XDECREF(PyTuple_GET_ITEM(arg, 0));
|
||||
return detail::none();
|
||||
return ::boost::python::detail::none();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
src/slice.cpp
Normal file
38
src/slice.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "boost/python/slice.hpp"
|
||||
|
||||
// Copyright (c) 2004 Jonathan Brandmeyer
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
slice::slice()
|
||||
: object( boost::python::detail::new_reference(
|
||||
PySlice_New( NULL, NULL, NULL)))
|
||||
{
|
||||
}
|
||||
|
||||
object
|
||||
slice::start()
|
||||
{
|
||||
return object( detail::borrowed_reference(
|
||||
((PySliceObject*)this->ptr())->start));
|
||||
}
|
||||
|
||||
object
|
||||
slice::stop()
|
||||
{
|
||||
return object( detail::borrowed_reference(
|
||||
((PySliceObject*)this->ptr())->stop));
|
||||
}
|
||||
|
||||
object
|
||||
slice::step()
|
||||
{
|
||||
return object( detail::borrowed_reference(
|
||||
((PySliceObject*)this->ptr())->step));
|
||||
}
|
||||
|
||||
} } // !namespace boost::python
|
||||
75
test/Jamfile
75
test/Jamfile
@@ -21,10 +21,13 @@ rule turn-off-intel-debug-symbols ( toolset variant : properties * )
|
||||
}
|
||||
return $(properties) ;
|
||||
}
|
||||
|
||||
local UNIT_TEST_PROPERTIES = $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
|
||||
[ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB ;
|
||||
|
||||
template py-unit-test
|
||||
:
|
||||
: $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
|
||||
[ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB
|
||||
;
|
||||
|
||||
# Convenience rule makes declaring tests faster
|
||||
rule bpl-test ( name ? : files * : requirements * )
|
||||
{
|
||||
@@ -61,16 +64,17 @@ rule bpl-test ( name ? : files * : requirements * )
|
||||
m = $(m)_ext ;
|
||||
}
|
||||
}
|
||||
extension $(m) : $(f) <dll>../build/boost_python : $(requirements) ;
|
||||
extension $(m) : $(f) <template>../build/extension : $(requirements) ;
|
||||
modules += $(m) ;
|
||||
}
|
||||
}
|
||||
|
||||
return [ boost-python-runtest $(name) : $(py) <pyd>$(modules) ] ;
|
||||
return [ boost-python-runtest $(name) : $(py) <pyd>$(modules) : $(requirements) ] ;
|
||||
}
|
||||
|
||||
test-suite python
|
||||
: [
|
||||
:
|
||||
[
|
||||
run ../test/embedding.cpp <lib>../build/boost_python
|
||||
: # program args
|
||||
: # input files
|
||||
@@ -82,7 +86,7 @@ test-suite python
|
||||
<$(gcc-compilers)><debug-python><library-path>$(CYGWIN_PYTHON_DEBUG_DLL_PATH)
|
||||
<$(gcc-compilers)><*><library-path>$(CYGWIN_PYTHON_DLL_PATH)
|
||||
<find-library>$(PYTHON_EMBEDDED_LIBRARY)
|
||||
]
|
||||
]
|
||||
|
||||
[
|
||||
bpl-test crossmod_exception
|
||||
@@ -106,7 +110,7 @@ bpl-test crossmod_exception
|
||||
|
||||
[ bpl-test keywords : keywords.cpp keywords_test.py ]
|
||||
|
||||
[ extension builtin_converters : test_builtin_converters.cpp <dll>../build/boost_python ]
|
||||
[ extension builtin_converters : test_builtin_converters.cpp <template>../build/extension ]
|
||||
[ boost-python-runtest builtin_converters : test_builtin_converters.py <pyd>builtin_converters ]
|
||||
|
||||
[ bpl-test test_pointer_adoption ]
|
||||
@@ -120,6 +124,7 @@ bpl-test crossmod_exception
|
||||
[ bpl-test dict ]
|
||||
[ bpl-test tuple ]
|
||||
[ bpl-test str ]
|
||||
[ bpl-test slice ]
|
||||
|
||||
[ bpl-test virtual_functions ]
|
||||
[ bpl-test back_reference ]
|
||||
@@ -146,6 +151,7 @@ bpl-test crossmod_exception
|
||||
[ bpl-test pickle1 ]
|
||||
[ bpl-test pickle2 ]
|
||||
[ bpl-test pickle3 ]
|
||||
[ bpl-test pickle4 ]
|
||||
|
||||
[ bpl-test nested ]
|
||||
|
||||
@@ -164,45 +170,30 @@ bpl-test crossmod_exception
|
||||
|
||||
[ run indirect_traits_test.cpp ]
|
||||
[ run destroy_test.cpp ]
|
||||
[ run pointer_type_id_test.cpp <lib>../../test/build/boost_test_exec_monitor : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run bases.cpp : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run pointer_type_id_test.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
[ run bases.cpp <template>py-unit-test ]
|
||||
[ run if_else.cpp ]
|
||||
[ run pointee.cpp : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run pointee.cpp <template>py-unit-test ]
|
||||
[ run result.cpp ]
|
||||
|
||||
[ compile string_literal.cpp ]
|
||||
[ compile borrowed.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ compile object_manager.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ compile copy_ctor_mutates_rhs.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ compile borrowed.cpp <template>py-unit-test ]
|
||||
[ compile object_manager.cpp <template>py-unit-test ]
|
||||
[ compile copy_ctor_mutates_rhs.cpp <template>py-unit-test ]
|
||||
|
||||
[ run upcast.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
[ run upcast.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
[ run select_holder.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
[ run select_from_python_test.cpp ../src/converter/type_id.cpp
|
||||
<lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
[ run select_holder.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
[ run select_arg_to_python_test.cpp ../src/converter/type_id.cpp
|
||||
<lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
|
||||
[ run select_from_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ run select_arg_to_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ compile-fail ./raw_pyobject_fail1.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./raw_pyobject_fail2.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./as_to_python_function.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./object_fail1.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./raw_pyobject_fail1.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./raw_pyobject_fail2.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./as_to_python_function.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./object_fail1.cpp <template>py-unit-test ]
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#include <boost/python/module.hpp>
|
||||
#include "test_class.hpp"
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/args.hpp>
|
||||
#include <boost/python/tuple.hpp>
|
||||
@@ -11,7 +12,6 @@
|
||||
#include <boost/python/overloads.hpp>
|
||||
#include <boost/python/raw_function.hpp>
|
||||
#include <boost/python/return_internal_reference.hpp>
|
||||
#include "test_class.hpp"
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#include <boost/python/module.hpp>
|
||||
#include "test_class.hpp"
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
@@ -12,7 +13,6 @@
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include "test_class.hpp"
|
||||
#include <memory>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
@@ -93,6 +93,8 @@ BOOST_PYTHON_MODULE(keywords)
|
||||
|
||||
.def("set", &Foo::set, (arg("a") = 0, arg("b") = 0.0, arg("n") = std::string()) )
|
||||
|
||||
.def("set2", &Foo::set, (arg("a"), "b", "n") )
|
||||
|
||||
.def("a", &Foo::geta)
|
||||
.def("b", &Foo::getb)
|
||||
.def("n", &Foo::getn)
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
>>> f.set(1,n="1")
|
||||
>>> f.a(), f.b(), f.n()
|
||||
(1, 0.0, '1')
|
||||
>>> f.set2(b=2.0,n="2",a=2)
|
||||
>>> f.a(), f.b(), f.n()
|
||||
(2, 2.0, '2')
|
||||
|
||||
# lets see how badly we've broken the 'regular' functions
|
||||
>>> f = Bar()
|
||||
|
||||
@@ -134,6 +134,9 @@ bool check_string_slice()
|
||||
if (s.slice(-3,_) != "rld")
|
||||
return false;
|
||||
|
||||
if (s.slice(_,_) != s)
|
||||
return false;
|
||||
|
||||
if (", " != s.slice(5,7))
|
||||
return false;
|
||||
|
||||
|
||||
41
test/pickle4.cpp
Normal file
41
test/pickle4.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Example by Ralf W. Grosse-Kunstleve
|
||||
|
||||
/*
|
||||
This example shows how to enable pickling without using the
|
||||
pickle_suite. The pickling interface (__getinitargs__) is
|
||||
implemented in Python.
|
||||
|
||||
For more information refer to boost/libs/python/doc/pickle.html.
|
||||
*/
|
||||
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
// A friendly class.
|
||||
class world
|
||||
{
|
||||
private:
|
||||
std::string country;
|
||||
public:
|
||||
world(const std::string& country) {
|
||||
this->country = country;
|
||||
}
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
std::string get_country() const { return country; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(pickle4_ext)
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<world>("world", init<const std::string&>())
|
||||
.enable_pickling()
|
||||
.def("greet", &world::greet)
|
||||
.def("get_country", &world::get_country)
|
||||
;
|
||||
}
|
||||
36
test/pickle4.py
Normal file
36
test/pickle4.py
Normal file
@@ -0,0 +1,36 @@
|
||||
r'''>>> import pickle4_ext
|
||||
>>> import pickle
|
||||
>>> def world_getinitargs(self):
|
||||
... return (self.get_country(),)
|
||||
>>> pickle4_ext.world.__getinitargs__ = world_getinitargs
|
||||
>>> pickle4_ext.world.__module__
|
||||
'pickle4_ext'
|
||||
>>> pickle4_ext.world.__safe_for_unpickling__
|
||||
1
|
||||
>>> pickle4_ext.world.__name__
|
||||
'world'
|
||||
>>> pickle4_ext.world('Hello').__reduce__()
|
||||
(<class 'pickle4_ext.world'>, ('Hello',))
|
||||
>>> wd = pickle4_ext.world('California')
|
||||
>>> pstr = pickle.dumps(wd)
|
||||
>>> wl = pickle.loads(pstr)
|
||||
>>> print wd.greet()
|
||||
Hello from California!
|
||||
>>> print wl.greet()
|
||||
Hello from California!
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
import sys
|
||||
import doctest
|
||||
|
||||
if args is not None:
|
||||
sys.argv = args
|
||||
return doctest.testmod(sys.modules.get(__name__))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "running..."
|
||||
import sys
|
||||
status = run()[0]
|
||||
if (status == 0): print "Done."
|
||||
sys.exit(status)
|
||||
@@ -2,6 +2,26 @@
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
namespace test {
|
||||
|
||||
// Hmm. return_internal_reference<>() wants to wrap a real class.
|
||||
class ret_type
|
||||
{
|
||||
public:
|
||||
ret_type() : i(42.5) {}
|
||||
double i;
|
||||
};
|
||||
|
||||
class crash_me
|
||||
{
|
||||
private:
|
||||
ret_type i;
|
||||
public:
|
||||
ret_type& get_i() { return i; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
X( int value ) : m_value( value )
|
||||
@@ -55,6 +75,20 @@ BOOST_PYTHON_MODULE(properties_ext)
|
||||
make_setter( &X::s_count, return_by_internal_reference_t() ) )
|
||||
//defining class property using a global function
|
||||
.add_static_property( "instance_count_injected", &get_X_instance_count );
|
||||
|
||||
|
||||
class_< test::ret_type>( "ret_type")
|
||||
.add_property( "i", &test::ret_type::i, &test::ret_type::i)
|
||||
;
|
||||
|
||||
class_< test::crash_me> crash_me_wrapper( "crash_me");
|
||||
|
||||
crash_me_wrapper
|
||||
.def( "get_i", &test::crash_me::get_i , return_internal_reference<>())
|
||||
;
|
||||
|
||||
crash_me_wrapper.add_property( "i", crash_me_wrapper.attr("get_i"));
|
||||
|
||||
}
|
||||
|
||||
#include "module_tail.cpp"
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
"""
|
||||
This is test module for properies.
|
||||
This is test module for properties.
|
||||
|
||||
>>> r = properties.ret_type()
|
||||
>>> r.i = 22.5
|
||||
>>> r.i
|
||||
22.5
|
||||
>>> c = properties.crash_me()
|
||||
>>> c.i.i
|
||||
42.5
|
||||
|
||||
>>> X = properties.X
|
||||
|
||||
|
||||
83
test/slice.cpp
Normal file
83
test/slice.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/slice.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
// These checks are only valid under Python 2.3
|
||||
// (rich slicing wasn't supported for builtins under Python 2.2)
|
||||
bool check_string_rich_slice()
|
||||
{
|
||||
object s("hello, world");
|
||||
|
||||
// default slice
|
||||
if (s[slice()] != "hello, world")
|
||||
return false;
|
||||
|
||||
// simple reverse
|
||||
if (s[slice(_,_,-1)] != "dlrow ,olleh")
|
||||
return false;
|
||||
|
||||
// reverse with mixed-sign offsets
|
||||
if (s[slice(-6,1,-1)] != " ,oll")
|
||||
return false;
|
||||
|
||||
// all of the object.cpp check_string_slice() checks should work
|
||||
// with the form that omits the step argument.
|
||||
if (s[slice(_,-3)] != "hello, wo")
|
||||
return false;
|
||||
if (s[slice(-3,_)] != "rld")
|
||||
return false;
|
||||
if (", " != s[slice(5,7)])
|
||||
return false;
|
||||
|
||||
return s[slice(2,-1)][slice(1,-1)] == "lo, wor";
|
||||
}
|
||||
|
||||
// These tests work with Python 2.2, but you must have Numeric installed.
|
||||
bool check_numeric_array_rich_slice()
|
||||
{
|
||||
using numeric::array;
|
||||
object original = array( make_tuple( make_tuple( 11, 12, 13, 14),
|
||||
make_tuple( 21, 22, 23, 24),
|
||||
make_tuple( 31, 32, 33, 34),
|
||||
make_tuple( 41, 42, 43, 44)));
|
||||
object upper_left_quadrant = array( make_tuple( make_tuple( 11, 12),
|
||||
make_tuple( 21, 22)));
|
||||
object odd_cells = array( make_tuple( make_tuple( 11, 13),
|
||||
make_tuple( 31, 33)));
|
||||
object even_cells = array( make_tuple( make_tuple( 22, 24),
|
||||
make_tuple( 42, 44)));
|
||||
object lower_right_quadrant_reversed = array(
|
||||
make_tuple( make_tuple(44, 43),
|
||||
make_tuple(34, 33)));
|
||||
|
||||
// The following comments represent equivalent Python expressions used
|
||||
// to validate the array behavior.
|
||||
// original[::] == original
|
||||
if (original[slice()] != original)
|
||||
return false;
|
||||
// original[:2,:2] == array( [[11, 12], [21, 22]])
|
||||
if (original[make_tuple(slice(_,2), slice(_,2))] != upper_left_quadrant)
|
||||
return false;
|
||||
// original[::2,::2] == array( [[11, 13], [31, 33]])
|
||||
if (original[make_tuple( slice(_,_,2), slice(_,_,2))] != odd_cells)
|
||||
return false;
|
||||
// original[1::2, 1::2] == array( [[22, 24], [42, 44]])
|
||||
if (original[make_tuple( slice(1,_,2), slice(1,_,2))] != even_cells)
|
||||
return false;
|
||||
// original[:-3:-1, :-3,-1] == array( [[44, 43], [34, 33]])
|
||||
if (original[make_tuple( slice(_,-3,-1), slice(_,-3,-1))] != lower_right_quadrant_reversed)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Verify functions accepting a slice argument can be called
|
||||
bool accept_slice( slice) { return true; }
|
||||
|
||||
BOOST_PYTHON_MODULE(slice_ext)
|
||||
{
|
||||
def( "accept_slice", accept_slice);
|
||||
def( "check_numeric_array_rich_slice", check_numeric_array_rich_slice);
|
||||
def( "check_string_rich_slice", check_string_rich_slice);
|
||||
}
|
||||
60
test/slice.py
Normal file
60
test/slice.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
>>> from slice_ext import *
|
||||
>>> accept_slice(slice(1, None, (1,2)))
|
||||
1
|
||||
>>> try:
|
||||
... accept_slice(list((1,2)))
|
||||
... print "test failed"
|
||||
... except:
|
||||
... print "test passed"
|
||||
...
|
||||
test passed
|
||||
>>> have_numeric = 0
|
||||
>>> try:
|
||||
... from Numeric import array
|
||||
... have_numeric = 1
|
||||
... except:
|
||||
... pass
|
||||
...
|
||||
>>> try:
|
||||
... from numarray import array
|
||||
... have_numeric = 1
|
||||
... except:
|
||||
... pass
|
||||
...
|
||||
>>> if have_numeric:
|
||||
... check_numeric_array_rich_slice()
|
||||
... else:
|
||||
... print 1
|
||||
...
|
||||
1
|
||||
>>> import sys
|
||||
>>> if sys.version_info[0] == 2 and sys.version_info[1] >= 3:
|
||||
... check_string_rich_slice()
|
||||
... elif sys.version_info[0] > 2:
|
||||
... check_string_rich_slice()
|
||||
... else:
|
||||
... print 1
|
||||
...
|
||||
1
|
||||
"""
|
||||
|
||||
# Performs an affirmative and negative argument resolution check,
|
||||
# checks the operation of extended slicing in Numeric arrays
|
||||
# (only performed if Numeric.array or numarray.array can be found).
|
||||
# checks the operation of extended slicing in new strings (Python 2.3 only).
|
||||
|
||||
def run(args = None):
|
||||
import sys
|
||||
import doctest
|
||||
|
||||
if args is not None:
|
||||
sys.argv = args
|
||||
return doctest.testmod(sys.modules.get(__name__))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "running..."
|
||||
import sys
|
||||
status = run()[0]
|
||||
if (status == 0): print "Done."
|
||||
sys.exit(status)
|
||||
143
todo.html
143
todo.html
@@ -3,7 +3,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.0: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" />
|
||||
<title>Boost.Python TODO list Boost</title>
|
||||
<link rel="stylesheet" href="../../rst.css" type="text/css" />
|
||||
</head>
|
||||
@@ -15,8 +15,10 @@
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams 2003. See accompanying
|
||||
<a class="reference" href="../../LICENSE_1_0.txt">license</a> for terms of use.</td>
|
||||
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams 2003. Use, modification, and
|
||||
distribution are subject to the Boost Software License, Version
|
||||
1.0. (See accompanying file <a class="reference" href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
|
||||
<a class="reference" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -27,30 +29,36 @@
|
||||
<li><a class="reference" href="#base-class-for-virtual-function-callback-wrappers" id="id5" name="id5">Base Class for Virtual Function Callback Wrappers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#functions" id="id6" name="id6">Functions</a><ul>
|
||||
<li><a class="reference" href="#wrapping-function-objects" id="id7" name="id7">Wrapping Function Objects</a></li>
|
||||
<li><a class="reference" href="#best-match-overload-resolution" id="id8" name="id8">"Best Match" Overload Resolution</a></li>
|
||||
<li><a class="reference" href="#injected-constructors" id="id9" name="id9">Injected Constructors</a></li>
|
||||
<li><a class="reference" href="#miscellaneous" id="id6" name="id6">Miscellaneous</a><ul>
|
||||
<li><a class="reference" href="#support-for-enums-with-duplicate-values" id="id7" name="id7">Support for Enums with Duplicate Values</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#type-converters" id="id10" name="id10">Type Converters</a><ul>
|
||||
<li><a class="reference" href="#lvalue-conversions-from-non-const-pytypeobject-s" id="id11" name="id11">Lvalue conversions from non-const <tt class="literal"><span class="pre">PyTypeObject*</span></tt>s</a></li>
|
||||
<li><a class="reference" href="#converter-scoping" id="id12" name="id12">Converter Scoping</a></li>
|
||||
<li><a class="reference" href="#file-conversions" id="id13" name="id13"><tt class="literal"><span class="pre">FILE*</span> <span class="pre">conversions</span></tt></a></li>
|
||||
<li><a class="reference" href="#post-call-actions" id="id14" name="id14">Post-Call Actions</a></li>
|
||||
<li><a class="reference" href="#pyunicode-support" id="id15" name="id15"><tt class="literal"><span class="pre">PyUnicode</span></tt> Support</a></li>
|
||||
<li><a class="reference" href="#functions" id="id8" name="id8">Functions</a><ul>
|
||||
<li><a class="reference" href="#wrapping-function-objects" id="id9" name="id9">Wrapping Function Objects</a></li>
|
||||
<li><a class="reference" href="#best-match-overload-resolution" id="id10" name="id10">"Best Match" Overload Resolution</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#documentation" id="id16" name="id16">Documentation</a><ul>
|
||||
<li><a class="reference" href="#builtin-converters" id="id17" name="id17">Builtin Converters</a></li>
|
||||
<li><a class="reference" href="#internals" id="id18" name="id18">Internals</a></li>
|
||||
<li><a class="reference" href="#type-converters" id="id11" name="id11">Type Converters</a><ul>
|
||||
<li><a class="reference" href="#lvalue-conversions-from-non-const-pytypeobject-s" id="id12" name="id12">Lvalue conversions from non-const <tt class="literal"><span class="pre">PyTypeObject*</span></tt>s</a></li>
|
||||
<li><a class="reference" href="#converter-scoping" id="id13" name="id13">Converter Scoping</a></li>
|
||||
<li><a class="reference" href="#file-conversions" id="id14" name="id14"><tt class="literal"><span class="pre">FILE*</span></tt> conversions</a></li>
|
||||
<li><a class="reference" href="#void-conversions" id="id15" name="id15"><tt class="literal"><span class="pre">void*</span></tt> conversions</a></li>
|
||||
<li><a class="reference" href="#post-call-actions" id="id16" name="id16">Post-Call Actions</a></li>
|
||||
<li><a class="reference" href="#pyunicode-support" id="id17" name="id17"><tt class="literal"><span class="pre">PyUnicode</span></tt> Support</a></li>
|
||||
<li><a class="reference" href="#ownership-metadata" id="id18" name="id18">Ownership Metadata</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#large-scale" id="id19" name="id19">Large Scale</a><ul>
|
||||
<li><a class="reference" href="#langbinding" id="id20" name="id20">Langbinding</a></li>
|
||||
<li><a class="reference" href="#refactoring-and-reorganization" id="id21" name="id21">Refactoring and Reorganization</a></li>
|
||||
<li><a class="reference" href="#numarray-support-enhancements" id="id22" name="id22">NumArray Support Enhancements</a></li>
|
||||
<li><a class="reference" href="#pyfinalize-safety" id="id23" name="id23"><tt class="literal"><span class="pre">PyFinalize</span></tt> Safety</a></li>
|
||||
<li><a class="reference" href="#documentation" id="id19" name="id19">Documentation</a><ul>
|
||||
<li><a class="reference" href="#builtin-converters" id="id20" name="id20">Builtin Converters</a></li>
|
||||
<li><a class="reference" href="#internals" id="id21" name="id21">Internals</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#large-scale" id="id22" name="id22">Large Scale</a><ul>
|
||||
<li><a class="reference" href="#full-threading-support" id="id23" name="id23">Full Threading Support</a></li>
|
||||
<li><a class="reference" href="#langbinding" id="id24" name="id24">Langbinding</a></li>
|
||||
<li><a class="reference" href="#refactoring-and-reorganization" id="id25" name="id25">Refactoring and Reorganization</a></li>
|
||||
<li><a class="reference" href="#numarray-support-enhancements" id="id26" name="id26">NumArray Support Enhancements</a></li>
|
||||
<li><a class="reference" href="#pyfinalize-safety" id="id27" name="id27"><tt class="literal"><span class="pre">PyFinalize</span></tt> Safety</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -65,13 +73,27 @@
|
||||
<li><a class="reference" href="http://mail.python.org/pipermail/c++-sig/2003-August/005297.html">http://mail.python.org/pipermail/c++-sig/2003-August/005297.html</a>
|
||||
(search for <tt class="literal"><span class="pre">VirtualDispatcher</span></tt>) describes how callback classes
|
||||
can swap ownership relationship with their Python wrappers.</li>
|
||||
<li><a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301">http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301</a>
|
||||
describes how this can also be used to considerably simplify
|
||||
callback classes, solve some "dangling reference" problems, and
|
||||
optimize the calling of non-overridden virtual functions.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="miscellaneous">
|
||||
<h1><a class="toc-backref" href="#id6" name="miscellaneous">Miscellaneous</a></h1>
|
||||
<div class="section" id="support-for-enums-with-duplicate-values">
|
||||
<h2><a class="toc-backref" href="#id7" name="support-for-enums-with-duplicate-values">Support for Enums with Duplicate Values</a></h2>
|
||||
<blockquote>
|
||||
Scott Snyder provided a patch; Dave was dissatisfied for some
|
||||
reason, but maybe it should just be applied if no further action
|
||||
occurs <a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1824616">http://aspn.activestate.com/ASPN/Mail/Message/1824616</a>.</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="functions">
|
||||
<h1><a class="toc-backref" href="#id6" name="functions">Functions</a></h1>
|
||||
<h1><a class="toc-backref" href="#id8" name="functions">Functions</a></h1>
|
||||
<div class="section" id="wrapping-function-objects">
|
||||
<h2><a class="toc-backref" href="#id7" name="wrapping-function-objects">Wrapping Function Objects</a></h2>
|
||||
<h2><a class="toc-backref" href="#id9" name="wrapping-function-objects">Wrapping Function Objects</a></h2>
|
||||
<blockquote>
|
||||
<p>It should be possible to wrap classes which support <tt class="literal"><span class="pre">operator()</span></tt>
|
||||
as Python methods.</p>
|
||||
@@ -79,7 +101,7 @@ as Python methods.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section" id="best-match-overload-resolution">
|
||||
<h2><a class="toc-backref" href="#id8" name="best-match-overload-resolution">"Best Match" Overload Resolution</a></h2>
|
||||
<h2><a class="toc-backref" href="#id10" name="best-match-overload-resolution">"Best Match" Overload Resolution</a></h2>
|
||||
<blockquote>
|
||||
<p>Overload resolution currently depends on the order in which <tt class="literal"><span class="pre">def</span></tt>
|
||||
calls are made (preferring later overloads). This should be
|
||||
@@ -88,29 +110,16 @@ This may await <a class="reference" href="#langbinding">Langbinding</a> integrat
|
||||
already in <a class="reference" href="http://luabind.sf.net">Luabind</a>.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section" id="injected-constructors">
|
||||
<h2><a class="toc-backref" href="#id9" name="injected-constructors">Injected Constructors</a></h2>
|
||||
<blockquote>
|
||||
<p>Enabling the addition of new constructor functors or factory
|
||||
constructors which aren't in the underlying C++ interface.
|
||||
Interface still to be decided. Here is a discussion of it:</p>
|
||||
<blockquote>
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1744280">http://aspn.activestate.com/ASPN/Mail/Message/1744280</a></blockquote>
|
||||
<p>However, I'm pretty sure we can't use the init<>(f) interface here
|
||||
because it will have to instantiate the code for the wrapped
|
||||
class' default constructor, which may not exist.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="type-converters">
|
||||
<h1><a class="toc-backref" href="#id10" name="type-converters">Type Converters</a></h1>
|
||||
<h1><a class="toc-backref" href="#id11" name="type-converters">Type Converters</a></h1>
|
||||
<div class="section" id="lvalue-conversions-from-non-const-pytypeobject-s">
|
||||
<h2><a class="toc-backref" href="#id11" name="lvalue-conversions-from-non-const-pytypeobject-s">Lvalue conversions from non-const <tt class="literal"><span class="pre">PyTypeObject*</span></tt>s</a></h2>
|
||||
<h2><a class="toc-backref" href="#id12" name="lvalue-conversions-from-non-const-pytypeobject-s">Lvalue conversions from non-const <tt class="literal"><span class="pre">PyTypeObject*</span></tt>s</a></h2>
|
||||
<blockquote>
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1662717">http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1662717</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="converter-scoping">
|
||||
<h2><a class="toc-backref" href="#id12" name="converter-scoping">Converter Scoping</a></h2>
|
||||
<h2><a class="toc-backref" href="#id13" name="converter-scoping">Converter Scoping</a></h2>
|
||||
<blockquote>
|
||||
<p><a class="reference" href="http://article.gmane.org/gmane.comp.python.c++/2044">http://article.gmane.org/gmane.comp.python.c++/2044</a></p>
|
||||
<p>If this gets done at all, it is going to happen in conjunction
|
||||
@@ -118,12 +127,18 @@ with <a class="reference" href="#langbinding">Luabind integration</a>.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section" id="file-conversions">
|
||||
<h2><a class="toc-backref" href="#id13" name="file-conversions"><tt class="literal"><span class="pre">FILE*</span> <span class="pre">conversions</span></tt></a></h2>
|
||||
<h2><a class="toc-backref" href="#id14" name="file-conversions"><tt class="literal"><span class="pre">FILE*</span></tt> conversions</a></h2>
|
||||
<blockquote>
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1411366">http://aspn.activestate.com/ASPN/Mail/Message/1411366</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="void-conversions">
|
||||
<h2><a class="toc-backref" href="#id15" name="void-conversions"><tt class="literal"><span class="pre">void*</span></tt> conversions</a></h2>
|
||||
<blockquote>
|
||||
Pointers to <em>cv</em> <tt class="literal"><span class="pre">void</span></tt> should be able to be passed and
|
||||
returned as opaque values.</blockquote>
|
||||
</div>
|
||||
<div class="section" id="post-call-actions">
|
||||
<h2><a class="toc-backref" href="#id14" name="post-call-actions">Post-Call Actions</a></h2>
|
||||
<h2><a class="toc-backref" href="#id16" name="post-call-actions">Post-Call Actions</a></h2>
|
||||
<blockquote>
|
||||
From-Python converters should be passed an extra reference to a
|
||||
chain of post-call actions in the Policies object, where they can
|
||||
@@ -131,23 +146,34 @@ register an additional action. See the end of
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1755435">http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1755435</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="pyunicode-support">
|
||||
<h2><a class="toc-backref" href="#id15" name="pyunicode-support"><tt class="literal"><span class="pre">PyUnicode</span></tt> Support</a></h2>
|
||||
<h2><a class="toc-backref" href="#id17" name="pyunicode-support"><tt class="literal"><span class="pre">PyUnicode</span></tt> Support</a></h2>
|
||||
<blockquote>
|
||||
<p>Review and possibly incorporate changes from <a class="reference" href="mailto:qinlj-at-solidshare.com">Lijun Qin</a> at
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1771145">http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1771145</a></p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section" id="ownership-metadata">
|
||||
<h2><a class="toc-backref" href="#id18" name="ownership-metadata">Ownership Metadata</a></h2>
|
||||
<blockquote>
|
||||
In the thread at
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301">http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301</a>,
|
||||
Niall Douglas describes an idea for solving some "false"
|
||||
dangling pointer/reference return errors by attaching data about
|
||||
objects which lets the framework determine that the reference
|
||||
count on an object doesn't tell us anything about the lifetime
|
||||
of its data.</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="documentation">
|
||||
<h1><a class="toc-backref" href="#id16" name="documentation">Documentation</a></h1>
|
||||
<h1><a class="toc-backref" href="#id19" name="documentation">Documentation</a></h1>
|
||||
<div class="section" id="builtin-converters">
|
||||
<h2><a class="toc-backref" href="#id17" name="builtin-converters">Builtin Converters</a></h2>
|
||||
<h2><a class="toc-backref" href="#id20" name="builtin-converters">Builtin Converters</a></h2>
|
||||
<blockquote>
|
||||
Builtin correspondences between builtiin Python types and C++
|
||||
types need to be documented</blockquote>
|
||||
</div>
|
||||
<div class="section" id="internals">
|
||||
<h2><a class="toc-backref" href="#id18" name="internals">Internals</a></h2>
|
||||
<h2><a class="toc-backref" href="#id21" name="internals">Internals</a></h2>
|
||||
<blockquote>
|
||||
<p>The structure of the framework needs to get documented; <a class="reference" href="mailto:brett.calcott-at-paradise.net.nz">Brett
|
||||
Calcott</a> has promised to turn <a class="reference" href="doc/internals.html">this document</a> into something fit
|
||||
@@ -156,27 +182,38 @@ for users</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="large-scale">
|
||||
<h1><a class="toc-backref" href="#id19" name="large-scale">Large Scale</a></h1>
|
||||
<h1><a class="toc-backref" href="#id22" name="large-scale">Large Scale</a></h1>
|
||||
<div class="section" id="full-threading-support">
|
||||
<h2><a class="toc-backref" href="#id23" name="full-threading-support">Full Threading Support</a></h2>
|
||||
<blockquote>
|
||||
Various people have proposed patches to improve threading support
|
||||
in Boost.Python: see the thread at
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1826544">http://aspn.activestate.com/ASPN/Mail/Message/1826544</a> and
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1865842">http://aspn.activestate.com/ASPN/Mail/Message/1865842</a> for some
|
||||
examples. The only problem is that these are incomplete
|
||||
solutions and verifying that we <em>do</em> have a complete solution is
|
||||
going to take some time and attention.</blockquote>
|
||||
</div>
|
||||
<div class="section" id="langbinding">
|
||||
<h2><a class="toc-backref" href="#id20" name="langbinding">Langbinding</a></h2>
|
||||
<h2><a class="toc-backref" href="#id24" name="langbinding">Langbinding</a></h2>
|
||||
<blockquote>
|
||||
This project to generalizes Boost.Python to work for other
|
||||
languages, initially Lua. See discussions at
|
||||
<a class="reference" href="http://lists.sourceforge.net/lists/listinfo/boost-langbinding">http://lists.sourceforge.net/lists/listinfo/boost-langbinding</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="refactoring-and-reorganization">
|
||||
<h2><a class="toc-backref" href="#id21" name="refactoring-and-reorganization">Refactoring and Reorganization</a></h2>
|
||||
<h2><a class="toc-backref" href="#id25" name="refactoring-and-reorganization">Refactoring and Reorganization</a></h2>
|
||||
<blockquote>
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1673338">http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1673338</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="numarray-support-enhancements">
|
||||
<h2><a class="toc-backref" href="#id22" name="numarray-support-enhancements">NumArray Support Enhancements</a></h2>
|
||||
<h2><a class="toc-backref" href="#id26" name="numarray-support-enhancements">NumArray Support Enhancements</a></h2>
|
||||
<blockquote>
|
||||
Consider integrating the enhancements described in
|
||||
<a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1757092">http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1757092</a></blockquote>
|
||||
</div>
|
||||
<div class="section" id="pyfinalize-safety">
|
||||
<h2><a class="toc-backref" href="#id23" name="pyfinalize-safety"><tt class="literal"><span class="pre">PyFinalize</span></tt> Safety</a></h2>
|
||||
<h2><a class="toc-backref" href="#id27" name="pyfinalize-safety"><tt class="literal"><span class="pre">PyFinalize</span></tt> Safety</a></h2>
|
||||
<blockquote>
|
||||
<p>Currently Boost.Python has several global (or function-static)
|
||||
objects whose existence keeps reference counts from dropping to
|
||||
@@ -191,10 +228,10 @@ interpreter. <a class="reference" href="mailto:dirk-at-gerrits.homeip.net">Dirk
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="footer"/>
|
||||
<hr class="footer" />
|
||||
<div class="footer">
|
||||
<a class="reference" href="todo.txt">View document source</a>.
|
||||
Generated on: 2003-09-11 11:04 UTC.
|
||||
Generated on: 2004-01-02 18:33 UTC.
|
||||
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
||||
</div>
|
||||
</body>
|
||||
|
||||
68
todo.txt
68
todo.txt
@@ -6,17 +6,20 @@
|
||||
|
||||
.. |(logo)| image:: ../../c++boost.gif
|
||||
:alt: Boost
|
||||
:class: boost-logo
|
||||
|
||||
__ ../../index.htm
|
||||
|
||||
.. _`Boost.Python`: index.html
|
||||
|
||||
:copyright: Copyright David Abrahams 2003. See accompanying
|
||||
license_ for terms of use.
|
||||
:copyright: Copyright David Abrahams 2003. Use, modification, and
|
||||
distribution are subject to the Boost Software License, Version
|
||||
1.0. (See accompanying file `LICENSE_1_0.txt`_ or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. contents:: Outline
|
||||
|
||||
.. _license: ../../LICENSE_1_0.txt
|
||||
.. _`LICENSE_1_0.txt`: ../../LICENSE_1_0.txt
|
||||
|
||||
Class Support
|
||||
=============
|
||||
@@ -31,6 +34,20 @@ Base Class for Virtual Function Callback Wrappers
|
||||
(search for ``VirtualDispatcher``) describes how callback classes
|
||||
can swap ownership relationship with their Python wrappers.
|
||||
|
||||
* http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301
|
||||
describes how this can also be used to considerably simplify
|
||||
callback classes, solve some "dangling reference" problems, and
|
||||
optimize the calling of non-overridden virtual functions.
|
||||
|
||||
Miscellaneous
|
||||
=============
|
||||
|
||||
Support for Enums with Duplicate Values
|
||||
---------------------------------------
|
||||
|
||||
Scott Snyder provided a patch; Dave was dissatisfied for some
|
||||
reason, but maybe it should just be applied if no further action
|
||||
occurs http://aspn.activestate.com/ASPN/Mail/Message/1824616.
|
||||
|
||||
|
||||
Functions
|
||||
@@ -56,21 +73,6 @@ Wrapping Function Objects
|
||||
|
||||
.. _Luabind: http://luabind.sf.net
|
||||
|
||||
Injected Constructors
|
||||
---------------------
|
||||
|
||||
Enabling the addition of new constructor functors or factory
|
||||
constructors which aren't in the underlying C++ interface.
|
||||
Interface still to be decided. Here is a discussion of it:
|
||||
|
||||
http://aspn.activestate.com/ASPN/Mail/Message/1744280
|
||||
|
||||
However, I'm pretty sure we can't use the init<>(f) interface here
|
||||
because it will have to instantiate the code for the wrapped
|
||||
class' default constructor, which may not exist.
|
||||
|
||||
|
||||
|
||||
Type Converters
|
||||
===============
|
||||
|
||||
@@ -89,11 +91,17 @@ Converter Scoping
|
||||
|
||||
__ Langbinding_
|
||||
|
||||
``FILE* conversions``
|
||||
``FILE*`` conversions
|
||||
---------------------
|
||||
|
||||
http://aspn.activestate.com/ASPN/Mail/Message/1411366
|
||||
|
||||
``void*`` conversions
|
||||
---------------------
|
||||
|
||||
Pointers to *cv* ``void`` should be able to be passed and
|
||||
returned as opaque values.
|
||||
|
||||
Post-Call Actions
|
||||
-----------------
|
||||
|
||||
@@ -110,6 +118,17 @@ Post-Call Actions
|
||||
|
||||
.. _`Lijun Qin`: mailto:qinlj-at-solidshare.com
|
||||
|
||||
Ownership Metadata
|
||||
------------------
|
||||
|
||||
In the thread at
|
||||
http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1860301,
|
||||
Niall Douglas describes an idea for solving some "false"
|
||||
dangling pointer/reference return errors by attaching data about
|
||||
objects which lets the framework determine that the reference
|
||||
count on an object doesn't tell us anything about the lifetime
|
||||
of its data.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
@@ -134,6 +153,17 @@ Internals
|
||||
Large Scale
|
||||
===========
|
||||
|
||||
Full Threading Support
|
||||
----------------------
|
||||
|
||||
Various people have proposed patches to improve threading support
|
||||
in Boost.Python: see the thread at
|
||||
http://aspn.activestate.com/ASPN/Mail/Message/1826544 and
|
||||
http://aspn.activestate.com/ASPN/Mail/Message/1865842 for some
|
||||
examples. The only problem is that these are incomplete
|
||||
solutions and verifying that we *do* have a complete solution is
|
||||
going to take some time and attention.
|
||||
|
||||
Langbinding
|
||||
-----------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user