diff --git a/doc/v2/operators.html b/doc/v2/operators.html index a43df858..6a551b92 100755 --- a/doc/v2/operators.html +++ b/doc/v2/operators.html @@ -1,407 +1,767 @@ - + + + + Boost.Python - <boost/python/operators.hpp> + + +
-

-

+

C++ Boost

+

Boost.Python

Header <boost/python/operators.hpp>

+

Contents

-
Introduction +
Introduction
+ +
Classes
-
Classes
+
Class + self_ns::self_t
-
Class self_ns::self_t
-
Class self_t synopsis +
Class self_t + synopsis
-
Class self_t inplace operators +
Class self_t + inplace operators
-
Class self_t comparison functions +
Class + self_t comparison functions
-
Class self_t non-member operations +
Class self_t + non-member operations
-
Class self_t unary operations +
Class + self_t unary operations
-
Class self_t value operations +
Class + self_t value operations
+
+ +
Class template + other
-
Class template other
-
Class other synopsis +
Class other + synopsis
+
+ +
Class template + operator_
-
Class template operator_
-
Class operator_ synopsis +
Class + operator_ synopsis
- -
- -
Objects -
-
-
self +
+ -
Examples +
Objects
+ +
+
+
self
+
+
+ +
Examples

Introduction

-

<boost/python/operators.hpp> provides types - and functions for automatically generating Python special - methods from the corresponding C++ constructs. Most of these - constructs are operator expressions, hence the name. To use the - facility, substitute the self object for an object of the - class type being wrapped in the expression to be exposed, and pass - the result to class_<>::def(). Much - of what is exposed in this header should be considered part of the - implementation, so is not documented in detail here. +

<boost/python/operators.hpp> provides types and + functions for automatically generating Python special methods + from the corresponding C++ constructs. Most of these constructs are + operator expressions, hence the name. To use the facility, substitute the + self object for an object of the + class type being wrapped in the expression to be exposed, and pass the + result to class_<>::def(). Much of + what is exposed in this header should be considered part of the + implementation, so is not documented in detail here.

Classes

Class self_ns::self_t

-

self_ns::self_t is the actual type of the self object. The library - isolates self_t in its own namespace, - self_ns, in order to prevent the generalized operator - templates which operate on it from being found by - argument-dependent lookup in other contexts. This should be - considered an implementation detail, since users should never have - to mention self_t directly. +

self_ns::self_t is the actual type of the self object. The library isolates + self_t in its own namespace, self_ns, in order + to prevent the generalized operator templates which operate on it from + being found by argument-dependent lookup in other contexts. This should + be considered an implementation detail, since users should never have to + mention self_t directly.

-

Class self_ns::self_t synopsis

+

