Subject: Re: [boost] boost::python: to-python conversion on polymorphic class
From: Allan Johns (allan.johns_at_[hidden])
Date: 2010-12-12 18:56:25
Right you are.
With regards to my original snippet:
static PyObject* convert(const Attrib& a)
return bp::incref(bp::object(a.value()).ptr()); // return POD
typedef TypedAttribute<T> attrib_t;
TypedAttribute<T> derives from Attribute, which derives from Object (the
common polymorphic base class).
TypedAttribute<T>.value() is a function which returns the POD type
associated with the attribute.
TypedAttribBind<T> is instantiated for a range of POD types T, in order to
register the to-python converters.
This doesn't behave as expected - if I call any bound function which returns
a shared_ptr<Object> from python (where the object is actually a
TypedAttribute<T>), I just get a wrapped Object back, rather than a POD
On Mon, Dec 13, 2010 at 10:04 AM, Dave Abrahams <dave_at_[hidden]> wrote:
> At Mon, 13 Dec 2010 09:57:59 +1100,
> Allan Johns wrote:
> > Sorry I don't think I was being clear enough.
> > I want to have the derived classes to-python convert into basic types
> > ,string etc). In other words, I don't actually want TypedAttribute<T> to
> > directly bound at all.
> Oh, I see.
> > Background: I have a 'table' class that can hold various types of
> > (all derived from the same base class), a subset of which are just
> > classes for POD types. I want these POD-based attributes to automatically
> > to-python convert to the relevant types.
> > I actually have this working at the moment but not by way of boost.python
> > converters... I have a hand-rolled dispatcher going on (think std::map
> > on std::type_info), that my table class's python binding uses directly.
> > I'd rather not be duplicating boost.python functionality, if that's what
> > doing (it would seem more elegant, and more flexible, to do this with
> > boost.python itself).
> You might start by answering the question of in which way what you did
> fails to work.
> Dave Abrahams
> BoostPro Computing
> Unsubscribe & other changes:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk