mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
138 lines
5.0 KiB
HTML
138 lines
5.0 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<meta name="generator" content="Microsoft FrontPage 5.0">
|
|
<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/def_visitor.hpp></title>
|
|
|
|
<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 valign="top">
|
|
<h1 align="center"><a href="../index.html"><font size="7">Boost.Python</font></a></h1>
|
|
|
|
<h2 align="center">Header <boost/python/def_visitor.hpp></h2>
|
|
</table>
|
|
<hr>
|
|
|
|
<h2>Contents</h2>
|
|
|
|
|
|
<dl class="page-index">
|
|
<dt><a href="#introduction">Introduction</a>
|
|
<dt><a href="#classes">Classes</a>
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#def_visitor-spec">Class <code>def_visitor</code></a>
|
|
<dd> <a href="#def_visitor-synopsis">Class <code>def_visitor</code>
|
|
synopsis</a></dd>
|
|
<dd> <a href="#def_visitor-requirements">Class <code>def_visitor</code>
|
|
requirements</a></dd>
|
|
</dl>
|
|
<dt><a href="#examples">Example</a>
|
|
</dl>
|
|
<hr>
|
|
|
|
<h2><a name="introduction"></a>Introduction</h2>
|
|
|
|
|
|
<p><code><boost/python/def_visitor.hpp></code> provides a generic visitation
|
|
interface through which the <a href="class.html">class_</a> <b>def</b> member
|
|
functionality can be extended non-intrusively to avoid cluttering the <a href="class.html">class_</a>
|
|
interface. It declares the <code>def_visitor<T> </code>class template,
|
|
which is parameterized on the derived type <tt>DerivedVisitor</tt>, which provides
|
|
the actual <b>def</b> functionality through its <b>visit</b> member functions.
|
|
<h2><a name="classes"></a>Classes</h2>
|
|
|
|
<h3><a name="def_visitor-spec"></a>Class template <code>def_visitor<DerivedVisitor></code></h3>
|
|
|
|
|
|
<p>The class def_visitor is a base class paramaterized by its derived class. The
|
|
def_visitor class is a protocol class. Its derived class, DerivedVisitor, is
|
|
expected to have a member function visit. The def_visitor class is never instantiated
|
|
directly. Instead, an instance of its subclass, DerivedVisitor, is passed
|
|
on as an argument to the <a href="class.html">class_</a> def member function.
|
|
<h4>
|
|
<a name="def_visitor-synopsis" id="def_visitor-synopsis"></a>Class <code>def_visitor </code>synopsis</h4>
|
|
<pre>namespace boost { namespace python {
|
|
|
|
template <class DerivedVisitor>
|
|
class def_visitor {};
|
|
}</pre>
|
|
<h3><a name="def_visitor-requirements"></a><code>def_visitor </code>requirements</h3>
|
|
|
|
|
|
<p>The <span class="pre">client supplied class </span><span class="pre"></span><tt class="literal"><span class="pre">DerivedVisitor</span></tt>
|
|
template parameter is expected to:
|
|
<ul>
|
|
<li>be privately derived from def_visitor</li>
|
|
<li>grant friend access to class def_visitor_access</li>
|
|
<li>define either or both visit member functions listed in the table below:</li>
|
|
</ul>
|
|
|
|
|
|
<table border class="table">
|
|
<tr>
|
|
<td width="181" nowrap><b>Expression</b></td>
|
|
<td width="85"><b>Return Type</b></td>
|
|
<td width="330"><b>Requirements</b></td>
|
|
<td width="259"><b>Effects</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td nowrap>visitor.visit(cls)</td>
|
|
<td>void</td>
|
|
<td>cls is an instance of a <a href="class.html">class_</a> being wrapped
|
|
to Python. visitor is a def_visitor derived class.</td>
|
|
<td>A call to cls.def(visitor) forwards to this member function.</td>
|
|
</tr>
|
|
<tr>
|
|
<td nowrap>visitor.visit(cls, name, options)</td>
|
|
<td>void</td>
|
|
<td>cls is a class_ instance, name is a C string. visitor is a def_visitor
|
|
derived class. options is a context specific optional argument.</td>
|
|
<td>A call to cls.def(name, visitor) or cls.def(name, visitor, options) forwards
|
|
to this member function. </td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h2><a name="examples"></a>Example</h2>
|
|
|
|
|
|
<pre>class X {/*...*/};<br>
|
|
class my_def_visitor : boost::python::def_visitor<my_def_visitor>
|
|
{
|
|
friend class def_visitor_access;
|
|
|
|
template <class classT>
|
|
void visit(classT& c) const
|
|
{
|
|
c
|
|
.def("foo", &my_def_visitor::foo)
|
|
.def("bar", &my_def_visitor::bar)
|
|
;
|
|
}
|
|
|
|
static void foo(X& self);
|
|
static void bar(X& self);
|
|
};
|
|
|
|
BOOST_PYTHON_MODULE(my_ext)
|
|
{
|
|
class_<X>("X")
|
|
.def(my_def_visitor())
|
|
;
|
|
}
|
|
</pre>
|
|
<p>Revised
|
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->27 August, 2003<!--webbot bot="Timestamp" endspan i-checksum="34484" -->
|
|
</p>
|
|
|
|
|
|
<p><i>© Copyright Joel de Guzman 2003. </i> 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)
|