Class self_ns::self_t + synopsis

 namespace boost { namespace python { namespace self_ns {
 {
    class self_t {};
 
    // inplace operators
-   template <class T> operator_<unspecified> operator+=(self_t, T);
-   template <class T> operator_<unspecified> operator-=(self_t, T);
-   template <class T> operator_<unspecified> operator*=(self_t, T);
-   template <class T> operator_<unspecified> operator/=(self_t, T);
-   template <class T> operator_<unspecified> operator%=(self_t, T);
-   template <class T> operator_<unspecified> operator>>=(self_t, T);
-   template <class T> operator_<unspecified> operator<<=(self_t, T);
-   template <class T> operator_<unspecified> operator&=(self_t, T);
-   template <class T> operator_<unspecified> operator^=(self_t, T);
-   template <class T> operator_<unspecified> operator|=(self_t, T);
+   template <class T> operator_<unspecified> operator+=(self_t, T);
+   template <class T> operator_<unspecified> operator-=(self_t, T);
+   template <class T> operator_<unspecified> operator*=(self_t, T);
+   template <class T> operator_<unspecified> operator/=(self_t, T);
+   template <class T> operator_<unspecified> operator%=(self_t, T);
+   template <class T> operator_<unspecified> operator>>=(self_t, T);
+   template <class T> operator_<unspecified> operator<<=(self_t, T);
+   template <class T> operator_<unspecified> operator&=(self_t, T);
+   template <class T> operator_<unspecified> operator^=(self_t, T);
+   template <class T> operator_<unspecified> operator|=(self_t, T);
 
    // comparisons
-   template <class L, class R> operator_<unspecified> operator==(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator!=(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator<(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator>(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator<=(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator>=(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator==(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator!=(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator<(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator>(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator<=(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator>=(L const&, R const&);
 
    // non-member operations
-   template <class L, class R> operator_<unspecified> operator+(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator-(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator*(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator/(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator%(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator>>(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator<<(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator&(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator^(L const&, R const&);
-   template <class L, class R> operator_<unspecified> operator|(L const&, R const&);
-   template <class L, class R> operator_<unspecified> pow(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator+(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator-(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator*(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator/(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator%(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator>>(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator<<(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator&(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator^(L const&, R const&);
+   template <class L, class R> operator_<unspecified> operator|(L const&, R const&);
+   template <class L, class R> operator_<unspecified> pow(L const&, R const&);
 
    // unary operations
-   operator_<unspecified> operator-(self_t);
-   operator_<unspecified> operator+(self_t);
-   operator_<unspecified> operator~(self_t);
+   operator_<unspecified> operator-(self_t);
+   operator_<unspecified> operator+(self_t);
+   operator_<unspecified> operator~(self_t);
 
    // value operations
-   operator_<unspecified> int_(self_t);
-   operator_<unspecified> long_(self_t);
-   operator_<unspecified> float_(self_t);
-   operator_<unspecified> complex_(self_t);
-   operator_<unspecified> str(self_t);
+   operator_<unspecified> int_(self_t);
+   operator_<unspecified> long_(self_t);
+   operator_<unspecified> float_(self_t);
+   operator_<unspecified> complex_(self_t);
+   operator_<unspecified> str(self_t);
 
 }}};
 
+ The tables below describe the methods generated when the results of the + expressions described are passed as arguments to class_<>::def(). + x is an object of the class type being wrapped. -The tables below describe the methods generated when the results of -the expressions described are passed as arguments to class_<>::def(). -x is an object of the class type being wrapped. +

Class self_t inplace + operators

+ In the table below, If r is an object of type + other<T>, + y is an object of type T; otherwise, + y is an object of the same type as + r. + + + -

Class self_t inplace operators

+ + + + + -In the table below, If r is an object of type -other<T>, -y is an object of type T; otherwise, -y is an object of the same type as -r. + -
C++ ExpressionPython Method NameC++ Implementation
self += r__iadd__
- - + - + - - + - + - - + - + - - + -
C++ Expression - Python Method Name - C++ Implementation + x += y
self += r -__iadd__ -x += y +
self -= r
self -= r -__isub__ -x -= y + __isub__
self *= r -__imul__ -x *= y + x -= y
self /= r -__idiv__ -x /= y +
self *= r
self %= r -__imod__ -x %= y + __imul__
self >>= r -__irshift__ -x >>= y + x *= y
self <<= r -__ilshift__ -x <<= y +
self /= r
self &= r -__iand__ -x &= y + __idiv__
self ^= r -__ixor__ -x ^= y + x /= y
self |= r -__ior__ -x |= y -
+ + self %= r -

Class self_t comparison - functions

+ __imod__ -In the tables below, if r is of type self_t, y is an object -of the same type as x; -
-if l or r is an object of type other<T>, -y is an object of type T; -
-otherwise, y is an object of the same type as -l or r.
-l -is never of type self_t. + x %= y + -

-The column of Python Expressions illustrates the expressions -that will be supported in Python for objects convertible to the types -of x and y. The secondary operation arises -due to Python's reflection -rules for rich comparison operators, and are only used when the -corresponding operation is not defined as a method of the -y object. + + self >>= r - - - + - + - - + - + - - + - + - - + - + - - -
C++ Expression Python Method Name C++ Implementation -Python Expressions
(primary, secondary) - +
__irshift__
self == r __eq__ x == y -x == y, y == x + x >>= y
l == self __eq__ y == x -y == x, x == y +
self <<= r
self != r __ne__ x != y -x != y, y != x + __ilshift__
l != self __ne__ y != x -y != x, x != y + x <<= y
self < r __lt__ x < y -x < y, y > x +
self &= r
l < self __gt__ y < x -y > x, x < y + __iand__
self > r __gt__ x > y -x > y, y < x + x &= y
l > self __lt__ y > x -y < x, x > y +
self ^= r
self <= r __le__ x <= y -x <= y, y >= x + __ixor__
l <= self __ge__ y <= x -y >= x, x <= y + x ^= y
self >= r __ge__ x >= y -x >= y, y <= x +
self |= r
l >= self __le__ y >= x -y <= x, x >= y + __ior__
+ x |= y + + +

Class self_t + comparison functions

+ In the tables below, if r is of type self_t, y is an object of + the same type as x;
+ if l or r is an object of type + other<T>, + y is an object of type T;
+ otherwise, y is an object of the same type as + l or r.
+ l is never of type self_t. -

Class - self_t non-member operations

+

The column of Python Expressions illustrates the expressions + that will be supported in Python for objects convertible to the types of + x and y. The secondary operation arises due to + Python's reflection + rules for rich comparison operators, and are only used when the + corresponding operation is not defined as a method of the y + object.

-The operations whose names begin with "__r" -below will only be called if the left-hand operand does not already -support the given operation, as described here. + + + -
C++ Expression
- - - + - + - - - + - + - - - + - + - -
C++ Expression Python Method Name C++ Implementation - + Python Method Name
self + r __add__ x + y -
l + self __radd__ y + x + C++ Implementation
self - r __sub__ x - y -
l - self __rsub__ y - x + Python Expressions
+ (primary, secondary)
self * r __mul__ x * y -
l * self __rmul__ y * x +
self == r
self / r __div__ x / y -
l / self __rdiv__ y / x + __eq__
self % r __mod__ x % y -
l % self __rmod__ y % x + x == y
self >> r __rshift__ x >> y -
l >> self __rrshift__ y >> x + x == y, y == x
self << r __lshift__ x << y -
l << self __rlshift__ y << x +
l == self
self & r __and__ x & y -
l & self __rand__ y & x + __eq__
self ^ r __xor__ x ^ y -
l ^ self __rxor__ y ^ x + y == x
self | r __or__ x | y -
l | self __ror__ y | x + y == x, x == y
pow(self, r) __pow__ pow(x, y) -
pow(l, self) __rpow__ pow(y, x) +
self != r
+ __ne__ + x != y -

Class - self_t unary operations

+ x != y, y != x + - - + - - -
C++ Expression Python Method Name C++ Implementation - +
l != self
-self __neg__ -x -
+self__pos__ +x -
~self__invert__ ~x + __ne__
+ y != x + y != x, x != y + -

Class - self_t value operations

+ + self < r - - - - -
C++ Expression Python Method Name C++ Implementation - + __lt__
int_(self)__int__ long(x) -
long___long__ PyLong_FromLong(x) -
float___float__ double(x) -
complex___complex__ std::complex<double>(x) -
str__str__ lexical_cast<std::string>(x) + x < y
+ x < y, y > x + + + l < self + __gt__ + + y < x + + y > x, x < y + + + + self > r + + __gt__ + + x > y + + x > y, y < x + + + + l > self + + __lt__ + + y > x + + y < x, x > y + + + + self <= r + + __le__ + + x <= y + + x <= y, y >= x + + + + l <= self + + __ge__ + + y <= x + + y >= x, x <= y + + + + self >= r + + __ge__ + + x >= y + + x >= y, y <= x + + + + l >= self + + __le__ + + y >= x + + y <= x, x >= y + + + +

Class self_t non-member + operations

+ The operations whose names begin with "__r" below will only + be called if the left-hand operand does not already support the given + operation, as described here. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C++ ExpressionPython Method NameC++ Implementation
self + r__add__x + y
l + self__radd__y + x
self - r__sub__x - y
l - self__rsub__y - x
self * r__mul__x * y
l * self__rmul__y * x
self / r__div__x / y
l / self__rdiv__y / x
self % r__mod__x % y
l % self__rmod__y % x
self >> r__rshift__x >> y
l >> self__rrshift__y >> x
self << r__lshift__x << y
l << self__rlshift__y << x
self & r__and__x & y
l & self__rand__y & x
self ^ r__xor__x ^ y
l ^ self__rxor__y ^ x
self | r__or__x | y
l | self__ror__y | x
pow(self, r)__pow__pow(x, y)
pow(l, self)__rpow__pow(y, x)
+ +

Class self_t unary + operations

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C++ ExpressionPython Method NameC++ Implementation
-self__neg__-x
+self__pos__+x
~self__invert__~x
+ +

Class self_t value + operations

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C++ ExpressionPython Method NameC++ Implementation
int_(self)__int__long(x)
long___long__PyLong_FromLong(x)
float___float__double(x)
complex___complex__std::complex<double>(x)
str__str__lexical_cast<std::string>(x)

Class Template other

-

Instances of other<T> can be used in - operator expressions with self; the - result is equivalent to the same expression with a T - object in place of other<T>. Use - other<T> to prevent construction of a - T object in case it is heavyweight, when no - constructor is available, or simply for clarity. +

Instances of other<T> can be used in operator + expressions with self; the result is equivalent + to the same expression with a T object in place of + other<T>. Use other<T> to prevent + construction of a T object in case it is heavyweight, when + no constructor is available, or simply for clarity.

Class Template other synopsis

@@ -413,19 +773,18 @@ namespace boost { namespace python
   };
 }}
 
+ - +

Class Template + detail::operator_

-

Class Template detail::operator_

+

Instantiations of detail::operator_<> are used as + the return type of operator expressions involving self. This should be considered an implementation + detail and is only documented here as a way of showing how the result of + self-expressions match calls to class_<>::def().

-

Instantiations of detail::operator_<> are - used as the return type of operator expressions involving self. This should be considered an - implementation detail and is only documented here as a way of - showing how the result of self-expressions match - calls to class_<>::def(). -

Class Template detail::operator_ synopsis

@@ -440,8 +799,7 @@ namespace boost { namespace python { namespace detail
 
     

Objects

-

self - +

self

 namespace boost { namespace python
 {
@@ -450,15 +808,15 @@ namespace boost { namespace python
 

Example

-
-#include <boost/python/module.hpp>
+#include <boost/python/module_init.hpp>
 #include <boost/python/class.hpp>
 #include <boost/python/operators.hpp>
 #include <boost/operators.hpp>
 
 struct number
-   : boost::integer_arithmetic<number>
+   : boost::integer_arithmetic<number>
 {
    number(long x_) : x(x_) {}
    operator long() const { return x; }
@@ -480,52 +838,50 @@ struct number
 using namespace boost::python;
 BOOST_PYTHON_MODULE_INIT(demo)
 {
-   module("demo")
-      .add(
-         class_<number>("number")
-            // interoperate with self
-            .def(self += self)
-            .def(self + self)
-            .def(self -= self)
-            .def(self - self)
-            .def(self *= self)
-            .def(self * self)
-            .def(self /= self)
-            .def(self / self)
-            .def(self %= self)
-            .def(self % self)
-            
-            // Convert to Python int
-            .def(int_(self))
+   class_<number>("number")
+      // interoperate with self
+      .def(self += self)
+      .def(self + self)
+      .def(self -= self)
+      .def(self - self)
+      .def(self *= self)
+      .def(self * self)
+      .def(self /= self)
+      .def(self / self)
+      .def(self %= self)
+      .def(self % self)
 
-            // interoperate with long
-            .def(self += long())
-            .def(self + long())
-            .def(long() + self)
-            .def(self -= long())
-            .def(self - long())
-            .def(long() - self)
-            .def(self *= long())
-            .def(self * long())
-            .def(long() * self)
-            .def(self /= long())
-            .def(self / long())
-            .def(long() / self)
-            .def(self %= long())
-            .def(self % long())
-            .def(long() % self)
+      // Convert to Python int
+      .def(int_(self))
 
-         )
+      // interoperate with long
+      .def(self += long())
+      .def(self + long())
+      .def(long() + self)
+      .def(self -= long())
+      .def(self - long())
+      .def(long() - self)
+      .def(self *= long())
+      .def(self * long())
+      .def(long() * self)
+      .def(self /= long())
+      .def(self / long())
+      .def(long() / self)
+      .def(self %= long())
+      .def(self % long())
+      .def(long() % self)
       ;
 }
 

Revised - 3 June, 2002 - + 29 Sept, 2002 +

- -

© Copyright Dave - Abrahams 2002. All Rights Reserved. +

© Copyright Dave Abrahams 2002. All Rights + Reserved.

+ + diff --git a/doc/v2/reference_existing_object.html b/doc/v2/reference_existing_object.html index dbb7a983..59a47216 100644 --- a/doc/v2/reference_existing_object.html +++ b/doc/v2/reference_existing_object.html @@ -1,47 +1,59 @@ - + + + + Boost.Python - <boost/python/reference_existing_object.hpp> + + +
-

-

+

C++ Boost

+

Boost.Python

Header <boost/python/reference_existing_object.hpp>

+

Contents

-
Classes +
Classes
Class - reference_existing_object + reference_existing_object
Class - reference_existing_object synopsis + reference_existing_object synopsis
-
Class - reference_existing_object metafunctions +
Class + reference_existing_object metafunctions
+
+
-
Example +
Example

@@ -51,19 +63,20 @@ reference_existing_object

reference_existing_object is a model of ResultConverterGenerator which can be - used to wrap C++ functions which return a reference or pointer to a C++ - object. When the wrapped function is called, the value referenced by its - return value is not copied. A new Python object is created which contains a - pointer to the referent, and no attempt is made to ensure that the lifetime - of the referent is at least as long as that of the corresponding Python - object. Thus, it can be highly - dangerous to use reference_existing_object without - additional lifetime management from such models of ResultConverterGenerator + which can be used to wrap C++ functions which return a reference or + pointer to a C++ object. When the wrapped function is called, the value + referenced by its return value is not copied. A new Python object is + created which contains a pointer to the referent, and no attempt is made + to ensure that the lifetime of the referent is at least as long as that + of the corresponding Python object. Thus, it can be highly dangerous to use + reference_existing_object without additional lifetime + management from such models of CallPolicies as with_custodian_and_ward. This class is used in the implementation of return_internal_reference. + "return_internal_reference.html#return_internal_reference-spec">return_internal_reference.

Class reference_existing_object synopsis

@@ -85,22 +98,22 @@ template <class T> struct apply
Requires: T is U& or - U*for some U. + U*for some U.
Returns: typedef to_python_indirect<T,V> type, where V is a HolderObjectGenerator which constructs an instance holder containing an unowned - U* pointing to the referent of the wrapped function's return - value. + U* pointing to the referent of the wrapped function's + return value.

Example

-

In C++: +

In C++:

-#include <boost/python/module.hpp>
+#include <boost/python/module_init.hpp>
 #include <boost/python/class.hpp>
 #include <boost/python/reference_existing_object.hpp>
 #include <boost/python/return_value_policy.hpp>
@@ -130,12 +143,10 @@ Singleton& get_it()
 using namespace boost::python;
 BOOST_PYTHON_MODULE_INIT(singleton)
 {
-   module("singleton")
-      .def("get_it", get_it)
-      .add(
-         class_<Singleton>()
-            .def("exchange", &Singleton::exchange)
-         );
+    def("get_it", get_it, reference_existing_object());
+    class_<Singleton>()
+       .def("exchange", &Singleton::exchange)
+       ;
 }
 
In Python: @@ -153,9 +164,13 @@ BOOST_PYTHON_MODULE_INIT(singleton)

Revised - 14 February 2002 + 29 September 2002 + +

- -

© Copyright Dave - Abrahams 2002. All Rights Reserved. +

© Copyright Dave Abrahams 2002. All Rights + Reserved.

+ + diff --git a/doc/v2/return_internal_reference.html b/doc/v2/return_internal_reference.html index 347db88c..596ed2c6 100644 --- a/doc/v2/return_internal_reference.html +++ b/doc/v2/return_internal_reference.html @@ -1,114 +1,129 @@ - + + + + - Boost.Python - <boost/python/return_internal_reference.hpp> + Boost.Python - + <boost/python/return_internal_reference.hpp> + + +
-

-

+

C++ Boost

+

Boost.Python

-

Header <boost/python/return_internal_reference.hpp>

+

Header + <boost/python/return_internal_reference.hpp>

+

Contents

-
Introduction +
Introduction
- -
Classes +
Classes
-
Class Template return_internal_reference +
Class Template + return_internal_reference
- -
Class Template - return_internal_reference synopsis +
Class + Template return_internal_reference + synopsis
Class - return_internal_reference static functions + return_internal_reference static + functions
+
+
- -
Example +
Example

Introduction

- - return_internal_reference instantiations are models of CallPolicies which allow pointers and + 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. + 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.

Classes

-

Class template return_internal_reference

+

Class template + return_internal_reference

- - +
- - - + + + + + + + + + + - - + - - - + +
return_internal_reference template parameters
Parameter - - Requirements - - Description - - Default
owner_arg + ParameterRequirementsDescriptionDefault
owner_arg A positive compile-time constant of type - std::size_t. + 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). Note that if the target Python object - type doesn't support weak references, a Python - TypeError exception will be raised when the - function being wrapped is called. + 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). Note + that if the target Python object type doesn't support weak + references, a Python TypeError exception will be raised + when the function being wrapped is called.1 + 1
Base + BaseA model of CallPolicies + A model of CallPoliciesUsed 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 + 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
-

Class template return_internal_reference synopsis

+

Class template + return_internal_reference synopsis

 namespace boost { namespace python
 {
@@ -116,31 +131,34 @@ namespace boost { namespace python
    struct return_internal_reference : Base
    {
       static PyObject* postcall(PyObject*, PyObject* result);
-      typedef reference_existing_object result_converter;
+      typedef reference_existing_object result_converter;
    };
 }}
 

Class default_call_policies static functions

-
 PyObject* postcall(PyObject* args, PyObject* result);
 
-
Requires: PyTuple_Check(args) != 0 +
Requires: PyTuple_Check(args) + != 0
-
Returns: with_custodian_and_ward_postcall::postcall(args, result) +
Returns: + with_custodian_and_ward_postcall::postcall(args, + result)
-

Example

-

C++ module definition

- +

C++ module definition

-#include <boost/python/module.hpp>
+#include <boost/python/module_init.hpp>
 #include <boost/python/class.hpp>
 #include <boost/python/return_internal_reference.hpp>
 
@@ -168,24 +186,20 @@ class Foo
 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<>())
-         )
+   class_<Bar>()
+      .def("get_x", &Bar::get_x)
+      .def("set_x", &Bar::set_x)
+      ;
+
+   class_<Foo>()
+      .def_init(args<int>())
+      .def("get_bar", &Foo::get_bar
+          , return_internal_reference<>())
       ;
 }
 
-

Python code

- +

Python code

 >>> from internal_refs import *
 >>> f = Foo(3)
@@ -202,9 +216,13 @@ BOOST_PYTHON_MODULE_INIT(internal_refs)
 
     

Revised - 15 February, 2002 + 15 February, 2002 +

-

© Copyright Dave - Abrahams 2002. All Rights Reserved. +

© Copyright Dave Abrahams 2002. All Rights + Reserved.

+ +