mirror of
https://github.com/boostorg/python.git
synced 2026-01-21 05:02:17 +00:00
doc update
[SVN r15552]
This commit is contained in:
@@ -1,77 +1,82 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content=
|
||||
"text/html; charset=iso-8859-1">
|
||||
<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/has_back_reference.hpp></title>
|
||||
<style type="text/css">
|
||||
<title>Boost.Python - <boost/python/has_back_reference.hpp></title>
|
||||
|
||||
<style type="text/css">
|
||||
p.c3 {font-style: italic}
|
||||
h2.c2 {text-align: center}
|
||||
h1.c1 {text-align: center}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width=
|
||||
"100%" summary="header">
|
||||
<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=
|
||||
"../../../../c++boost.gif" border="0"></a></h3>
|
||||
<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 class="c1">Boost.Python</h1>
|
||||
|
||||
<h2 class="c2">Header
|
||||
<boost/python/has_back_reference.hpp></h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
<dt><a href="#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#has_back_reference-spec">Class template
|
||||
<code>has_back_reference</code></a>
|
||||
<code>has_back_reference</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href=
|
||||
"#has_back_reference-spec-synopsis">Class template
|
||||
<code>has_back_reference</code> synopsis</a>
|
||||
<dt><a href="#has_back_reference-spec-synopsis">Class template
|
||||
<code>has_back_reference</code> synopsis</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#examples">Example(s)</a>
|
||||
<dt><a href="#examples">Example(s)</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p><code><boost/python/has_back_reference.hpp></code>
|
||||
defines the traits class template
|
||||
<code>has_back_reference<></code>, which can be
|
||||
specialized by the user to indicate that a wrapped class
|
||||
instance holds a <code>PyObject*</code> corresponding to a
|
||||
Python object.
|
||||
<p><code><boost/python/has_back_reference.hpp></code> defines the
|
||||
traits class template <code>has_back_reference<></code>, which can
|
||||
be specialized by the user to indicate that a wrapped class instance
|
||||
holds a <code>PyObject*</code> corresponding to a Python object.</p>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="has_back_reference-spec"></a>Class template
|
||||
<code>has_back_reference</code></h3>
|
||||
|
||||
<p>A unary metafunction whose <code>value</code> is true iff
|
||||
its argument is a <code>pointer_wrapper<></code>.
|
||||
<p>A unary metafunction whose <code>value</code> is true iff its argument
|
||||
is a <code>pointer_wrapper<></code>.</p>
|
||||
|
||||
<h4><a name="has_back_reference-spec-synopsis"></a>Class
|
||||
template <code>has_back_reference</code> synopsis</h4>
|
||||
<h4><a name="has_back_reference-spec-synopsis"></a>Class template
|
||||
<code>has_back_reference</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
@@ -82,36 +87,33 @@ namespace boost { namespace python
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<p>A "<a href=
|
||||
"../../../../more/generic_programming.html#traits">traits
|
||||
class</a>" which is inspected by Boost.Python to
|
||||
determine how wrapped classes can be constructed.
|
||||
<p>A "<a href="../../../../more/generic_programming.html#traits">traits
|
||||
class</a>" which is inspected by Boost.Python to determine how wrapped
|
||||
classes can be constructed.</p>
|
||||
|
||||
<dl class="traits-semantics">
|
||||
|
||||
<dt><code>value</code> is an integral constant convertible
|
||||
to bool of unspecified type.
|
||||
<dt><code>value</code> is an integral constant convertible to bool of
|
||||
unspecified type.</dt>
|
||||
|
||||
<dt>Specializations may substitute a value convertible to
|
||||
<code>true</code> for <code>value</code> iff for each invocation of
|
||||
<code>class_<WrappedClass>::def_init(args<</code><i>type-sequence...</i><code>>())</code>,
|
||||
there exists a corresponding constructor
|
||||
<code>WrappedClass::WrappedClass(PyObject*, </code><i>type-sequence...</i><code>)</code>. If
|
||||
such a specialization exists, the <code>WrappedClass</code>
|
||||
constructors will be called with a "back reference" pointer
|
||||
to the corresponding Python object whenever they are invoked from
|
||||
Python.
|
||||
|
||||
<code>true</code> for <code>value</code> iff for each invocation of
|
||||
<code>class_<WrappedClass>::def_init(args<</code><i>type-sequence...</i>
|
||||
<code>>())</code>, there exists a corresponding constructor
|
||||
<code>WrappedClass::WrappedClass(PyObject*, </code><i>type-sequence...</i>
|
||||
<code>)</code>. If such a specialization exists, the
|
||||
<code>WrappedClass</code> constructors will be called with a "back
|
||||
reference" pointer to the corresponding Python object whenever they are
|
||||
invoked from Python.</dt>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
<pre>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/has_back_reference.hpp>
|
||||
#include <boost/python/handle.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
@@ -121,7 +123,7 @@ struct X
|
||||
X(PyObject* self) : m_self(self), m_x(0) {}
|
||||
X(PyObject* self, int x) : m_self(self), m_x(x) {}
|
||||
|
||||
PyObject* self() { return m_self; }
|
||||
handle<> self() { return handle<>(borrowed(m_self)); }
|
||||
int get() { return m_x; }
|
||||
void set(int x) { m_x = x; }
|
||||
|
||||
@@ -153,34 +155,27 @@ boost::shared_ptr<Y> Y_self(boost::shared_ptr<Y> self) const { retur
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(back_references)
|
||||
{
|
||||
module("back_references")
|
||||
.add(
|
||||
class_<X>("X")
|
||||
.def_init()
|
||||
.def_init(args<int>())
|
||||
.def("self", &X::self)
|
||||
.def("get", &X::get)
|
||||
.def("set", &X::set)
|
||||
)
|
||||
.add(
|
||||
class_<Y, shared_ptr<Y> >("Y")
|
||||
.def_init()
|
||||
.def_init(args<int>())
|
||||
.def("get", &Y::get)
|
||||
.def("set", &Y::set)
|
||||
.def("self", Y_self)
|
||||
)
|
||||
;
|
||||
class_<X>("X")
|
||||
.def(init<int>())
|
||||
.def("self", &X::self)
|
||||
.def("get", &X::get)
|
||||
.def("set", &X::set)
|
||||
;
|
||||
|
||||
class_<Y, shared_ptr<Y> >("Y")
|
||||
.def(init<int>())
|
||||
.def("get", &Y::get)
|
||||
.def("set", &Y::set)
|
||||
.def("self", Y_self)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
The following Python session illustrates that <code>x.self()</code>
|
||||
returns the same Python object on which it is invoked, while
|
||||
<code>y.self()</code> must create a new Python object which refers to the
|
||||
same Y instance.
|
||||
|
||||
The following Python session illustrates that <code>x.self()</code>
|
||||
returns the same Python object on which it is invoked, while
|
||||
<code>y.self()</code> must create a new Python object which refers to
|
||||
the same Y instance.
|
||||
|
||||
<h3>Python code</h3>
|
||||
|
||||
<h3>Python code</h3>
|
||||
<pre>
|
||||
>>> from back_references import *
|
||||
>>> x = X(1)
|
||||
@@ -207,11 +202,13 @@ the same Y instance.
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
07 May, 2002
|
||||
29 September, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
|
||||
<p class="c3">© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.
|
||||
<p class="c3">© Copyright <a href=
|
||||
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
||||
Reserved.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user