diff --git a/doc/v2/class.html b/doc/v2/class.html index 85e24993..fc64eabd 100644 --- a/doc/v2/class.html +++ b/doc/v2/class.html @@ -191,7 +191,7 @@ template <class F> class_& def(char const* name, F f) template <class Fn, class CallPolicy> -class_& def(char const* name, Fn fn, CallPolicy policy) +class_& def(char const* name, Fn f, CallPolicy policy)
name is a ntbs which conforms to
Python's identifier
- naming rules. If supplied, policy conforms to the CallPolicy concept requirements.
+ naming rules. In the first form, the return type of
+ f is not a reference and is not a pointer other
+ than char const* or PyObject*. In the
+ second form policy is a model of CallPolicies.
make_function(f) to
diff --git a/doc/v2/header.html b/doc/v2/header.html
index 7b36a65c..7b65547d 100644
--- a/doc/v2/header.html
+++ b/doc/v2/header.html
@@ -49,27 +49,22 @@
{{class name}}
+ {{name}}
{{class
- name}} synopsis
+ {{name}} synopsis
- {{class name}}
+ {{name}}
constructors and destructor
- {{class
- name}} comparison functions
+ {{name}} comparison functions
- {{class
- name}} modifier functions
+ {{name}} modifier functions
- {{class
- name}} observer functions
+ {{name}} observer functions
- {{class
- name}} static functions
+ {{name}} static functions
{{class overview text}} -
{{name}} synopsis
namespace boost
{
@@ -123,7 +118,7 @@ namespace boost
};
- {{name}} constructors and
destructor
{{constructor}}
@@ -164,7 +159,7 @@ namespace boost
{{name}} comparison
functions
{{function}}
@@ -186,7 +181,7 @@ namespace boost
{{name}} modifier
functions
{{function}}
@@ -208,7 +203,7 @@ namespace boost
{{name}} observer
functions
{{function}}
@@ -230,7 +225,7 @@ namespace boost
{{name}} static functions
{{function}}
diff --git a/doc/v2/module.html b/doc/v2/module.html
index f39ff4e8..0e3516ed 100644
--- a/doc/v2/module.html
+++ b/doc/v2/module.html
@@ -188,19 +188,23 @@ module& add(class_<T,Bases,HolderGenerator> const& c);
template <class Fn> -module& def(char const* name, Fn fn); +module& def(char const* name, Fn f); template <class Fn, class ResultHandler> -module& def(char const* name, Fn fn, ResultHandler handler); +module& def(char const* name, Fn f, ResultHandler handler);
f is a non-null pointer-to-function or
pointer-to-member-function. name is a ntbs which conforms to
Python's identifier
- naming rules. If supplied, policy conforms to the CallPolicy concept requirements.
+ naming rules. In the first form, the return type of
+ f is not a reference and is not a pointer other
+ than char const* or PyObject*. In the
+ second form policy is a model of CallPolicy.
make_function(f) to
diff --git a/doc/v2/reference.html b/doc/v2/reference.html
index 5e2e4463..5f82fe4d 100644
--- a/doc/v2/reference.html
+++ b/doc/v2/reference.html
@@ -353,19 +353,19 @@
|
+ |
+ Boost.Python+ +Header <boost/python/return_internal_reference.hpp>+ |
return_internal_reference
+
+ return_internal_reference synopsis
+
+ return_internal_reference static functions
+ return_internal_reference instantiations are models of CallPolicies which allow pointers and
+ references to objects held internally by a free or member function
+ argument or from the target of a member function to be returned
+ safely without making a copy of the referent. The default for its
+ first template argument handles the common case where the
+ containing object is the target (*this) of a wrapped member function.
+
+ return_internal_reference| Parameter + + | Requirements + + | Description + + | Default + + |
|---|---|---|---|
owner_arg
+
+ | A positive compile-time constant of type
+ std::size_t.
+
+ | The index of the parameter which contains the object to
+ which the reference or pointer is being returned. If used to
+ wrap a member function, parameter 1 is the target object
+ (*this).
+
+ | 1 + + |
Base
+
+ | A model of CallPolicies + + | Used for policy composition. Any
+ result_converter it supplies will be overridden by
+ return_internal_reference, but its
+ precall and postcall policies are
+ composed as described here CallPolicies.
+
+ | default_call_policies
+
+ |
return_internal_reference synopsis
+namespace boost { namespace python {
+ template <std::size_t owner_arg = 1, class Base = default_call_policies>
+ struct return_internal_reference : Base
+ {
+ static PyObject* postcall(PyObject*, PyObject* result);
+ typedef reference_existing_object result_converter;
+ };
+}}
+
+
+ default_call_policies static functions+PyObject* postcall(PyObject* args, PyObject* result); ++ +
PyTuple_Check(args) != 0
+
+ make_custodian_and_ward_postcall::postcall(args, result)
+
+#include <boost/python/module.hpp>
+#include <boost/python/class.hpp>
+#include <boost/python/return_internal_reference.hpp>
+
+class Bar
+{
+ Bar(int x) : x(x) {}
+ int get_x() const { return x; }
+ void set_x(int x) { this->x = x; }
+ private:
+ int x;
+}
+
+class Foo
+{
+ public:
+ Foo(int x) : b(x) {}
+
+ // Returns an internal reference
+ Bar const& get_bar() const { return b; }
+
+ private:
+ Bar b;
+};
+
+using namespace boost::python;
+BOOST_PYTHON_MODULE_INIT(internal_refs)
+{
+ module m("internal_refs")
+ .add(
+ class_<Bar>()
+ .def("get_x", &Bar::get_x)
+ .def("set_x", &Bar::set_x)
+ )
+ .add(
+ class_<Foo>()
+ .def_init(args<int>())
+ .def("get_bar", &Foo::get_bar
+ , return_internal_reference<>())
+ )
+ ;
+}
+
+
++>>> from internal_refs import * +>>> f = Foo(3) +>>> b1 = f.get_bar() +>>> b2 = f.get_bar() +>>> b1.get_x() +3 +>>> b2.get_x() +3 +>>> b1.set_x(42) +>>> b2.get_x() +42 ++ +
Revised + + 15 February, 2002 + + +
© Copyright Dave + Abrahams 2002. All Rights Reserved. +