mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
Merging all trunk changes in Boost.Python to release. The logs for
these changes follow. r44807 is a merge from another branch; many of those changes probably don't apply. ------------------------------------------------------------------------ r43423 | danieljames | 2008-02-27 14:22:01 -0500 (Wed, 27 Feb 2008) | 1 line Fix incorrect links to copyright of the form 'http:#www.boost.org ------------------------------------------------------------------------ r43546 | rwgk | 2008-03-08 23:30:13 -0500 (Sat, 08 Mar 2008) | 1 line map std::invalid_argument -> Python ValueError ------------------------------------------------------------------------ r43799 | grafik | 2008-03-22 18:53:35 -0400 (Sat, 22 Mar 2008) | 1 line Remove svn exec property from files that should not be executable to fix permission problems in archives. ------------------------------------------------------------------------ r43845 | dave | 2008-03-24 14:27:22 -0400 (Mon, 24 Mar 2008) | 1 line Work around vc9 bugs ------------------------------------------------------------------------ r43901 | bemandawes | 2008-03-27 22:11:13 -0400 (Thu, 27 Mar 2008) | 1 line Remove per email from Dave ------------------------------------------------------------------------ r44041 | rwgk | 2008-04-04 14:57:27 -0400 (Fri, 04 Apr 2008) | 1 line bogus VC8 warning C4180 disabled ------------------------------------------------------------------------ r44449 | djowel | 2008-04-15 23:07:06 -0400 (Tue, 15 Apr 2008) | 1 line Andreas patch ------------------------------------------------------------------------ r44450 | djowel | 2008-04-15 23:07:11 -0400 (Tue, 15 Apr 2008) | 1 line Andreas indexing suite patch ------------------------------------------------------------------------ r44807 | danieljames | 2008-04-27 03:39:49 -0400 (Sun, 27 Apr 2008) | 78 lines Merge in documentation fixes. Apart from the change to optional's documenation Jamfile, which I included by mistake. Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801 I wrote about this at: http://lists.boost.org/Archives/boost/2008/04/136405.php Merged revisions 44585-44806 via svnmerge from https://svn.boost.org/svn/boost/branches/doc ........ r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines Fix broken link to vacpp in bjam docs. Refs #1512 ........ r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines Fix broken link to bcpp in bjam docs. Refs #1513 ........ r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines DateTime documentation - Fix a link to the serialization library. Refs #1659 ........ r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in interprocess & intrusive. Refs #1661 ........ r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in the python docs. Refs #1684. ........ r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines Work around a quickbook bug which is affecting the python docs. Refs #1684. ........ r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines Fix a broken link in the numeric conversion docs. Refs #1685 ........ r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in the optional docs. Refs #1687 ........ r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines Fix link to the hash documentation from bimap. Refs #1690 ........ r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines Fix a typo in the format library. Refs #1801 ........ r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line Initialise svnmerge. ........ r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines Fix the lincense url in shared container iterator documentation. ........ r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines Fix image link in the mpi documentation. ........ r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines Fix a typo in the spirit docs. ........ r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844 ........ r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines Fix another typo in spirit docs. ........ ------------------------------------------------------------------------ r45283 | danieljames | 2008-05-11 09:49:20 -0400 (Sun, 11 May 2008) | 1 line Quote href values - our tools don't support unquoted values. ------------------------------------------------------------------------ r45359 | rwgk | 2008-05-14 15:38:08 -0400 (Wed, 14 May 2008) | 1 line braces added to resolve g++ 4.3.0 warning ------------------------------------------------------------------------ r45918 | rwgk | 2008-05-29 15:48:55 -0400 (Thu, 29 May 2008) | 66 lines See Python C++-SIG thread: "object.attr(object& attrname) proposal" Started 2008-05-25 by hohehohe2@gmail.com. Excerpts: If char const* is passed to objecjt.attr(), it uses PyObject_GetAttrStrng() or PyObject_SetAttrStrng(). If object is passed to objecjt.attr(), it takes the object as a Python string object and uses PyObject_GetAttr() or PyObject_SetAttr(). If attr() behaves like this, it can be useful when there are lots of objects which you know have the same attribute name. You can save time by first making a boost::python::object and passing it to every object's attr() inside a loop. I just made a bit of modification to boost:python locally and did a quick test, like test 1: for(int i = 0; i < n; ++i) { omain.attr(attrname) = 444; //attrname is a char const* } test 2: for(int i = 0; i < n; ++i) { object o = omain.attr(attrname); //attrname is a char const* } test 3: for(int i = 0; i < n; ++i) { omain.attr(oaaaa) = 444; //oaaaa is boost::python::object that represents a string } test 4: for(int i = 0; i < n; ++i) { object o = omain.attr(oaaaa); //oaaaa is boost::python::object that represents a string } and it reasonably reflected the difference between PyObject_*Attr() and PyObject_*AttrString. test 1 :2783ms test 2 :2357ms test 3 :1882ms test 4 :1267ms test5: PyObject_SetAttrString(po_main, "aaaa", po_num444); test6: Py_DECREF(PyObject_GetAttrString(po_main, "aaaa")); test7: PyObject_SetAttr(po_main, po_aaaa, po_num444); test8: Py_DECREF(PyObject_GetAttr(po_main, po_aaaa)); (po_ prefixed variables are PyObject*), all inside each for loop, and the results were test 5 :2410ms test 6 :2277ms test 7 :1629ms test 8 :1094ms It's boost 1.35.0, Python 2.5 on linux(gcc4.1.2). I also did the same test on windows(vs8) and the tendency was not so different. ------------------------------------------------------------------------ r45920 | rwgk | 2008-05-29 16:04:19 -0400 (Thu, 29 May 2008) | 1 line Projects using Boost.Python: PolyBoRi (text provided by Michael Brickenstein) ------------------------------------------------------------------------ r46115 | schoepflin | 2008-06-04 11:11:05 -0400 (Wed, 04 Jun 2008) | 1 line Added missing ostream header file. ------------------------------------------------------------------------ r46445 | dgregor | 2008-06-17 09:54:46 -0400 (Tue, 17 Jun 2008) | 1 line Add mime-type and eol-style properties as needed ------------------------------------------------------------------------ r46721 | dave | 2008-06-26 12:41:34 -0400 (Thu, 26 Jun 2008) | 2 lines Compatibility with Apache STDCXX library. Don't assume eh.h comes along with the other headers automatically. ------------------------------------------------------------------------ r46808 | bemandawes | 2008-06-28 09:45:21 -0400 (Sat, 28 Jun 2008) | 1 line With his kind permission, change Jaakko "J<LATIN SMALL LETTER A WITH DIARESIS>rvi" to "Jarvi" ------------------------------------------------------------------------ r46817 | djowel | 2008-06-28 14:24:17 -0400 (Sat, 28 Jun 2008) | 1 line added note on removing targets ------------------------------------------------------------------------ r46844 | dave | 2008-06-29 08:26:17 -0400 (Sun, 29 Jun 2008) | 2 lines Make valid HTML ------------------------------------------------------------------------ [SVN r47459]
This commit is contained in:
@@ -375,6 +375,27 @@
|
||||
application modules, including GUI and post-processing of results.</p>
|
||||
</dd>
|
||||
|
||||
<dt><b><a href="http://polybori.sourceforge.net/">PolyBoRi</a></b></dt>
|
||||
|
||||
<dd>
|
||||
<p><a href="mailto:brickenstein@mfo.de"
|
||||
>Michael Brickenstein</a> writes:</p>
|
||||
|
||||
<blockquote>
|
||||
<p>The core of PolyBoRi is a C++ library, which provides
|
||||
high-level data types for Boolean polynomials and monomials,
|
||||
exponent vectors, as well as for the underlying polynomial
|
||||
rings and subsets of the powerset of the Boolean variables. As
|
||||
a unique approach, binary decision diagrams are used as
|
||||
internal storage type for polynomial structures. On top of
|
||||
this C++-library we provide a Python interface. This allows
|
||||
parsing of complex polynomial systems, as well as sophisticated
|
||||
and extendable strategies for Gröbner basis computation.
|
||||
Boost.Python has helped us to create this interface in a
|
||||
very clean way.</p>
|
||||
</blockquote>
|
||||
</dd>
|
||||
|
||||
<dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
|
||||
LLC</a></b></dt>
|
||||
|
||||
@@ -435,11 +456,11 @@
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 July, 2003</p>
|
||||
29 May, 2008</p>
|
||||
|
||||
<p><i>© Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002-2003.</i></p>
|
||||
Abrahams</a> 2002-2008.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Dereferenceable Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
2
doc/v2/Extractor.html
Executable file → Normal file
2
doc/v2/Extractor.html
Executable file → Normal file
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Extractor Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
2
doc/v2/HolderGenerator.html
Executable file → Normal file
2
doc/v2/HolderGenerator.html
Executable file → Normal file
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Holder Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
@@ -74,6 +74,32 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#const_objattribute_policies-spec">Class
|
||||
<code>const_objattribute_policies</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#const_objattribute_policies-spec-synopsis">Class
|
||||
<code>const_objattribute_policies</code> synopsis</a></dt>
|
||||
|
||||
<dt><a href="#const_objattribute_policies-spec-statics">Class
|
||||
<code>const_objattribute_policies</code> static functions</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#objattribute_policies-spec">Class
|
||||
<code>objattribute_policies</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#objattribute_policies-spec-synopsis">Class
|
||||
<code>objattribute_policies</code> synopsis</a></dt>
|
||||
|
||||
<dt><a href="#objattribute_policies-spec-statics">Class
|
||||
<code>objattribute_policies</code> static functions</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#const_item_policies-spec">Class
|
||||
<code>const_item_policies</code></a></dt>
|
||||
|
||||
@@ -328,6 +354,102 @@ static void del(object const&target, char const* key);
|
||||
<!-- end -->
|
||||
<!-- begin -->
|
||||
|
||||
<h3><a name="const_objattribute_policies-spec"></a>Class
|
||||
<code>const_objattribute_policies</code></h3>
|
||||
|
||||
<p>The policies which are used for proxies representing an attribute
|
||||
access to a <code>const object</code> when the attribute name is
|
||||
given as a <code>const object</code>.</p>
|
||||
|
||||
<h4><a name="const_objattribute_policies-spec-synopsis"></a>Class
|
||||
<code>const_objattribute_policies</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python { namespace api
|
||||
{
|
||||
struct const_objattribute_policies
|
||||
{
|
||||
typedef object const& key_type;
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
}}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="const_objattribute_policies-spec-statics"></a>Class
|
||||
<code>const_objattribute_policies</code> static functions</h4>
|
||||
<pre>
|
||||
static object get(object const& target, object const& key);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> accesses the attribute of <code>target</code> named
|
||||
by <code>key</code>.</dt>
|
||||
|
||||
<dt><b>Returns:</b> An <code>object</code> managing the result of the
|
||||
attribute access.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
|
||||
<h3><a name="objattribute_policies-spec"></a>Class
|
||||
<code>objattribute_policies</code></h3>
|
||||
|
||||
<p>The policies which are used for proxies representing an attribute
|
||||
access to a mutable <code>object</code> when the attribute name is
|
||||
given as a <code>const object</code>.</p>
|
||||
|
||||
<h4><a name="objattribute_policies-spec-synopsis"></a>Class
|
||||
<code>objattribute_policies</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python { namespace api
|
||||
{
|
||||
struct objattribute_policies : const_objattribute_policies
|
||||
{
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
static void del(object const&target, object const& key);
|
||||
};
|
||||
}}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="objattribute_policies-spec-statics"></a>Class
|
||||
<code>objattribute_policies</code> static functions</h4>
|
||||
<pre>
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> sets the attribute of <code>target</code> named by
|
||||
<code>key</code> to <code>value</code>.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
static void del(object const&target, object const& key);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> deletes the attribute of <code>target</code> named
|
||||
by <code>key</code>.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
<!-- end -->
|
||||
<!-- begin -->
|
||||
|
||||
<h3><a name="const_item_policies-spec"></a>Class
|
||||
<code>const_item_policies</code></h3>
|
||||
|
||||
@@ -542,6 +664,8 @@ namespace boost { namespace python { namespace api
|
||||
//
|
||||
proxy<const_object_attribute> attr(char const*) const;
|
||||
proxy<object_attribute> attr(char const*);
|
||||
proxy<const_object_objattribute> attr(object const&) const;
|
||||
proxy<object_objattribute> attr(object const&);
|
||||
|
||||
// item access
|
||||
//
|
||||
@@ -608,6 +732,21 @@ proxy<object_attribute> attr(char const* name);
|
||||
<code>name</code> as its key.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
proxy<const_object_objattribute> attr(const object& name) const;
|
||||
proxy<object_objattribute> attr(const object& name);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> name is a <code>object</code> holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> accesses the named attribute of
|
||||
<code>*this</code>.</dt>
|
||||
|
||||
<dt><b>Returns:</b> a proxy object which binds
|
||||
<code>object(*static_cast<U*>(this))</code> as its target, and
|
||||
<code>name</code> as its key.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
template <class T>
|
||||
proxy<const_object_item> operator[](T const& key) const;
|
||||
template <class T>
|
||||
@@ -938,11 +1077,11 @@ object sum_items(object seq)
|
||||
</pre>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
13 January, 2006
|
||||
27 May, 2008
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p><i>© Copyright <a href=
|
||||
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2006.</i></p>
|
||||
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2008.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -14,6 +14,16 @@
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
# if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) /*
|
||||
> warning C4180: qualifier applied to function type has no meaning; ignored
|
||||
Peter Dimov wrote:
|
||||
This warning is caused by an overload resolution bug in VC8 that cannot be
|
||||
worked around and will probably not be fixed by MS in the VC8 line. The
|
||||
problematic overload is only instantiated and never called, and the code
|
||||
works correctly. */
|
||||
# pragma warning(disable: 4180)
|
||||
# endif
|
||||
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/bind/protect.hpp>
|
||||
|
||||
|
||||
48
include/boost/python/object_attributes.hpp
Executable file → Normal file
48
include/boost/python/object_attributes.hpp
Executable file → Normal file
@@ -17,6 +17,7 @@ struct const_attribute_policies
|
||||
{
|
||||
typedef char const* key_type;
|
||||
static object get(object const& target, char const* key);
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
|
||||
struct attribute_policies : const_attribute_policies
|
||||
@@ -25,6 +26,18 @@ struct attribute_policies : const_attribute_policies
|
||||
static void del(object const&target, char const* key);
|
||||
};
|
||||
|
||||
struct const_objattribute_policies
|
||||
{
|
||||
typedef object const key_type;
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
|
||||
struct objattribute_policies : const_objattribute_policies
|
||||
{
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
static void del(object const&target, object const& key);
|
||||
};
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
@@ -42,11 +55,30 @@ inline const_object_attribute object_operators<U>::attr(char const* name) const
|
||||
return const_object_attribute(x, name);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline object_objattribute object_operators<U>::attr(object const& name)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_objattribute(x, name);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline const_object_objattribute object_operators<U>::attr(object const& name) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_objattribute(x, name);
|
||||
}
|
||||
|
||||
inline object const_attribute_policies::get(object const& target, char const* key)
|
||||
{
|
||||
return python::getattr(target, key);
|
||||
}
|
||||
|
||||
inline object const_objattribute_policies::get(object const& target, object const& key)
|
||||
{
|
||||
return python::getattr(target, key);
|
||||
}
|
||||
|
||||
inline object const& attribute_policies::set(
|
||||
object const& target
|
||||
, char const* key
|
||||
@@ -56,6 +88,15 @@ inline object const& attribute_policies::set(
|
||||
return value;
|
||||
}
|
||||
|
||||
inline object const& objattribute_policies::set(
|
||||
object const& target
|
||||
, object const& key
|
||||
, object const& value)
|
||||
{
|
||||
python::setattr(target, key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline void attribute_policies::del(
|
||||
object const& target
|
||||
, char const* key)
|
||||
@@ -63,6 +104,13 @@ inline void attribute_policies::del(
|
||||
python::delattr(target, key);
|
||||
}
|
||||
|
||||
inline void objattribute_policies::del(
|
||||
object const& target
|
||||
, object const& key)
|
||||
{
|
||||
python::delattr(target, key);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::api
|
||||
|
||||
#endif // OBJECT_ATTRIBUTES_DWA2002615_HPP
|
||||
|
||||
6
include/boost/python/object_core.hpp
Executable file → Normal file
6
include/boost/python/object_core.hpp
Executable file → Normal file
@@ -59,6 +59,8 @@ namespace api
|
||||
|
||||
struct const_attribute_policies;
|
||||
struct attribute_policies;
|
||||
struct const_objattribute_policies;
|
||||
struct objattribute_policies;
|
||||
struct const_item_policies;
|
||||
struct item_policies;
|
||||
struct const_slice_policies;
|
||||
@@ -67,6 +69,8 @@ namespace api
|
||||
|
||||
typedef proxy<const_attribute_policies> const_object_attribute;
|
||||
typedef proxy<attribute_policies> object_attribute;
|
||||
typedef proxy<const_objattribute_policies> const_object_objattribute;
|
||||
typedef proxy<objattribute_policies> object_objattribute;
|
||||
typedef proxy<const_item_policies> const_object_item;
|
||||
typedef proxy<item_policies> object_item;
|
||||
typedef proxy<const_slice_policies> const_object_slice;
|
||||
@@ -108,6 +112,8 @@ namespace api
|
||||
//
|
||||
const_object_attribute attr(char const*) const;
|
||||
object_attribute attr(char const*);
|
||||
const_object_objattribute attr(object const&) const;
|
||||
object_objattribute attr(object const&);
|
||||
|
||||
// item access
|
||||
//
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
#ifndef PY_CONTAINER_UTILS_JDG20038_HPP
|
||||
# define PY_CONTAINER_UTILS_JDG20038_HPP
|
||||
|
||||
# include <utility>
|
||||
# include <boost/foreach.hpp>
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/extract.hpp>
|
||||
# include <boost/python/stl_iterator.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace container_utils {
|
||||
|
||||
@@ -19,11 +22,13 @@ namespace boost { namespace python { namespace container_utils {
|
||||
{
|
||||
typedef typename Container::value_type data_type;
|
||||
|
||||
// l must be a list or some container
|
||||
|
||||
for (int i = 0; i < l.attr("__len__")(); i++)
|
||||
// l must be iterable
|
||||
BOOST_FOREACH(object elem,
|
||||
std::make_pair(
|
||||
boost::python::stl_input_iterator<object>(l),
|
||||
boost::python::stl_input_iterator<object>()
|
||||
))
|
||||
{
|
||||
object elem(l[i]);
|
||||
extract<data_type const&> x(elem);
|
||||
// try if elem is an exact data_type type
|
||||
if (x.check())
|
||||
|
||||
1
include/boost/python/type_id.hpp
Executable file → Normal file
1
include/boost/python/type_id.hpp
Executable file → Normal file
@@ -11,6 +11,7 @@
|
||||
# include <boost/operators.hpp>
|
||||
# include <typeinfo>
|
||||
# include <cstring>
|
||||
# include <ostream>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
@@ -68,8 +68,9 @@ struct with_custodian_and_ward : BasePolicy_
|
||||
|
||||
bool result = BasePolicy_::precall(args_);
|
||||
|
||||
if (!result)
|
||||
if (!result) {
|
||||
Py_DECREF(life_support);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ BOOST_PYTHON_DECL bool handle_exception_impl(function0<void> f)
|
||||
{
|
||||
PyErr_SetString(PyExc_IndexError, x.what());
|
||||
}
|
||||
catch(const std::invalid_argument& x)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, x.what());
|
||||
}
|
||||
catch(const std::exception& x)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, x.what());
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
# endif
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# include <eh.h> // for _set_se_translator()
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4297)
|
||||
# pragma warning(disable:4535)
|
||||
|
||||
@@ -10,19 +10,16 @@
|
||||
#include <boost/python/str.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
namespace py = boost::python;
|
||||
|
||||
// See if we can invoke array() from C++
|
||||
numeric::array new_array()
|
||||
{
|
||||
return numeric::array(
|
||||
make_tuple(
|
||||
make_tuple(1,2,3)
|
||||
, make_tuple(4,5,6)
|
||||
, make_tuple(7,8,9)
|
||||
py::make_tuple(
|
||||
py::make_tuple(1,2,3)
|
||||
, py::make_tuple(4,5,6)
|
||||
, py::make_tuple(7,8,9)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -51,7 +48,7 @@ namespace
|
||||
str format("exception type: %sn");
|
||||
format += "exception value: %sn";
|
||||
format += "traceback:n%s" ;
|
||||
object ret = format % boost::python::make_tuple(ty, v, tr);
|
||||
object ret = format % py::make_tuple(ty, v, tr);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +68,7 @@ namespace
|
||||
// inherits that behavior from object.
|
||||
void exercise(numeric::array& y, object check)
|
||||
{
|
||||
y[make_tuple(2,1)] = 3;
|
||||
y[py::make_tuple(2,1)] = 3;
|
||||
CHECK(y);
|
||||
CHECK(y.astype('D'));
|
||||
CHECK(y.copy());
|
||||
@@ -116,12 +113,12 @@ void exercise_numarray(numeric::array& y, object check)
|
||||
CHECK(y);
|
||||
CHECK(y.type());
|
||||
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4)));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8"));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false, object()));
|
||||
CHECK (y.factory(make_tuple(1.2, 3.4), "f8", true, false, object(), make_tuple(1,2,1)));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4)));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8"));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object()));
|
||||
CHECK (y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object(), py::make_tuple(1,2,1)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
55
test/object.cpp
Executable file → Normal file
55
test/object.cpp
Executable file → Normal file
@@ -38,26 +38,61 @@ object obj_getattr(object x, char const* name)
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_objgetattr(object x, object const& name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_const_getattr(object const& x, char const* name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_const_objgetattr(object const& x, object const& name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
void obj_setattr(object x, char const* name, object value)
|
||||
{
|
||||
x.attr(name) = value;
|
||||
}
|
||||
|
||||
void obj_objsetattr(object x, object const& name, object value)
|
||||
{
|
||||
x.attr(name) = value;
|
||||
}
|
||||
|
||||
void obj_setattr42(object x, char const* name)
|
||||
{
|
||||
x.attr(name) = 42;
|
||||
}
|
||||
|
||||
void obj_objsetattr42(object x, object const& name)
|
||||
{
|
||||
x.attr(name) = 42;
|
||||
}
|
||||
|
||||
void obj_moveattr(object& x, char const* src, char const* dst)
|
||||
{
|
||||
x.attr(dst) = x.attr(src);
|
||||
}
|
||||
|
||||
void obj_objmoveattr(object& x, object const& src, object const& dst)
|
||||
{
|
||||
x.attr(dst) = x.attr(src);
|
||||
}
|
||||
|
||||
void obj_delattr(object x, char const* name)
|
||||
{
|
||||
x.attr(name).del();
|
||||
}
|
||||
|
||||
void obj_objdelattr(object x, object const& name)
|
||||
{
|
||||
x.attr(name).del();
|
||||
}
|
||||
|
||||
object obj_getitem(object x, object key)
|
||||
{
|
||||
return x[key];
|
||||
@@ -108,11 +143,21 @@ bool test_attr(object y, char* name)
|
||||
return y.attr(name);
|
||||
}
|
||||
|
||||
bool test_objattr(object y, object& name)
|
||||
{
|
||||
return y.attr(name);
|
||||
}
|
||||
|
||||
bool test_not_attr(object y, char* name)
|
||||
{
|
||||
return !y.attr(name);
|
||||
}
|
||||
|
||||
bool test_not_objattr(object y, object& name)
|
||||
{
|
||||
return !y.attr(name);
|
||||
}
|
||||
|
||||
bool test_item(object y, object key)
|
||||
{
|
||||
return y[key];
|
||||
@@ -301,11 +346,17 @@ BOOST_PYTHON_MODULE(object_ext)
|
||||
def("number", number);
|
||||
|
||||
def("obj_getattr", obj_getattr);
|
||||
def("obj_objgetattr", obj_objgetattr);
|
||||
def("obj_const_getattr", obj_const_getattr);
|
||||
def("obj_const_objgetattr", obj_const_objgetattr);
|
||||
def("obj_setattr", obj_setattr);
|
||||
def("obj_objsetattr", obj_objsetattr);
|
||||
def("obj_setattr42", obj_setattr42);
|
||||
def("obj_objsetattr42", obj_objsetattr42);
|
||||
def("obj_moveattr", obj_moveattr);
|
||||
|
||||
def("obj_objmoveattr", obj_objmoveattr);
|
||||
def("obj_delattr", obj_delattr);
|
||||
def("obj_objdelattr", obj_objdelattr);
|
||||
|
||||
def("obj_getitem", obj_getitem);
|
||||
def("obj_getitem3", obj_getitem);
|
||||
@@ -319,7 +370,9 @@ BOOST_PYTHON_MODULE(object_ext)
|
||||
def("test_not", test_not);
|
||||
|
||||
def("test_attr", test_attr);
|
||||
def("test_objattr", test_objattr);
|
||||
def("test_not_attr", test_not_attr);
|
||||
def("test_not_objattr", test_not_objattr);
|
||||
|
||||
def("test_item", test_item);
|
||||
def("test_not_item", test_not_item);
|
||||
|
||||
@@ -34,29 +34,68 @@
|
||||
>>> try: obj_getattr(x, 'foo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> try: obj_objgetattr(x, 'objfoo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
|
||||
>>> obj_setattr(x, 'foo', 1)
|
||||
>>> x.foo
|
||||
1
|
||||
>>> obj_objsetattr(x, 'objfoo', 1)
|
||||
>>> try:obj_objsetattr(x, 1)
|
||||
... except TypeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> x.objfoo
|
||||
1
|
||||
>>> obj_getattr(x, 'foo')
|
||||
1
|
||||
>>> obj_objgetattr(x, 'objfoo')
|
||||
1
|
||||
>>> try:obj_objgetattr(x, 1)
|
||||
... except TypeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> obj_const_getattr(x, 'foo')
|
||||
1
|
||||
>>> obj_const_objgetattr(x, 'objfoo')
|
||||
1
|
||||
>>> obj_setattr42(x, 'foo')
|
||||
>>> x.foo
|
||||
42
|
||||
>>> obj_objsetattr42(x, 'objfoo')
|
||||
>>> x.objfoo
|
||||
42
|
||||
>>> obj_moveattr(x, 'foo', 'bar')
|
||||
>>> x.bar
|
||||
42
|
||||
>>> obj_objmoveattr(x, 'objfoo', 'objbar')
|
||||
>>> x.objbar
|
||||
42
|
||||
>>> test_attr(x, 'foo')
|
||||
1
|
||||
>>> test_objattr(x, 'objfoo')
|
||||
1
|
||||
>>> test_not_attr(x, 'foo')
|
||||
0
|
||||
>>> test_not_objattr(x, 'objfoo')
|
||||
0
|
||||
>>> x.foo = None
|
||||
>>> test_attr(x, 'foo')
|
||||
0
|
||||
>>> x.objfoo = None
|
||||
>>> test_objattr(x, 'objfoo')
|
||||
0
|
||||
>>> test_not_attr(x, 'foo')
|
||||
1
|
||||
>>> test_not_objattr(x, 'objfoo')
|
||||
1
|
||||
>>> obj_delattr(x, 'foo')
|
||||
>>> obj_objdelattr(x, 'objfoo')
|
||||
>>> try:obj_delattr(x, 'foo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> try:obj_objdelattr(x, 'objfoo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
|
||||
Items
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/back_reference.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
|
||||
@@ -321,6 +321,19 @@ e
|
||||
>>> print_xvec(v)
|
||||
[ a b c d e f g h i j ]
|
||||
|
||||
#####################################################################
|
||||
# extend using a generator expression
|
||||
#####################################################################
|
||||
>>> v[:] = ['a','b','c','d','e'] # reset again
|
||||
>>> def generator():
|
||||
... addlist = ['f','g','h','i','j']
|
||||
... for i in addlist:
|
||||
... if i != 'g':
|
||||
... yield i
|
||||
>>> v.extend(generator())
|
||||
>>> print_xvec(v)
|
||||
[ a b c d e f h i j ]
|
||||
|
||||
#####################################################################
|
||||
# vector of strings
|
||||
#####################################################################
|
||||
|
||||
Reference in New Issue
Block a user