[C++-sig] Re: Making Boost.Python understand DerivedSafe
Nikolay Mladenov
nickm at sitius.com
Tue Jun 22 00:01:57 CEST 2004
Try to satisfy the detailed requirements for the "HeldType"
(http://www.boost.org/libs/python/doc/v2/class.html#class_-spec).
I think you'll have to define get_pointer(CutScenePtr).
And maybe specialize python::pointee.
HTH,
Nikolay
Chad Austin wrote:
>
> (I am not yet subscribed to the list... it seems mailman is having
> trouble sending me the authorization. Please CC me on replies..
> Thanks.)
>
> Hi all,
>
> I just started using Boost.Python to embed Python in a project of
> mine. I spent a couple days evaluating, testing, and studying, but it
> seems to have paid off! Great job on making such a time-saving
> library!
>
> I am wrapping an internally refcounted class called CutScene.
> CutScene objects are referenced by RefPtr<CutScene> smart pointers,
> typedef'd as CutScenePtr. I export the class with:
>
> class_<CutScene, CutScenePtr>("CutScene").def /*etc*/;
>
> So far, so good. The problem comes about when I want to pass a
> CutScenePtr into object::operator() to call a function. If I pass a
> CutScenePtr object in, it says something about reject_raw_object_ptr:
>
> d:\Projects\empyrean\empyrean\third-party-vc7\include\boost\python\converter\arg_to_python.hpp(244)
> : error C2784: 'void
> boost::python::converter::detail::reject_raw_object_ptr(T *)' : could
> not deduce template argument for 'T1 *' from 'pyr::RefPtr<T>'
> with
> [
> T=pyr::CutScene
> ]
>
> If I pass the result of CutScenePtr::get() into operator() I get a
> runtime error about Boost.Python not knowing how to convert
> RefDerivedSafe<T>* to a Python object. This makes sense, because
> RefPtr's implicit conversion operator, operator->, and get() all
> return RefDerivedSafe<T>*. (RefDerivedSafe<T> is a special class
> derived from T that prevents C++ clients from accidentally calling
> delete, ref(), or unref() on a smart pointer. This techique is used in
> both ATL and nsCOMPtr in Mozilla).
>
> Here's my question: Is there a way to tell Boost.Python that
> ptr(someCutScenePtr) is valid and should be equivalent to
> ptr(someCutScenePtr.get()) and/or that RefDerivedSafe<T>* can be
> implicitly converted to T*? I've tried several different things, and
> nothing seems to work...
>
> I'm currently using Boost 1.31 with both gcc 3.3.1 and VS.NET 2003.
>
> Many thanks,
> Chad
--
Nikolay Mladenov
Sitius Automation Inc.
www.sitius.com
More information about the Cplusplus-sig
mailing list