mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
* added return_arg policy from Nikolay Mladenov
* removed duplication from reference.html * improved automatic redirection messages [SVN r19226]
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
Automatic redirection failed, please go to <a href=
|
||||
Loading index page; if nothing happens, please go to <a href=
|
||||
"../index.html">../index.html</a>.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
p.c3 {font-style: italic}
|
||||
h2.c2 {text-align: center}
|
||||
h1.c1 {text-align: center}
|
||||
</style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -570,6 +570,24 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="return_arg.html">return_arg.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="return_arg.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"return_arg.html#return_arg-spec">return_arg</a></dt>
|
||||
|
||||
<dt><a href=
|
||||
"return_arg.html#return_self-spec">return_self</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href=
|
||||
"return_internal_reference.html">return_internal_reference.hpp</a></dt>
|
||||
|
||||
@@ -750,16 +768,18 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
|
||||
<dt><a href=
|
||||
"return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
|
||||
<dt><a href=
|
||||
"return_opaque_pointer.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
|
||||
return_opaque_pointer</a></dt>
|
||||
<dt><a href=
|
||||
"return_opaque_pointer.html#return_opaque_pointer-spec">return_opaque_pointer</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
@@ -821,139 +841,28 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
<dt><a href=
|
||||
"opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
<dt><a href=
|
||||
"opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
<dt><a href=
|
||||
"opaque_pointer_converter.html#opaque_pointer_converter-spec">opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
|
||||
opaque_pointer_converter</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
<dt><a href=
|
||||
"opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
|
||||
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
@@ -974,11 +883,13 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="register_ptr_to_python.html">register_ptr_to_python.hpp</a></dt>
|
||||
<dt><a href=
|
||||
"register_ptr_to_python.html">register_ptr_to_python.hpp</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="register_ptr_to_python.html#functions">Functions</a></dt>
|
||||
<dt><a href=
|
||||
"register_ptr_to_python.html#functions">Functions</a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
@@ -987,8 +898,7 @@
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h2><a name="utility">Utility and Infrastructure</a></h2>
|
||||
@@ -1100,8 +1010,7 @@
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
7 March, 2003
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
19 July, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p class="c3">© Copyright <a href=
|
||||
|
||||
219
doc/v2/return_arg.html
Executable file
219
doc/v2/return_arg.html
Executable file
@@ -0,0 +1,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="../../../../c++boost.gif" 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. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
100
include/boost/python/return_arg.hpp
Executable file
100
include/boost/python/return_arg.hpp
Executable file
@@ -0,0 +1,100 @@
|
||||
// Copyright David Abrahams and Nikolay Mladenov 2003. Permission to
|
||||
// copy, use, modify, sell and distribute this software is granted
|
||||
// provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with
|
||||
// no claim as to its suitability for any purpose.
|
||||
#ifndef RETURN_ARG_DWA2003719_HPP
|
||||
# define RETURN_ARG_DWA2003719_HPP
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <std::size_t>
|
||||
struct return_arg_pos_argument_must_be_positive
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
|
||||
struct return_none
|
||||
{
|
||||
template <class T> struct apply
|
||||
{
|
||||
struct type
|
||||
{
|
||||
static bool convertible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PyObject *operator()(
|
||||
typename add_reference<
|
||||
typename add_const<T>::type
|
||||
>::type
|
||||
) const
|
||||
{
|
||||
return none();
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
template <
|
||||
std::size_t arg_pos=1
|
||||
, class Base = default_call_policies
|
||||
>
|
||||
struct return_arg : Base
|
||||
{
|
||||
private:
|
||||
BOOST_STATIC_CONSTANT(bool, legal = arg_pos > 0);
|
||||
|
||||
public:
|
||||
typedef typename mpl::if_c<
|
||||
legal
|
||||
, detail::return_none
|
||||
, detail::return_arg_pos_argument_must_be_positive<arg_pos>
|
||||
// we could default to the base result_converter in case or
|
||||
// arg_pos==0 since return arg 0 means return result, but I
|
||||
// think it is better to issue an error instead, cause it can
|
||||
// lead to confusions
|
||||
>::type result_converter;
|
||||
|
||||
static PyObject* postcall(PyObject *args, PyObject* result);
|
||||
};
|
||||
|
||||
template <
|
||||
class Base = default_call_policies
|
||||
>
|
||||
struct return_self
|
||||
: return_arg<1,Base>
|
||||
{};
|
||||
|
||||
|
||||
template <size_t arg_pos, class Base>
|
||||
inline PyObject*
|
||||
return_arg<arg_pos, Base>::postcall(PyObject *args, PyObject* result)
|
||||
{
|
||||
// In case of arg_pos == 0 we could simply return Base::postcall,
|
||||
// but this is redundant
|
||||
BOOST_STATIC_ASSERT(arg_pos > 0);
|
||||
|
||||
handle<> base_result(Base::postcall(args,result));
|
||||
|
||||
if(!base_result)
|
||||
return 0;
|
||||
|
||||
return incref(PyTuple_GetItem(args,arg_pos-1));
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // RETURN_ARG_DWA2003719_HPP
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="refresh" content="0; URL=doc/index.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
Automatically loading index page... if nothing happens, please go to
|
||||
<a href="doc/index.html">doc/index.html</a>.
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -66,6 +66,7 @@ run ../test/embedding.cpp <lib>../build/boost_python
|
||||
<$(gcc-compilers)><*><library-path>$(CYGWIN_PYTHON_DLL_PATH)
|
||||
<find-library>$(PYTHON_EMBEDDED_LIBRARY) ;
|
||||
|
||||
bpl-test return_arg ;
|
||||
bpl-test staticmethod ;
|
||||
bpl-test shared_ptr ;
|
||||
bpl-test polymorphism ;
|
||||
|
||||
68
test/return_arg.cpp
Executable file
68
test/return_arg.cpp
Executable file
@@ -0,0 +1,68 @@
|
||||
// Copyright David Abrahams and Nikolay Mladenov 2003. Permission to
|
||||
// copy, use, modify, sell and distribute this software is granted
|
||||
// provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with
|
||||
// no claim as to its suitability for any purpose.
|
||||
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/def.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_;
|
||||
};
|
||||
|
||||
void return_arg_f(boost::python::object) {}
|
||||
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE(return_arg_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)//,return_arg<0>()) //error(s)
|
||||
.def("label", &Label::set_label, return_self<>())
|
||||
;
|
||||
|
||||
def("return_arg", return_arg_f, return_arg<1>());
|
||||
}
|
||||
|
||||
#include "module_tail.cpp"
|
||||
22
test/return_arg.py
Normal file
22
test/return_arg.py
Normal file
@@ -0,0 +1,22 @@
|
||||
'''
|
||||
>>> from return_arg_ext import *
|
||||
>>> l1=Label()
|
||||
>>> assert l1 is l1.label("bar")
|
||||
>>> assert l1 is l1.label("bar").sensitive(0)
|
||||
>>> assert l1.label("foo").sensitive(0) is l1.sensitive(1).label("bar")
|
||||
>>> assert return_arg is return_arg(return_arg)
|
||||
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
import sys
|
||||
import doctest
|
||||
|
||||
if args is not None:
|
||||
sys.argv = args
|
||||
return doctest.testmod(sys.modules.get(__name__))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "running..."
|
||||
import sys
|
||||
sys.exit(run()[0])
|
||||
Reference in New Issue
Block a user