mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Compare commits
33 Commits
svn-branch
...
boost-1.29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cbf652c85 | ||
|
|
0e7e64c4a9 | ||
|
|
dae2e27a32 | ||
|
|
3744f8b4c1 | ||
|
|
e9a3d020f3 | ||
|
|
77b6388723 | ||
|
|
a4912cebe0 | ||
|
|
956b0c5038 | ||
|
|
682f175412 | ||
|
|
0dc693a9e3 | ||
|
|
fa61758f32 | ||
|
|
53cebbf024 | ||
|
|
64035277dc | ||
|
|
a8d37ebc4a | ||
|
|
d5cfa0483a | ||
|
|
9e21275595 | ||
|
|
0faabfb091 | ||
|
|
ee6e678c95 | ||
|
|
66358ecfd8 | ||
|
|
dfdf805106 | ||
|
|
281a5271da | ||
|
|
6eaa0827e5 | ||
|
|
c33ac6b47a | ||
|
|
0462c4d2f4 | ||
|
|
1b35d5d3df | ||
|
|
512b912a9c | ||
|
|
7da5d6344d | ||
|
|
f4ba587b19 | ||
|
|
f1612c4294 | ||
|
|
f1b376776e | ||
|
|
eb6994e6b4 | ||
|
|
bd0b01c049 | ||
|
|
628573eb58 |
Binary file not shown.
Binary file not shown.
@@ -52,8 +52,11 @@
|
||||
<hr>
|
||||
|
||||
<h2><a name="requirements">Requirements</a></h2>
|
||||
Boost.Python requires <a href="http://www.python.org">Python</a> 2.2 or
|
||||
later.
|
||||
<b>Boost.Python</b> version 2 requires <a href=
|
||||
"http://www.python.org/2.2">Python 2.2</a> <i>or <a href=
|
||||
"http://www.python.org">newer</a></i>. An unsupported archive of
|
||||
Boost.Python version 1, which works with versions of Python since 1.5.2,
|
||||
is available <a href="../build/python_v1.zip">here</a>.
|
||||
|
||||
<h2><a name="building">Building Boost.Python</a></h2>
|
||||
|
||||
|
||||
@@ -28,6 +28,36 @@
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
Welcome to version 2 of <b>Boost.Python</b>, a C++ library which enables
|
||||
seamless interoperability between C++ and the <a href=
|
||||
"http://www.python.org">Python</a> programming language. The new version
|
||||
has been rewritten from the ground up, with a more convenient and
|
||||
flexible interface, and many new capabilities, including support for:
|
||||
|
||||
<ul>
|
||||
<li>References and Pointers</li>
|
||||
|
||||
<li>Globally Registered Type Coercions</li>
|
||||
|
||||
<li>Automatic Cross-Module Type Conversions</li>
|
||||
|
||||
<li>Efficient Function Overloading</li>
|
||||
|
||||
<li>C++ to Python Exception Translation</li>
|
||||
|
||||
<li>Default Arguments</li>
|
||||
|
||||
<li>Keyword Arguments</li>
|
||||
|
||||
<li>Manipulating Python objects in C++</li>
|
||||
|
||||
<li>Exporting C++ Iterators as Python Iterators</li>
|
||||
|
||||
<li>Documentation Strings</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="index">
|
||||
@@ -39,7 +69,8 @@
|
||||
|
||||
<dt><a href="v2/configuration.html">Configuration Information</a></dt>
|
||||
|
||||
<dt><a href="v2/rationale.html">Rationale</a></dt>
|
||||
<dt><a href="v2/platforms.html">Known Working Platforms and
|
||||
Compilers</a></dt>
|
||||
|
||||
<dt><a href="v2/definitions.html">Definitions</a></dt>
|
||||
|
||||
@@ -51,9 +82,9 @@
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
08 October, 2002
|
||||
08 October, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
|
||||
@@ -32,18 +32,36 @@
|
||||
the architect, designer, and implementor of <b>Boost.Python</b>.</p>
|
||||
|
||||
<p>Joel de Guzman implemented the <a href="overloads.html">default
|
||||
argument support</a> and wrote the excellent tutorial documentation.</p>
|
||||
argument support</a> and wrote the excellent <a href=
|
||||
"../tutorial/index.html">tutorial documentation</a>.</p>
|
||||
|
||||
<p><a href="../../../../people/ralf_w_grosse_kunstleve.htm">Ralf W.
|
||||
Grosse-Kunstleve</a> implemented the <a href="pickle.html">pickle
|
||||
support</a>, and has enthusiastically supported the library since its
|
||||
birth, contributing to design decisions and providing invaluable
|
||||
real-world insight into user requirements. Ralf has written some
|
||||
extensions for converting C++ containers that I hope will be incorporated
|
||||
into the library soon. He also implemented the cross-module support in
|
||||
the first version of Boost.Python. More importantly, Ralf makes sure
|
||||
nobody forgets the near-perfect synergy of C++ and Python for solving the
|
||||
problems of large-scale software construction.</p>
|
||||
real-world insight into user requirements. Ralf has written some <a href=
|
||||
"faq.html#question2">extensions</a> for converting C++ containers that I
|
||||
hope will be incorporated into the library soon. He also implemented the
|
||||
cross-module support in the first version of Boost.Python. More
|
||||
importantly, Ralf makes sure nobody forgets the near-perfect synergy of
|
||||
C++ and Python for solving the problems of large-scale software
|
||||
construction.</p>
|
||||
|
||||
<p><a href="../../../../people/aleksey_gurtovoy.htm">Aleksey Gurtovoy</a>
|
||||
wrote an incredible C++ <a href="http://www.mywikinet.com/mpl">Template
|
||||
Metaprogramming Library</a> which allows Boost.Python to perform much of
|
||||
its compile-time magic. In addition, Aleksey very generously contributed
|
||||
his time and deep knowledge of the quirks of various buggy compilers to
|
||||
help us get around problems at crucial moments.</p>
|
||||
|
||||
<p><a href="../../../../people/paul_mensonides.htm">Paul Mensonides</a>,
|
||||
building on the work <a href="../../../../people/vesa_karvonen.htm">Vesa
|
||||
Karvonen</a>, wrote a similarly amazing <a href=
|
||||
"../../../preprocessor/doc/index.html">Preprocessor Metaprogramming
|
||||
Library</a>, and generously contributed the time and expertise to get it
|
||||
working in the Boost.Python library, rewriting much of Boost.Python to
|
||||
use the new preproccessor metaprogramming constructs and helping us to
|
||||
work around buggy and slow C++ preprocessors.</p>
|
||||
|
||||
<p><a href="mailto:achim@procoders.net">Achim Domma</a> contributed some
|
||||
of the <a href="reference.html#object_wrappers">Object Wrappers</a> and
|
||||
|
||||
141
doc/v2/platforms.html
Normal file
141
doc/v2/platforms.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!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 - Known Working Platforms and Compilers</title>
|
||||
</head>
|
||||
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<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">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Known Working Platforms and Compilers</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<b>Boost.Python</b> has been successfully tested on the following
|
||||
platforms and compilers:
|
||||
|
||||
<dl class="page-index">
|
||||
<dt>Unix Platforms:</dt>
|
||||
|
||||
<dd>
|
||||
<dl>
|
||||
<dt>with Python <a href="http://www.python.org/2.2">2.2</a> and <a
|
||||
href="http://www.python.org/2.2.2">2.2.2b1</a>:</dt>
|
||||
|
||||
<dd>
|
||||
<dl>
|
||||
<dt><a href="http://gcc.gnu.org">GCC</a> 2.96, 3.0.4,
|
||||
3.1, and 3.2 on <a href="http://www.redhat.com">RedHat Linux 7.3</a>
|
||||
for Intel x86. </dt>
|
||||
|
||||
<dt><a href="http://gcc.gnu.org">GCC</a> 2.95.3
|
||||
(20010315 release) on <a
|
||||
href="http://www.redhat.com">RedHat Linux 7.3</a> for
|
||||
Intel x86. All tests passed except those involving C++
|
||||
exceptions. Bugs in the C++ exception-handling
|
||||
implementation prevented these tests from running to
|
||||
completion.</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://www.tru64unix.compaq.com/cplus/index.html">Tru64 CXX
|
||||
6.5.1</a> on OSF v. 5.1 for Dec/Compaq Alpha</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://www.sgi.com/developers/devtools/languages/mipspro.html">
|
||||
MIPSPro 7.3.1.2m</a> on <a href=
|
||||
"http://www.sgi.com/software/irix6.5/">IRIX 6.5</a> for SGI
|
||||
mips</dt>
|
||||
|
||||
<dt><a href="http://gcc.gnu.org">GCC 3.1</a> on SunOS 5.8</dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt>with Python <a href=
|
||||
"http://www.python.org/2.2.1">2.2.1</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl>
|
||||
<dt><a href=
|
||||
"http://developer.intel.com/software/products/kcc/">KCC
|
||||
3.4d</a> on OSF v. 5.1 for Dec/Compaq Alpha</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://developer.intel.com/software/products/kcc/">KCC
|
||||
3.4d</a> on AIX</dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
<br>
|
||||
</dd>
|
||||
|
||||
<dt><a href="http://www.microsoft.com/windowsxp/default.asp">Microsoft
|
||||
Windows XP Professional</a> with Python <a href=
|
||||
"http://www.python.org/2.2">2.2</a>, <a href=
|
||||
"http://www.python.org/2.2.1">2.2.1</a>, and <a href=
|
||||
"http://www.python.org/2.2.2">2.2.2b1</a>:</dt>
|
||||
|
||||
<dd>
|
||||
<dl>
|
||||
<dt><a href=
|
||||
"http://msdn.microsoft.com/visualc/default.asp">Microsoft Visual
|
||||
C++</a> 6, 7, and 7.1 beta</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://msdn.microsoft.com/visualc/default.asp">Microsoft Visual
|
||||
C++ 6</a> with <a href="http://www.stlport.org">STLPort
|
||||
4.5.3</a></dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://www.metrowerks.com/MW/Develop/Desktop/Windows/Professional/Default.htm">
|
||||
Metrowerks CodeWarrior</a> 7.2, 8.0, 8.2 and 8.3 beta</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://www.intel.com/software/products/compilers/c60/">Intel
|
||||
C++</a> 5.0, 6.0, and 7.0 beta</dt>
|
||||
|
||||
<dt><a href=
|
||||
"http://www.intel.com/software/products/compilers/c60/">Intel C++
|
||||
5.0</a> with <a href="http://www.stlport.org">STLPort
|
||||
4.5.3</a></dt>
|
||||
|
||||
<dt><a href="http://www.cygwin.com">Cygwin</a> <a href=
|
||||
"http://gcc.gnu.org">GCC</a> 3.0.4 and 3.2</dt>
|
||||
|
||||
<dt><a href="http://www.mingw.org">MinGW-1.1</a> (<a href=
|
||||
"http://gcc.gnu.org">GCC 2.95.3-5</a>)</dt>
|
||||
|
||||
<dt><a href="http://www.mingw.org">MinGW-2.0</a> (<a href=
|
||||
"http://gcc.gnu.org">GCC 3.2</a>)</dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
10 October, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p><i>© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
||||
Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -352,8 +352,8 @@
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="object.html#object-spec">object</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
@@ -898,7 +898,7 @@
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
3 June, 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
08 October, 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p class="c3">© Copyright <a href=
|
||||
|
||||
@@ -157,7 +157,7 @@ BOOST_PYTHON_MODULE(nested)
|
||||
42
|
||||
</pre>
|
||||
|
||||
<p>Revised 03 October, 2002</p>
|
||||
<p>Revised 09 October, 2002</p>
|
||||
|
||||
<p><i>© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -94,7 +94,8 @@ struct rvalue_from_python_data : rvalue_from_python_storage<T>
|
||||
{
|
||||
# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
|
||||
&& (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \
|
||||
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014)
|
||||
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) \
|
||||
&& !(defined(__APPLE__) && defined(__MACH__) && __APPLE_CC__ <= 1161)
|
||||
// This must always be a POD struct with m_data its first member.
|
||||
BOOST_STATIC_ASSERT(BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,stage1) == 0);
|
||||
# endif
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace objects
|
||||
namespace detail
|
||||
{
|
||||
template <class T, class F> struct member_function_cast;
|
||||
|
||||
|
||||
template <class Func, class CallPolicies, class NameSpaceT>
|
||||
static void name_space_def(
|
||||
NameSpaceT& name_space
|
||||
@@ -51,7 +51,7 @@ namespace detail
|
||||
)
|
||||
{
|
||||
typedef typename NameSpaceT::wrapped_type wrapped_type;
|
||||
|
||||
|
||||
objects::add_to_namespace(
|
||||
name_space, name,
|
||||
make_keyword_range_function(
|
||||
@@ -162,10 +162,10 @@ namespace detail
|
||||
{
|
||||
// define the NTH stub function of stubs
|
||||
define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
|
||||
|
||||
|
||||
if (kw.second > kw.first)
|
||||
--kw.second;
|
||||
|
||||
|
||||
// call the next define_with_defaults_helper
|
||||
define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
|
||||
}
|
||||
|
||||
53
include/boost/python/detail/module_init.hpp
Normal file
53
include/boost/python/detail/module_init.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifdef BOOST_PYTHON_V2
|
||||
# error obsolete
|
||||
#endif
|
||||
#ifndef MODULE_INIT_DWA2002529_HPP
|
||||
# define MODULE_INIT_DWA2002529_HPP
|
||||
|
||||
# ifndef BOOST_PYTHON_MODULE_INIT
|
||||
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" __declspec(dllexport) void init##name() \
|
||||
{ \
|
||||
boost::python::handle_exception(&init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# elif defined(_AIX)
|
||||
|
||||
# include <boost/python/detail/aix_init_module.hpp>
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" \
|
||||
{ \
|
||||
extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \
|
||||
void init##name() \
|
||||
{ \
|
||||
boost::python::detail::aix_init_module(_PyImport_LoadDynamicModule, &init_module_##name); \
|
||||
} \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" void init##name() \
|
||||
{ \
|
||||
boost::python::handle_exception(&init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#endif // MODULE_INIT_DWA2002529_HPP
|
||||
@@ -208,7 +208,7 @@ class init : public init_base<init<BOOST_PYTHON_OVERLOAD_ARGS> >
|
||||
: base(doc_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class Keywords>
|
||||
init(char const* doc_, Keywords const& kw)
|
||||
: base(doc_, std::make_pair(kw.base(), kw.base() + Keywords::size))
|
||||
|
||||
340
include/boost/python/operators2.hpp
Executable file
340
include/boost/python/operators2.hpp
Executable file
@@ -0,0 +1,340 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OPERATORS2_DWA2002530_HPP
|
||||
# define OPERATORS2_DWA2002530_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
# include <boost/python/detail/operator_id.hpp>
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
# include <boost/python/back_reference.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/python/self.hpp>
|
||||
# include <boost/python/other.hpp>
|
||||
# include <boost/lexical_cast.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <string>
|
||||
# include <complex>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This is essentially the old v1 to_python(). It will be eliminated
|
||||
// once the public interface for to_python is settled on.
|
||||
template <class T>
|
||||
PyObject* convert_result(T const& x)
|
||||
{
|
||||
return converter::arg_to_python<T>(x).release();
|
||||
}
|
||||
|
||||
// Operator implementation template declarations. The nested apply
|
||||
// declaration here keeps MSVC6 happy.
|
||||
template <operator_id> struct operator_l
|
||||
{
|
||||
template <class L, class R> struct apply;
|
||||
};
|
||||
|
||||
template <operator_id> struct operator_r
|
||||
{
|
||||
template <class L, class R> struct apply;
|
||||
};
|
||||
|
||||
template <operator_id> struct operator_1
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
|
||||
// MSVC6 doesn't want us to do this sort of inheritance on a nested
|
||||
// class template, so we use this layer of indirection to avoid
|
||||
// ::template<...> on the nested apply functions below
|
||||
template <operator_id id, class L, class R>
|
||||
struct operator_l_inner
|
||||
: operator_l<id>::template apply<L,R>
|
||||
{};
|
||||
|
||||
template <operator_id id, class L, class R>
|
||||
struct operator_r_inner
|
||||
: operator_r<id>::template apply<L,R>
|
||||
{};
|
||||
|
||||
template <operator_id id, class T>
|
||||
struct operator_1_inner
|
||||
: operator_1<id>::template apply<T>
|
||||
{};
|
||||
|
||||
// Define three different binary_op templates which take care of
|
||||
// these cases:
|
||||
// self op self
|
||||
// self op R
|
||||
// L op self
|
||||
//
|
||||
// The inner apply metafunction is used to adjust the operator to
|
||||
// the class type being defined. Inheritance of the outer class is
|
||||
// simply used to provide convenient access to the operation's
|
||||
// name().
|
||||
|
||||
// self op self
|
||||
template <operator_id id>
|
||||
struct binary_op : operator_l<id>
|
||||
{
|
||||
template <class T>
|
||||
struct apply : operator_l_inner<id,T,T>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
// self op R
|
||||
template <operator_id id, class R>
|
||||
struct binary_op_l : operator_l<id>
|
||||
{
|
||||
template <class T>
|
||||
struct apply : operator_l_inner<id,T,R>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
// L op self
|
||||
template <operator_id id, class L>
|
||||
struct binary_op_r : operator_r<id>
|
||||
{
|
||||
template <class T>
|
||||
struct apply : operator_r_inner<id,L,T>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
template <operator_id id>
|
||||
struct unary_op : operator_1<id>
|
||||
{
|
||||
template <class T>
|
||||
struct apply : operator_1_inner<id,T>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
// This type is what actually gets returned from operators used on
|
||||
// self_t
|
||||
template <operator_id id, class L = not_specified, class R = not_specified>
|
||||
struct operator_
|
||||
: mpl::if_<
|
||||
is_same<L,self_t>
|
||||
, typename mpl::if_<
|
||||
is_same<R,self_t>
|
||||
, binary_op<id>
|
||||
, binary_op_l<id,typename unwrap_other<R>::type>
|
||||
>::type
|
||||
, typename mpl::if_<
|
||||
is_same<L,not_specified>
|
||||
, unary_op<id>
|
||||
, binary_op_r<id,typename unwrap_other<L>::type>
|
||||
>::type
|
||||
>::type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_BINARY_OPERATION(id, rid, expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template <> \
|
||||
struct operator_l<op_##id> \
|
||||
{ \
|
||||
template <class L, class R> \
|
||||
struct apply \
|
||||
{ \
|
||||
static inline PyObject* execute(L const& l, R const& r) \
|
||||
{ \
|
||||
return detail::convert_result(expr); \
|
||||
} \
|
||||
}; \
|
||||
static char const* name() { return "__" #id "__"; } \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct operator_r<op_##id> \
|
||||
{ \
|
||||
template <class L, class R> \
|
||||
struct apply \
|
||||
{ \
|
||||
static inline PyObject* execute(R const& r, L const& l) \
|
||||
{ \
|
||||
return detail::convert_result(expr); \
|
||||
} \
|
||||
}; \
|
||||
static char const* name() { return "__" #rid "__"; } \
|
||||
}; \
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_BINARY_OPERATOR(id, rid, op) \
|
||||
BOOST_PYTHON_BINARY_OPERATION(id, rid, l op r) \
|
||||
namespace self_ns \
|
||||
{ \
|
||||
template <class L, class R> \
|
||||
inline detail::operator_<detail::op_##id,L,R> \
|
||||
operator##op(L const&, R const&) \
|
||||
{ \
|
||||
return detail::operator_<detail::op_##id,L,R>(); \
|
||||
} \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_BINARY_OPERATOR(add, radd, +)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(sub, rsub, -)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(mul, rmul, *)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(mod, rmod, %)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(lshift, rlshift, <<)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(rshift, rrshift, >>)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(and, rand, &)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(xor, rxor, ^)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(or, ror, |)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(gt, lt, >)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(ge, le, >=)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(lt, gt, <)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(le, ge, <=)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(eq, eq, ==)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(ne, ne, !=)
|
||||
# undef BOOST_PYTHON_BINARY_OPERATOR
|
||||
|
||||
// pow isn't an operator in C++; handle it specially.
|
||||
BOOST_PYTHON_BINARY_OPERATION(pow, rpow, pow(l,r))
|
||||
# undef BOOST_PYTHON_BINARY_OPERATION
|
||||
|
||||
namespace self_ns
|
||||
{
|
||||
# ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
|
||||
template <class L, class R>
|
||||
inline detail::operator_<detail::op_pow,L,R>
|
||||
pow(L const&, R const&)
|
||||
{
|
||||
return detail::operator_<detail::op_pow,L,R>();
|
||||
}
|
||||
# else
|
||||
// When there's no argument-dependent lookup, we need these
|
||||
// overloads to handle the case when everything is imported into the
|
||||
// global namespace. Note that the plain overload below does /not/
|
||||
// take const& arguments. This is needed by MSVC6 at least, or it
|
||||
// complains of ambiguities, since there's no partial ordering.
|
||||
inline detail::operator_<detail::op_pow,self_t,self_t>
|
||||
pow(self_t, self_t)
|
||||
{
|
||||
return detail::operator_<detail::op_pow,self_t,self_t>();
|
||||
}
|
||||
template <class R>
|
||||
inline detail::operator_<detail::op_pow,self_t,R>
|
||||
pow(self_t const&, R const&)
|
||||
{
|
||||
return detail::operator_<detail::op_pow,self_t,R>();
|
||||
}
|
||||
template <class L>
|
||||
inline detail::operator_<detail::op_pow,L,self_t>
|
||||
pow(L const&, self_t const&)
|
||||
{
|
||||
return detail::operator_<detail::op_pow,L,self_t>();
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
# define BOOST_PYTHON_INPLACE_OPERATOR(id, op) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template <> \
|
||||
struct operator_l<op_##id> \
|
||||
{ \
|
||||
template <class L, class R> \
|
||||
struct apply \
|
||||
{ \
|
||||
static inline PyObject* \
|
||||
execute(back_reference<L&> l, R const& r) \
|
||||
{ \
|
||||
l.get() op r; \
|
||||
return python::incref(l.source().ptr()); \
|
||||
} \
|
||||
}; \
|
||||
static char const* name() { return "__" #id "__"; } \
|
||||
}; \
|
||||
} \
|
||||
namespace self_ns \
|
||||
{ \
|
||||
template <class R> \
|
||||
inline detail::operator_<detail::op_##id,self_t,R> \
|
||||
operator##op(self_t const&, R const&) \
|
||||
{ \
|
||||
return detail::operator_<detail::op_##id,self_t,R>(); \
|
||||
} \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(iadd,+=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(isub,-=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(imul,*=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(idiv,/=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(imod,%=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(ilshift,<<=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(irshift,>>=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(iand,&=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(ixor,^=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(ior,|=)
|
||||
|
||||
# define BOOST_PYTHON_UNARY_OPERATOR(id, op, func_name) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template <> \
|
||||
struct operator_1<op_##id> \
|
||||
{ \
|
||||
template <class T> \
|
||||
struct apply \
|
||||
{ \
|
||||
static PyObject* execute(T const& x) \
|
||||
{ \
|
||||
return detail::convert_result(op(x)); \
|
||||
} \
|
||||
}; \
|
||||
static char const* name() { return "__" #id "__"; } \
|
||||
}; \
|
||||
} \
|
||||
namespace self_ns \
|
||||
{ \
|
||||
inline detail::operator_<detail::op_##id> \
|
||||
func_name(self_t const&) \
|
||||
{ \
|
||||
return detail::operator_<detail::op_##id>(); \
|
||||
} \
|
||||
}
|
||||
# undef BOOST_PYTHON_INPLACE_OPERATOR
|
||||
|
||||
BOOST_PYTHON_UNARY_OPERATOR(neg, -, operator-)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(pos, +, operator+)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(abs, abs, abs)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(invert, ~, operator~)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(int, long, int_)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(long, PyLong_FromLong, long_)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(float, double, float_)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(complex, std::complex<double>, complex_)
|
||||
BOOST_PYTHON_UNARY_OPERATOR(str, lexical_cast<std::string>, str)
|
||||
# undef BOOST_PYTHON_UNARY_OPERATOR
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
|
||||
using boost::python::self_ns::abs;
|
||||
using boost::python::self_ns::int_;
|
||||
using boost::python::self_ns::long_;
|
||||
using boost::python::self_ns::float_;
|
||||
using boost::python::self_ns::complex_;
|
||||
using boost::python::self_ns::str;
|
||||
using boost::python::self_ns::pow;
|
||||
# endif
|
||||
|
||||
#endif // OPERATORS2_DWA2002530_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ get_signature(RT(ClassT::*)(BOOST_PYTHON_SIGNATURE_TYPES) const)
|
||||
#endif // N < (BOOST_PYTHON_MAX_ARITY - 2)
|
||||
|
||||
# undef BOOST_PYTHON_SIGNATURE_PARAMS
|
||||
# undef BOOST_PYTHON_SIGNATURE_TYPES
|
||||
# undef BOOST_PYTHON_SIGNATURE_TYPES
|
||||
# undef BOOST_PYTHON_TRAILING_SIGNATURE_TYPES
|
||||
|
||||
#endif // !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
@@ -79,6 +79,7 @@ private:
|
||||
|
||||
BOOST_PYTHON_MODULE(iterator_ext)
|
||||
{
|
||||
using boost::python::iterator; // gcc 2.96 bug workaround
|
||||
def("range", &::range);
|
||||
|
||||
class_<list_int>("list_int")
|
||||
|
||||
Reference in New Issue
Block a user