[C++-sig] shared_ptr converters

Nicodemus nicodemus at globalite.com.br
Tue Apr 22 00:13:20 CEST 2003



David Abrahams wrote:

>Nicodemus <nicodemus at globalite.com.br> writes:
>
>  
>
>>To resume, pyste is generating the following code when the user requests
>>shared_ptr support for a class X:
>>
>>    // Temporary code for smart pointers
>>    objects::class_value_wrapper<
>>      boost::shared_ptr< X >, objects::make_ptr_instance<
>>        X, objects::pointer_holder<
>>          boost::shared_ptr< X >, X >
>>      >
>>    >();
>>    
>>
>
>Perhaps you'd like to contribute a nice wrapper function for this to
>the Boost.Python codebase, e.g.:
>
>    template <class P>
>    void register_ptr_to_python(P* = 0)
>    {
>        typedef pointee<P>::type X;
>        objects::class_value_wrapper<
>            P
>          , objects::make_ptr_instance<
>                X
>              , objects::pointer_holder<P,X>
>            >
>        >();
>    }
>
>??
>

Well, you already did all the work! ;)
Attached are the needed changes to the current CVS: 
register_ptr_to_python.hpp should go to boost/python/converter, and a 
diff for boost/python.hpp. I tested in my example like so:

    class_< A, boost::noncopyable, A_Wrapper >("A");       
    register_ptr_to_python< boost::shared_ptr<A> >();

and it seems to work fine.

Thanks again for the help Dave!

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: python.hpp.diff
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030421/ef046946/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: register_ptr_to_python.hpp
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030421/ef046946/attachment-0001.txt>


More information about the Cplusplus-sig mailing list