|
Boost.PythonHeader <boost/python/object.hpp> |
const_attribute_policies
const_attribute_policies
synopsisconst_attribute_policies
static functionsattribute_policies
attribute_policies
synopsisattribute_policies
static functionsconst_objattribute_policies
const_objattribute_policies
synopsisconst_objattribute_policies
static functionsobjattribute_policies
objattribute_policies
synopsisobjattribute_policies
static functionsconst_item_policies
const_item_policies
synopsisconst_item_policies
static functionsitem_policies
item_policies
synopsisitem_policies
static functionsconst_slice_policies
const_slice_policies
synopsisconst_slice_policies
static functionsslice_policies
slice_policies
synopsisslice_policies
static functionsobject_operators
object_operators
synopsisobject_operators
observer functionsobject
object
synopsisobject
constructors and destructorobject
modifier functionsobject
observer functionsproxy
proxy
synopsisproxy
modifier functionsproxy
observer functionsExposes the generic Python object wrapper class object
,
and related classes. In order to avoid some potenential problems with
argument-dependent lookup and the generalized operators defined on
object
, all these facilities are defined in
namespace boost::python::api
, and object
is imported into namespace boost::python
with a
using-declaration.
class slice_nil; static const _ = slice_nil();A type that can be used to get the effect of leaving out an index in a Python slice expression:
>>> x[:-1] >>> x[::-1]C++ equivalent:
x.slice(_,-1) x[slice(_,_,-1)]
const_attribute_policies
The policies which are used for proxies representing an attribute
access to a const object
.
const_attribute_policies
synopsisnamespace boost { namespace python { namespace api { struct const_attribute_policies { typedef char const* key_type; static object get(object const& target, char const* key); }; }}}
const_attribute_policies
static functionsstatic object get(object const& target, char const* key);
key
is an ntbs.target
named
by key
.object
managing the result of the
attribute access.error_already_set
if a
Python exception is raised.attribute_policies
The policies which are used for proxies representing an attribute
access to a mutable object
.
attribute_policies
synopsisnamespace boost { namespace python { namespace api { struct attribute_policies : const_attribute_policies { static object const& set(object const& target, char const* key, object const& value); static void del(object const&target, char const* key); }; }}}
attribute_policies
static functionsstatic object const& set(object const& target, char const* key, object const& value);
key
is an ntbs.target
named by
key
to value
.error_already_set
if a
Python exception is raised.static void del(object const&target, char const* key);
key
is an ntbs.target
named
by key
.error_already_set
if a
Python exception is raised.const_objattribute_policies
The policies which are used for proxies representing an attribute
access to a const object
when the attribute name is
given as a const object
.
const_objattribute_policies
synopsisnamespace boost { namespace python { namespace api { struct const_objattribute_policies { typedef object const& key_type; static object get(object const& target, object const& key); }; }}}
const_objattribute_policies
static functionsstatic object get(object const& target, object const& key);
key
is an object
holding a string.target
named
by key
.object
managing the result of the
attribute access.error_already_set
if a
Python exception is raised.objattribute_policies
The policies which are used for proxies representing an attribute
access to a mutable object
when the attribute name is
given as a const object
.
objattribute_policies
synopsisnamespace boost { namespace python { namespace api { struct objattribute_policies : const_objattribute_policies { static object const& set(object const& target, object const& key, object const& value); static void del(object const&target, object const& key); }; }}}
objattribute_policies
static functionsstatic object const& set(object const& target, object const& key, object const& value);
key
is an object
holding a string.target
named by
key
to value
.error_already_set
if a
Python exception is raised.static void del(object const&target, object const& key);
key
is an object
holding a string.target
named
by key
.error_already_set
if a
Python exception is raised.const_item_policies
The policies which are used for proxies representing an item access
(via the Python bracket operators []
) to a
const object
.
const_item_policies
synopsisnamespace boost { namespace python { namespace api { struct const_item_policies { typedef object key_type; static object get(object const& target, object const& key); }; }}}
const_item_policies
static functionsstatic object get(object const& target, object const& key);
target
specified
by key
.object
managing the result of the
item access.error_already_set
if a
Python exception is raised.item_policies
The policies which are used for proxies representing an item access
(via the Python bracket operators []
) to a mutable
object
.
item_policies
synopsisnamespace boost { namespace python { namespace api { struct item_policies : const_item_policies { static object const& set(object const& target, object const& key, object const& value); static void del(object const& target, object const& key); }; }}}
item_policies
static functionsstatic object const& set(object const& target, object const& key, object const& value);
target
specified by
key
to value
.error_already_set
if a
Python exception is raised.static void del(object const& target, object const& key);
target
specified
by key
.error_already_set
if a
Python exception is raised.const_slice_policies
The policies which are used for proxies representing an slice access
(via the Python slice notation
[
x:
y]
) to a
const object
.
const_slice_policies
synopsisnamespace boost { namespace python { namespace api { struct const_slice_policies { typedef std::pair<handle<>, handle<> > key_type; static object get(object const& target, key_type const& key); }; }}}
const_slice_policies
static functionsstatic object get(object const& target, key_type const& key);
target
specified
by key
.object
managing the result of the
slice access.error_already_set
if a
Python exception is raised.slice_policies
The policies which are used for proxies representing an slice access
to a mutable object
.
slice_policies
synopsisnamespace boost { namespace python { namespace api { struct slice_policies : const_slice_policies { static object const& set(object const& target, key_type const& key, object const& value); static void del(object const& target, key_type const& key); }; }}}
slice_policies
static functionsstatic object const& set(object const& target, key_type const& key, object const& value);
target
specified by
key
to value
.error_already_set
if a
Python exception is raised.static void del(object const& target, key_type const& key);
target
specified
by key
.error_already_set
if a
Python exception is raised.object_operators<U>
This is the base class of object
and its
proxy
template used to supply common interface: member
functions, and operators which must be defined within the class body. Its
template parameter U
is expected to be a class derived from
object_operators<U>
. In practice users should never
use this class directly, but it is documented here because it supplies
important interface to object
and its proxies.
object_operators
synopsisnamespace boost { namespace python { namespace api { template <class U> class object_operators { public: // function call // object operator()() const; template <class A0> object operator()(A0 const&) const; template <class A0, class A1> object operator()(A0 const&, A1 const&) const; ... template <class A0, class A1,...class An> object operator()(A0 const&, A1 const&,...An const&) const; detail::args_proxy operator* () const; object operator()(detail::args_proxy const &args) const; object operator()(detail::args_proxy const &args, detail::kwds_proxy const &kwds) const; // truth value testing // typedef unspecified bool_type; operator bool_type() const; // Attribute access // proxy<const_object_attribute> attr(char const*) const; proxy<object_attribute> attr(char const*); proxy<const_object_objattribute> attr(object const&) const; proxy<object_objattribute> attr(object const&); // item access // template <class T> proxy<const_object_item> operator[](T const& key) const; template <class T> proxy<object_item> operator[](T const& key); // slicing // template <class T, class V> proxy<const_object_slice> slice(T const& start, V const& end) const template <class T, class V> proxy<object_slice> slice(T const& start, V const& end); }; }}}
object_operators
observer functionsobject operator()() const; template <class A0> object operator()(A0 const&) const; template <class A0, class A1> object operator()(A0 const&, A1 const&) const; ... template <class A0, class A1,...class An> object operator()(A0 const& a1, A1 const& a2,...An const& aN) const;
object operator()(detail::args_proxy const &args) const;
object operator()(detail::args_proxy const &args, detail::kwds_proxy const &kwds) const;
operator bool_type() const;
*this
.proxy<const_object_attribute> attr(char const* name) const; proxy<object_attribute> attr(char const* name);
*this
.object(*static_cast<U*>(this))
as its target, and
name
as its key.proxy<const_object_objattribute> attr(const object& name) const; proxy<object_objattribute> attr(const object& name);
object
holding a string.*this
.object(*static_cast<U*>(this))
as its target, and
name
as its key.template <class T> proxy<const_object_item> operator[](T const& key) const; template <class T> proxy<object_item> operator[](T const& key);
*this
indicated
by key
.object(*static_cast<U*>(this))
as its target, and
object(key)
as its key.template <class T, class V> proxy<const_object_slice> slice(T const& start; start, V const& finish) const template <class T, class V> proxy<object_slice> slice(T const& start; start, V const& finish);
*this
indicated
by std::make_pair(object(start), object(finish))
.object(*static_cast<U*>(this))
as its target, and
std::make_pair(object(start), object(finish))
as its
key.object
The intention is that object
acts as much like a
Python variable as possible. Thus expressions you'd expect to work
in Python should generally work in the same way from C++. Most of
object
's interface is provided by its base class
object_operators<object>
,
and the free functions defined in this
header.
object
synopsisnamespace boost { namespace python { namespace api { class object : public object_operators<object> { public: object(); object(object const&); template <class T> explicit object(T const& x); ~object(); object& operator=(object const&); PyObject* ptr() const; bool is_none() const; }; }}}
object
constructors and destructorobject();
None
object.template <class T> explicit object(T const& x);
x
to python and manages a
reference to it.error_already_set
and sets a Python
TypeError
exception if no such conversion is
possible.~object();
object
modifiersobject& operator=(object const& rhs);
rhs
and decrements the reference count of the object
held by *this
.object
observersPyObject* ptr() const;
bool is_none() const;
proxy
This template is instantiated with various Policies described in this
document in order to implement attribute, item, and slice access for
object
. It stores an object of type
Policies::key_type
.
proxy
synopsisnamespace boost { namespace python { namespace api { template <class Policies> class proxy : public object_operators<proxy<Policies> > { public: operator object() const; proxy const& operator=(proxy const&) const; template <class T> inline proxy const& operator=(T const& rhs) const; void del() const; template <class R> proxy operator+=(R const& rhs); template <class R> proxy operator-=(R const& rhs); template <class R> proxy operator*=(R const& rhs); template <class R> proxy operator/=(R const& rhs); template <class R> proxy operator%=(R const& rhs); template <class R> proxy operator<<=(R const& rhs); template <class R> proxy operator>>=(R const& rhs); template <class R> proxy operator&=(R const& rhs); template <class R> proxy operator|=(R const& rhs); }; }}}
proxy
observer functionsoperator object() const;
Policies::get(
target,
key
)
with the proxy's target and key objects.proxy
modifier functionsproxy const& operator=(proxy const& rhs) const; template <class T> inline proxy const& operator=(T const& rhs) const;
Policies::set(
target,
key
, object(rhs))
with the proxy's target and key
objects.template <class R> proxy operator+=(R const& rhs); template <class R> proxy operator-=(R const& rhs); template <class R> proxy operator*=(R const& rhs); template <class R> proxy operator/=(R const& rhs); template <class R> proxy operator%=(R const& rhs); template <class R> proxy operator<<=(R const& rhs); template <class R> proxy operator>>=(R const& rhs); template <class R> proxy operator&=(R const& rhs); template <class R> proxy operator|=(R const& rhs);
object(*this) @= rhs;
*this
void del() const;
Policies::del(
target,
key
)
with the proxy's target and key objects.template <class T> void del(proxy<T> const& x);
template<class L,class R> object operator>(L const&l,R const&r); template<class L,class R> object operator>=(L const&l,R const&r); template<class L,class R> object operator<(L const&l,R const&r); template<class L,class R> object operator<=(L const&l,R const&r); template<class L,class R> object operator==(L const&l,R const&r); template<class L,class R> object operator!=(L const&l,R const&r);
object(l)
and object(r)
, respectively, in
Python.template<class L,class R> object operator+(L const&l,R const&r); template<class L,class R> object operator-(L const&l,R const&r); template<class L,class R> object operator*(L const&l,R const&r); template<class L,class R> object operator/(L const&l,R const&r); template<class L,class R> object operator%(L const&l,R const&r); template<class L,class R> object operator<<(L const&l,R const&r); template<class L,class R> object operator>>(L const&l,R const&r); template<class L,class R> object operator&(L const&l,R const&r); template<class L,class R> object operator^(L const&l,R const&r); template<class L,class R> object operator|(L const&l,R const&r);
object(l)
and object(r)
, respectively, in
Python.template<class R> object& operator+=(object&l,R const&r); template<class R> object& operator-=(object&l,R const&r); template<class R> object& operator*=(object&l,R const&r); template<class R> object& operator/=(object&l,R const&r); template<class R> object& operator%=(object&l,R const&r); template<class R> object& operator<<=(object&l,R const&r) template<class R> object& operator>>=(object&l,R const&r); template<class R> object& operator&=(object&l,R const&r); template<class R> object& operator^=(object&l,R const&r); template<class R> object& operator|=(object&l,R const&r);
l
and
object(r)
, respectively.l
.inline long len(object const& obj);
def sum_items(seq): result = 0 for x in seq: result += x return resultC++ version:
object sum_items(object seq) { object result = object(0); for (int i = 0; i < len(seq); ++i) result += seq[i]; return result; }
Revised 15 March, 2010
© Copyright Dave Abrahams 2008.