|
Boost : |
From: Rainer Deyke (root_at_[hidden])
Date: 2001-03-27 10:15:46
----- Original Message -----
From: "David Abrahams" <abrahams_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, March 26, 2001 7:52 PM
Subject: Re: [boost] Python: is there any way to make this work?
>
> ----- Original Message -----
> From: "Rainer Deyke" <root_at_[hidden]>
> > struct A { virtual ~A(); }
> > struct B : A { void f(); }
> > void call_f(B& b) { b.f(); }
> > boost::shared_ptr<A> get_B() { return boost::shared_ptr<A>(new B); }
> >
> > // Wrapper code ommited for brevity.
> > // Then in Python...
> > b = get_B()
> > call_f(b) # This works.
> > b.f() # This doesn't.
> >
> > This strikes me as inconsistent. I suspect that it would be possible to
> > remove this inconsistency by modifying 'boost::python::to_python'.
>
> What modification did you have in mind? I don't think I'd want to try to
> automatically downcast every returned smart pointer to its most-derived
> type...
That is more or less what I had in mind. Maybe this automatic downcasting
could be made optional:
boost::shared_ptr<A> a;
boost::python::ref r(boost::python::to_python(a)); // current semantics
boost::python::ref r(boost::python::to_python_with_downcast(a));
boost::shared_ptr<A> f();
my_class_builder.def(f); // current semantics
my_class_builder.def_with_downcast(f); // The return value of 'f'
// is automatically downcast.
-- Rainer Deyke (root_at_[hidden]) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk