[C++-sig] wrapper & HeldType

Scott McKay skottmckay at gmail.com
Tue Oct 11 21:27:49 CEST 2005


Have you tried

class_< data_wrapper, shared_ptr< data_wrapper > >(...);
implicitly_convertible< smart_ptr< data_wrapper >, smart_ptr< data > >();

That works for me.

S

On 10/10/05, Roman Yakovenko <roman.yakovenko at gmail.com> wrote:
>
> Sorry, I pushed the wrong button.
>
> Hi. I think I found bug in treatment of held type.
> Consider next code:
>
> struct data{
> virtual int f();
> }
>
> There are 2 way to "override" f in Python.
> The first one is:
> struct data_wrapper : data, wrapper<data>{...}
>
> And the second one:
>
> struct data_wrapper : data{
> data_wrapper( PyObject* self,...)
>
> private:
> PyObject* m_self;
> }
>
> The problem is that if I want HeldType to be smart pointer, in my
> specific case is shared_ptr, then I can not use the first way as is.
>
> class_< data, data_wrapper, shared_ptr<data> >(...) will not compile.
> The message, compiler gives, is too long to post, but it say something
> that data_wrapper does not have
> constructor that takes PyObject* as first argument. If I add PyObject*
> as first argument to
> data_wrapper constructor then all works as expected.
>
> There are a few things, that I think, are wrong here:
> 1. wrapper<data> already has access to self. So the data_wrapper does
> not have to
> keep reference to self:
> struct data_wrapper : data, wrapper< data >{
> data_wrapper( PyObject* self )
> : data(), wrapper<data>(){
> //unused first argument
> }
> }
>
> 2. If I use first approach to wrap classes, then I write
> class_< data_wrapper >(...)
> in order to use custom HeldType I should switch to
> class_< data, data_wrapper, shared_ptr<data> > syntax. I thing that
> this interface
> is not perfect. The better one is
> class_< data_wrapper, shared_ptr<data> >. I think that
> Boost.Python can find out
> needed information about HeldType from HeldType itself.
>
> Hope I was clear.
>
> P.S.
> I tried to find out the place where fix should be done, but lost in
> ppl and mpl and
> recursive includes.
>
> Thanks
>
> Roman Yakovenko
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20051011/7fdc74f5/attachment.htm>


More information about the Cplusplus-sig mailing list