...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
|
Boost.PythonObjectWrapper and TypeWrapper Concepts |
This page defines two concepts used to describe classes which manage a Python objects, and which are intended to support usage with a Python-like syntax.
R
is itself an TypeWrapper, a member function invocation of
the form
x.some_function(a1, a2,...an)always has semantics equivalent to:
extract<R>(x.attr("some_function")(object(a1), object(a2),...object(an)))()When the
R
is an TypeWrapper, the result type may be
constructed by taking direct posession of:
x.attr("some_function")(object(a1), object(a2),...object(an)).ptr()[see caveat below]
X
. For a given TypeWrapper
T
, a valid constructor expression
T(a1, a2,...an)builds a new
T
object managing the result of invoking
X
with arguments corresponding to
object(a1), object(a2),...object(an)When used as arguments to wrapped C++ functions, or as the template parameter to
extract<>
, only
instances of the associated Python type will be considered a match.
dict
member function items
returns an object of type list
. Now suppose the user defines this
dict
subclass in Python:
>>> class mydict(dict): ... def items(self): ... return tuple(dict.items(self)) # return a tupleSince an instance of
mydict
is also an instance of
dict
, when used as an argument to a wrapped C++ function,
boost::python::dict
can
accept objects of Python type mydict
. Invoking
items()
on this object can result in an instance of boost::python::list
which actually
holds a Python tuple. Subsequent attempts to use list methods (e.g.
append
, or any other mutating operation) on this object will
raise the same exception that would occur if you tried to do it from
Python.
Revised 13 November, 2002
© Copyright Dave Abrahams 2002. All Rights Reserved.
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.