diff options
Diffstat (limited to 'libs/python/doc/v2/object.html')
-rw-r--r-- | libs/python/doc/v2/object.html | 1121 |
1 files changed, 1121 insertions, 0 deletions
diff --git a/libs/python/doc/v2/object.html b/libs/python/doc/v2/object.html new file mode 100644 index 000000000..8df8ef5f8 --- /dev/null +++ b/libs/python/doc/v2/object.html @@ -0,0 +1,1121 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<!-- Copyright David Abrahams 2006. Distributed under 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) --> +<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/object.hpp></title> + </head> + + <body> + <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="../../../../boost.png" 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/object.hpp></h2> + </td> + </tr> + </table> + <hr> + + <h2>Contents</h2> + + <dl class="page-index"> + <dt><a href="#introduction">Introduction</a></dt> + + <dt><a href="#types">Types</a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#slice_nil-spec">slice_nil</a></dt> + </dl> + </dd> + + <dt><a href="#classes">Classes</a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#const_attribute_policies-spec">Class + <code>const_attribute_policies</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#const_attribute_policies-spec-synopsis">Class + <code>const_attribute_policies</code> synopsis</a></dt> + + <dt><a href="#const_attribute_policies-spec-statics">Class + <code>const_attribute_policies</code> static functions</a></dt> + </dl> + </dd> + + <dt><a href="#attribute_policies-spec">Class + <code>attribute_policies</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#attribute_policies-spec-synopsis">Class + <code>attribute_policies</code> synopsis</a></dt> + + <dt><a href="#attribute_policies-spec-statics">Class + <code>attribute_policies</code> static functions</a></dt> + </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> + + <dd> + <dl class="page-index"> + <dt><a href="#const_item_policies-spec-synopsis">Class + <code>const_item_policies</code> synopsis</a></dt> + + <dt><a href="#const_item_policies-spec-statics">Class + <code>const_item_policies</code> static functions</a></dt> + </dl> + </dd> + + <dt><a href="#item_policies-spec">Class + <code>item_policies</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#item_policies-spec-synopsis">Class + <code>item_policies</code> synopsis</a></dt> + + <dt><a href="#item_policies-spec-statics">Class + <code>item_policies</code> static functions</a></dt> + </dl> + </dd> + + <dt><a href="#const_slice_policies-spec">Class + <code>const_slice_policies</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#const_slice_policies-spec-synopsis">Class + <code>const_slice_policies</code> synopsis</a></dt> + + <dt><a href="#const_slice_policies-spec-statics">Class + <code>const_slice_policies</code> static functions</a></dt> + </dl> + </dd> + + <dt><a href="#slice_policies-spec">Class + <code>slice_policies</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#slice_policies-spec-synopsis">Class + <code>slice_policies</code> synopsis</a></dt> + + <dt><a href="#slice_policies-spec-statics">Class + <code>slice_policies</code> static functions</a></dt> + </dl> + </dd> + + <dt><a href="#object_operators-spec">Class + <code>object_operators</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#object_operators-spec-synopsis">Class + <code>object_operators</code> synopsis</a></dt> + + <dt><a href="#object_operators-spec-observers">Class + <code>object_operators</code> observer functions</a></dt> + </dl> + </dd> + + <dt><a href="#object-spec">Class <code>object</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#object-spec-synopsis">Class <code>object</code> + synopsis</a></dt> + + <dt><a href="#object-spec-ctors">Class <code>object</code> + constructors and destructor</a></dt> + + <dt><a href="#object-spec-modifiers">Class template + <code>object</code> modifier functions</a></dt> + + <dt><a href="#object-spec-observers">Class template + <code>object</code> observer functions</a></dt> + </dl> + </dd> + + <dt><a href="#proxy-spec">Class template + <code>proxy</code></a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#proxy-spec-synopsis">Class template + <code>proxy</code> synopsis</a></dt> + + <dt><a href="#proxy-spec-modifiers">Class template + <code>proxy</code> modifier functions</a></dt> + + <dt><a href="#proxy-spec-observers">Class template + <code>proxy</code> observer functions</a></dt> + </dl> + </dd> + </dl> + </dd> + + <dt><a href="#functions">Functions</a></dt> + + <dd> + <dl class="page-index"> + <dt><a href="#del-spec">del</a></dt> + + <dt><a href="#comparisons-spec">comparisons</a></dt> + + <dt><a href="#binary-spec">binary operations</a></dt> + + <dt><a href="#assignment-spec">assignment operations</a></dt> + + </dl> + + <dl class="page-index"> + <dt><a href="#object_operators-spec">operators</a></dt> + </dl> + + <dl class="page-index"> + <dt><a href="#len-spec">len()</a></dt> + </dl> + </dd> + + <dt><a href="#examples">Example</a></dt> + </dl> + <hr> + + <h2><a name="introduction"></a>Introduction</h2> + + <p>Exposes the generic Python object wrapper class <code>object</code>, + and related classes. In order to avoid some potenential problems with + argument-dependent lookup and the generalized operators defined on + <code>object</code>, all these facilities are defined in + <code>namespace boost::python::api</code>, and <code>object</code> + is imported into <code>namespace boost::python</code> with a + <i>using-declaration</i>.</p> + + <h2><a name="types"></a>Types</h2> + + <p><a name="slice_nil-spec"></a></p> +<pre> +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> + <!-- begin --> + + <h3><a name="const_attribute_policies-spec"></a>Class + <code>const_attribute_policies</code></h3> + + <p>The policies which are used for proxies representing an attribute + access to a <code>const object</code>.</p> + + <h4><a name="const_attribute_policies-spec-synopsis"></a>Class + <code>const_attribute_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct const_attribute_policies + { + typedef char const* key_type; + static object get(object const& target, char const* key); + }; +}}} +</pre> + + <h4><a name="const_attribute_policies-spec-statics"></a>Class + <code>const_attribute_policies</code> static functions</h4> +<pre> +static object get(object const& target, char const* key); +</pre> + + <dl class="function-semantics"> + <dt><b>Requires:</b> <code>key</code> is an <a href= + "definitions.html#ntbs">ntbs</a>.</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="attribute_policies-spec"></a>Class + <code>attribute_policies</code></h3> + + <p>The policies which are used for proxies representing an attribute + access to a mutable <code>object</code>.</p> + + <h4><a name="attribute_policies-spec-synopsis"></a>Class + <code>attribute_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct attribute_policies : const_attribute_policies + { + static object const& set(object const& target, char const* key, object const& value); + static void del(object const&target, char const* key); + }; +}}} +</pre> + + <h4><a name="attribute_policies-spec-statics"></a>Class + <code>attribute_policies</code> static functions</h4> +<pre> +static object const& set(object const& target, char const* key, object const& value); +</pre> + + <dl class="function-semantics"> + <dt><b>Requires:</b> <code>key</code> is an <a href= + "definitions.html#ntbs">ntbs</a>.</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, char const* key); +</pre> + + <dl class="function-semantics"> + <dt><b>Requires:</b> <code>key</code> is an <a href= + "definitions.html#ntbs">ntbs</a>.</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_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> + + <p>The policies which are used for proxies representing an item access + (via the Python bracket operators <code>[]</code>) to a + <code>const object</code>.</p> + + <h4><a name="const_item_policies-spec-synopsis"></a>Class + <code>const_item_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct const_item_policies + { + typedef object key_type; + static object get(object const& target, object const& key); + }; +}}} +</pre> + + <h4><a name="const_item_policies-spec-statics"></a>Class + <code>const_item_policies</code> static functions</h4> +<pre> +static object get(object const& target, object const& key); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> accesses the item of <code>target</code> specified + by <code>key</code>.</dt> + + <dt><b>Returns:</b> An <code>object</code> managing the result of the + item 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="item_policies-spec"></a>Class + <code>item_policies</code></h3> + + <p>The policies which are used for proxies representing an item access + (via the Python bracket operators <code>[]</code>) to a mutable + <code>object</code>.</p> + + <h4><a name="item_policies-spec-synopsis"></a>Class + <code>item_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct item_policies : const_item_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="item_policies-spec-statics"></a>Class + <code>item_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>Effects:</b> sets the item of <code>target</code> specified 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>Effects:</b> deletes the item of <code>target</code> specified + 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_slice_policies-spec"></a>Class + <code>const_slice_policies</code></h3> + + <p>The policies which are used for proxies representing an slice access + (via the Python slice notation + <code>[</code><i>x</i><code>:</code><i>y</i><code>]</code>) to a + <code>const object</code>.</p> + + <h4><a name="const_slice_policies-spec-synopsis"></a>Class + <code>const_slice_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct const_slice_policies + { + typedef std::pair<handle<>, handle<> > key_type; + static object get(object const& target, key_type const& key); + }; +}}} +</pre> + + <h4><a name="const_slice_policies-spec-statics"></a>Class + <code>const_slice_policies</code> static functions</h4> +<pre> +static object get(object const& target, key_type const& key); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> accesses the slice of <code>target</code> specified + by <code>key</code>.</dt> + + <dt><b>Returns:</b> An <code>object</code> managing the result of the + slice 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="slice_policies-spec"></a>Class + <code>slice_policies</code></h3> + + <p>The policies which are used for proxies representing an slice access + to a mutable <code>object</code>.</p> + + <h4><a name="slice_policies-spec-synopsis"></a>Class + <code>slice_policies</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + struct slice_policies : const_slice_policies + { + static object const& set(object const& target, key_type const& key, object const& value); + static void del(object const& target, key_type const& key); + }; +}}} +</pre> + + <h4><a name="slice_policies-spec-statics"></a>Class + <code>slice_policies</code> static functions</h4> +<pre> +static object const& set(object const& target, key_type const& key, object const& value); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> sets the slice of <code>target</code> specified 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, key_type const& key); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> deletes the slice of <code>target</code> specified + 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 --> + + <h3><a name="object_operators-spec"></a>Class template + <code>object_operators<U></code></h3> + + <p>This is the base class of <code>object</code> and its + <code>proxy</code> template used to supply common interface: member + functions, and operators which must be defined within the class body. Its + template parameter <code>U</code> is expected to be a class derived from + <code>object_operators<U></code>. In practice users should never + use this class directly, but it is documented here because it supplies + important interface to <code>object</code> and its proxies.</p> + + <h4><a name="object_operators-spec-synopsis"></a>Class template + <code>object_operators</code> synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + template <class U> + class object_operators + { + public: + // function call + // + object operator()() const; + + template <class A0> + object operator()(A0 const&) const; + template <class A0, class A1> + object operator()(A0 const&, A1 const&) const; + ... + template <class A0, class A1,...class An> + object operator()(A0 const&, A1 const&,...An const&) const; + + detail::args_proxy operator* () const; + object operator()(detail::args_proxy const &args) const; + object operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const; + + // truth value testing + // + typedef unspecified bool_type; + operator bool_type() const; + + // Attribute access + // + 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 + // + template <class T> + proxy<const_object_item> operator[](T const& key) const; + + template <class T> + proxy<object_item> operator[](T const& key); + + // slicing + // + template <class T, class V> + proxy<const_object_slice> slice(T const& start, V const& end) const + + template <class T, class V> + proxy<object_slice> slice(T const& start, V const& end); + }; +}}} +</pre> + + <h4><a name="object_operators-spec-observers"></a>Class template + <code>object_operators</code> observer functions</h4> +<pre> +object operator()() const; +template <class A0> +object operator()(A0 const&) const; +template <class A0, class A1> +object operator()(A0 const&, A1 const&) const; +... +template <class A0, class A1,...class An> +object operator()(A0 const& a1, A1 const& a2,...An const& aN) const; +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> + call<object>(object(*static_cast<U*>(this)).ptr(), a1, + a2,...aN)</dt> + </dl> + +<pre> +object operator()(detail::args_proxy const &args) const; +</pre> +<dl class="function-semantics"> + <dt><b>Effects:</b> + call object with arguments given by the tuple <varname>args</varname></dt> +</dl> +<pre> +object operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const; +</pre> +<dl class="function-semantics"> + <dt><b>Effects:</b> + call object with arguments given by the tuple <varname>args</varname>, and named + arguments given by the dictionary <varname>kwds</varname></dt> +</dl> + + +<pre> +operator bool_type() const; +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> Tests truth value of <code>*this</code>.</dt> + + <dt><b>Returns:</b> + call<object>(object(*static_cast<U*>(this)).ptr(), a1, + a2,...aN)</dt> + </dl> +<pre> +proxy<const_object_attribute> attr(char const* name) const; +proxy<object_attribute> attr(char const* name); +</pre> + + <dl class="function-semantics"> + <dt><b>Requires:</b> name is an <a href= + "definitions.html#ntbs">ntbs</a>.</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> +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> +proxy<object_item> operator[](T const& key); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> accesses the item of <code>*this</code> indicated + by <code>key</code>.</dt> + + <dt><b>Returns:</b> a proxy object which binds + <code>object(*static_cast<U*>(this))</code> as its target, and + <code>object(key)</code> as its key.</dt> + </dl> +<pre> +template <class T, class V> +proxy<const_object_slice> slice(T const& start; start, V const& finish) const +template <class T, class V> +proxy<object_slice> slice(T const& start; start, V const& finish); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> accesses the slice of <code>*this</code> indicated + by <code>std::make_pair(object(start), object(finish))</code>.</dt> + + <dt><b>Returns:</b> a proxy object which binds + <code>object(*static_cast<U*>(this))</code> as its target, and + <code>std::make_pair(object(start), object(finish))</code> as its + key.</dt> + </dl> + <!-- --> + + <h3><a name="object-spec"></a>Class <code>object</code></h3> + + <p>The intention is that <code>object</code> acts as much like a + Python variable as possible. Thus expressions you'd expect to work + in Python should generally work in the same way from C++. Most of + <code>object</code>'s interface is provided by its base class + <code><a + href="#object_operators-spec">object_operators</a><object></code>, + and the <a href="#functions">free functions</a> defined in this + header. +</p> + + <h4><a name="object-spec-synopsis"></a>Class <code>object</code> + synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + class object : public object_operators<object> + { + public: + object(); + + object(object const&); + + template <class T> + explicit object(T const& x); + + ~object(); + + object& operator=(object const&); + + PyObject* ptr() const; + + bool is_none() const; + }; +}}} +</pre> + + <h4><a name="object-spec-ctors"></a>Class <code>object</code> + constructors and destructor</h4> +<pre> +object(); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> Constructs an object managing a reference to the + Python <code>None</code> object.</dt> + + <dt><b>Throws:</b> nothing.</dt> + </dl> +<pre> +template <class T> +explicit object(T const& x); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> converts <code>x</code> to python and manages a + reference to it.</dt> + + <dt><b>Throws:</b> <code>error_already_set</code> and sets a Python + <code>TypeError</code> exception if no such conversion is + possible.</dt> + </dl> +<pre> +~object(); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> decrements the reference count of the + internally-held object.</dt> + </dl> + + <h4><a name="object-spec-modifiers"></a>Class <code>object</code> + modifiers</h4> +<pre> +object& operator=(object const& rhs); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> increments the reference count of the object held + by <code>rhs</code> and decrements the reference count of the object + held by <code>*this</code>.</dt> + </dl> + + <h4><a name="object-spec-observers"></a>Class <code>object</code> + observers</h4> +<pre> +PyObject* ptr() const; +</pre> + + <dl class="function-semantics"> + <dt><b>Returns:</b> a pointer to the internally-held Python + object.</dt> + </dl> + +<pre> +bool is_none() const; +</pre> + + <dl class="function-semantics"> + <dt><b>Returns:</b> result of (ptr() == Py_None)</dt> + </dl> + <!-- --> + + <h3><a name="proxy-spec"></a>Class template <code>proxy</code></h3> + + <p>This template is instantiated with various Policies described in this + document in order to implement attribute, item, and slice access for + <code>object</code>. It stores an object of type + <code>Policies::key_type</code>.</p> + + <h4><a name="proxy-spec-synopsis"></a>Class template <code>proxy</code> + synopsis</h4> +<pre> +namespace boost { namespace python { namespace api +{ + template <class Policies> + class proxy : public object_operators<proxy<Policies> > + { + public: + operator object() const; + + proxy const& operator=(proxy const&) const; + template <class T> + inline proxy const& operator=(T const& rhs) const; + + void del() const; + + template <class R> + proxy operator+=(R const& rhs); + template <class R> + proxy operator-=(R const& rhs); + template <class R> + proxy operator*=(R const& rhs); + template <class R> + proxy operator/=(R const& rhs); + template <class R> + proxy operator%=(R const& rhs); + template <class R> + proxy operator<<=(R const& rhs); + template <class R> + proxy operator>>=(R const& rhs); + template <class R> + proxy operator&=(R const& rhs); + template <class R> + proxy operator|=(R const& rhs); + }; +}}} +</pre> + + <h4><a name="proxy-spec-observers"></a>Class template <code>proxy</code> + observer functions</h4> +<pre> +operator object() const; +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> applies + <code>Policies::get(</code><i>target</i><code>,</code> <i>key</i> + <code>)</code> with the proxy's target and key objects.</dt> + </dl> + + <h4><a name="proxy-spec-modifiers"></a>Class template <code>proxy</code> + modifier functions</h4> +<pre> +proxy const& operator=(proxy const& rhs) const; +template <class T> +inline proxy const& operator=(T const& rhs) const; +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> + <code>Policies::set(</code><i>target</i><code>,</code> <i>key</i> + <code>, object(rhs))</code> with the proxy's target and key + objects.</dt> + </dl> +<pre> +template <class R> +proxy operator+=(R const& rhs); +template <class R> +proxy operator-=(R const& rhs); +template <class R> +proxy operator*=(R const& rhs); +template <class R> +proxy operator/=(R const& rhs); +template <class R> +proxy operator%=(R const& rhs); +template <class R> +proxy operator<<=(R const& rhs); +template <class R> +proxy operator>>=(R const& rhs); +template <class R> +proxy operator&=(R const& rhs); +template <class R> +proxy operator|=(R const& rhs); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> for a given operator@=, + <code>object(*this) @= rhs;</code></dt> + <dt><b>Returns:</b> <code>*this</code></dt> + </dl> +<pre> +void del() const; +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> + <code>Policies::del(</code><i>target</i><code>,</code> <i>key</i> + <code>)</code> with the proxy's target and key objects.</dt> + </dl> + <!-- --> + + <h2><a name="functions"></a>Functions</h2> +<pre> +<a name="del-spec"></a>template <class T> +void del(proxy<T> const& x); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> x.del()</dt> + </dl> +<pre> +<a name="comparisons-spec"></a> +template<class L,class R> object operator>(L const&l,R const&r); +template<class L,class R> object operator>=(L const&l,R const&r); +template<class L,class R> object operator<(L const&l,R const&r); +template<class L,class R> object operator<=(L const&l,R const&r); +template<class L,class R> object operator==(L const&l,R const&r); +template<class L,class R> object operator!=(L const&l,R const&r); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> returns the result of applying the operator to + <code>object(l)</code> and <code>object(r)</code>, respectively, in + Python.</dt> + </dl> +<pre> +<a name="binary-spec"></a> +template<class L,class R> object operator+(L const&l,R const&r); +template<class L,class R> object operator-(L const&l,R const&r); +template<class L,class R> object operator*(L const&l,R const&r); +template<class L,class R> object operator/(L const&l,R const&r); +template<class L,class R> object operator%(L const&l,R const&r); +template<class L,class R> object operator<<(L const&l,R const&r); +template<class L,class R> object operator>>(L const&l,R const&r); +template<class L,class R> object operator&(L const&l,R const&r); +template<class L,class R> object operator^(L const&l,R const&r); +template<class L,class R> object operator|(L const&l,R const&r); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> returns the result of applying the operator to + <code>object(l)</code> and <code>object(r)</code>, respectively, in + Python.</dt> + </dl> +<pre> +<a name="assignment-spec"></a> +template<class R> object& operator+=(object&l,R const&r); +template<class R> object& operator-=(object&l,R const&r); +template<class R> object& operator*=(object&l,R const&r); +template<class R> object& operator/=(object&l,R const&r); +template<class R> object& operator%=(object&l,R const&r); +template<class R> object& operator<<=(object&l,R const&r) +template<class R> object& operator>>=(object&l,R const&r); +template<class R> object& operator&=(object&l,R const&r); +template<class R> object& operator^=(object&l,R const&r); +template<class R> object& operator|=(object&l,R const&r); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> assigns to l the result of applying the + corresponding Python inplace operator to <code>l</code> and + <code>object(r)</code>, respectively.</dt> + + <dt><b>Returns:</b> <code>l</code>.</dt> + </dl> + +<pre> +inline long len(object const& obj); +</pre> + + <dl class="function-semantics"> + <dt><b>Effects:</b> PyObject_Length(obj.ptr()) </dt> + <dt><b>Returns:</b> len() of object.</dt> + </dl> + +<h2><a name="examples"></a>Example</h2> + Python code: +<pre> +def sum_items(seq): + result = 0 + for x in seq: + result += x + return result +</pre> + C++ version: +<pre> +object sum_items(object seq) +{ + object result = object(0); + for (int i = 0; i < len(seq); ++i) + result += seq[i]; + return result; +} +</pre> + <p>Revised + <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> + 15 March, 2010 + <!--webbot bot="Timestamp" endspan i-checksum="39359" --> + </p> + + <p><i>© Copyright <a href= + "http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2008.</i></p> + </body> +</html> |