| <!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 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; }; |
| template <class Sig> struct extract_return_type : mpl::at_c<Sig, arg_pos>{}; |
| |
| }; |
| }} |
| </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= |
| "http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> and Nikolay |
| Mladenov 2003. </i></p> |
| </body> |
| </html> |
| |