1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st April 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/return_arg.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/return_arg.hpp></h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#return_arg-spec">Class Template
<code>return_arg</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#return_arg-spec-synopsis">Class Template
<code>return_arg</code> synopsis</a></dt>
<dt><a href="#return_arg-spec-statics">Class
<code>return_arg</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#return_self-spec">Class Template
<code>return_self</code></a></dt>
</dl>
</dd>
<dt><a href="#examples">Example</a></dt>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<code>return_arg</code> and <code>return_self</code> instantiations are
models of <a href="CallPolicies.html">CallPolicies</a> which return the
specified argument parameter (usually <code>*this</code>) of a wrapped
(member) function.
<h2><a name="classes"></a>Classes</h2>
<h3><a name="return_arg-spec"></a>Class template
<code>return_arg</code></h3>
<table border="1" summary="return_arg template parameters">
<caption>
<b><code>return_arg</code> template parameters</b>
</caption>
<tr>
<th>Parameter</th>
<th>Requirements</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td><code>arg_pos</code></td>
<td>A positive compile-time constant of type
<code>std::size_t</code>.</td>
<td>the position of the argument to be returned.</td>
<td>1</td>
</tr>
<tr>
<td><code>Base</code></td>
<td>A model of <a href="CallPolicies.html">CallPolicies</a></td>
<td>Used for policy composition. Any <code>result_converter</code> it
supplies will be overridden by <code>return_arg</code>, but its
<code>precall</code> and <code>postcall</code> policies are composed
as described here <a href=
"CallPolicies.html#composition">CallPolicies</a>.</td>
<td><code><a href=
"default_call_policies.html#default_call_policies-spec">default_call_policies</a></code></td>
</tr>
</table>
<h4><a name="return_arg-spec-synopsis"></a>Class template
<code>return_arg</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
template <size_t arg_pos=1, class Base = default_call_policies>
struct return_arg : Base
{
static PyObject* postcall(PyObject*, PyObject* result);
struct result_converter{ template <class T> struct apply; };
};
}}
</pre>
<h4><a name="return_arg-spec-statics"></a>Class <code>return_arg</code>
static functions</h4>
<pre>
PyObject* postcall(PyObject* args, PyObject* result);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code><a href=
"http://www.python.org/doc/2.2/api/tupleObjects.html#l2h-476">PyTuple_Check</a>(args)
!= 0</code> and <code>PyTuple_Size(args) != 0</code></dt>
<dt><b>Returns:</b> <code>PyTuple_GetItem(args,arg_pos-1)</code></dt>
</dl>
<h3><a name="return_self-spec"></a>Class template
<code>return_self</code></h3>
<h4>Class template <code>return_self</code> synopsis:</h4>
<pre>
namespace boost { namespace python
{
template <class Base = default_call_policies>
struct return_self
: return_arg<1,Base>
{};
}}
</pre>
<h2><a name="examples"></a>Example</h2>
<h3>C++ module definition</h3>
<pre>
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/return_arg.hpp>
struct Widget
{
Widget() :sensitive_(true){}
bool get_sensitive() const { return sensitive_; }
void set_sensitive(bool s) { this->sensitive_ = s; }
private:
bool sensitive_;
};
struct Label : Widget
{
Label() {}
std::string get_label() const { return label_; }
void set_label(const std::string &l){ label_ = l; }
private:
std::string label_;
};
using namespace boost::python;
BOOST_PYTHON_MODULE(return_self_ext)
{
class_<widget>("Widget")
.def("sensitive", &Widget::get_sensitive)
.def("sensitive", &Widget::set_sensitive, return_self<>())
;
class_<Label, bases<Widget> >("Label")
.def("label", &Label::get_label)
.def("label", &Label::set_label, return_self<>())
;
}
</pre>
<h3>Python code</h3>
<pre>
>>> from return_self_ext import *
>>> l1 = Label().label("foo").sensitive(false)
>>> l2 = Label().sensitive(false).label("foo")
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
19 July, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>© Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> and Nikolay
Mladenov 2003. </i></p>
</body>
</html>
|