[C++-sig] Re: shared_ptr<Object>

John Meinel john at johnmeinel.com
Sun Oct 31 19:18:48 CET 2004


David Abrahams wrote:
> John Meinel <john at johnmeinel.com> writes:
> 
> 
> I have lots of questions about your questions, but see ******** below
> before answering.
> 

I recognized I use the wrong terms in several places. Using "object" 
instead of "class", etc. However, your ***** was what I needed, as:
http://www.boost.org/libs/python/doc/v2/register_ptr_to_python.html#register_ptr_to_python-spec

Is pretty much exactly what I am doing, just with a little more hierarchy.


[...]

> 
> Please show code that produces the error... otherwise I will assume
> you just added it 
> 
If you change the line:
	class_<mine, mine_w, bases<parent>, boost::noncopyable>("mine")
To:
	class_<mine, boost::shared_ptr<mine>, mine_w
		, bases<parent>, boost::noncopyable>("mine")

It will not compile.

> 
> What happens that indicates to you that it will "not allow you to
> inherit the C++ object" in python?  BTW, you can't "inherit a C++
> object."  I think I know what you mean, but using clear and correct
> terminology will help me to help you.
> 

Sorry, again here I meant I cannot create a Python class that inherits 
properly from the C++ class. From my limited understanding, I could 
either use:

class_<mine, shared_ptr<mine>, ...>
or
class_<mine, mine_w, ...>

The second would let me inherit in Python, the first would let me return 
shared_ptr<mine> objects.

> 
>>    If I try to do shared_ptr<mine_w>, then I still cannot create a
>>    shared_ptr<mine>.
> 
> 
> What happens that indicates to you that "still cannot create a
> shared_ptr<mine>."
> 

If I used:
class_<mine, shared_ptr<mine_w>, ...>
then if I called a function with:

shared_ptr<mine> create() { return shared_ptr<mine>(new child); }
I would get "no to-python converter registered for type ...".


> *************
> 
> Did you try using 
> 
>   implicitly_convertible<shared_ptr<mine_w>, shared_ptr<mine> >()
> 
> ??
> 
> Did you try using 
> 
>   register_ptr_to_python<shared_ptr<mine> >()
> 
> ??
> 

Just to clarify, should I use both? I think if I use:
class_<mine, mine_w, bases<...>, boost::noncopyable> ...
register_ptr_to_python<shared_ptr<mine> >();

Then the above function "create" would work. But do I need the 
"implicitly_convertible" in the case where I have create a Python class, 
and then I want to pass that into a C++ function that wants a 
shared_ptr? Or do I need to define my base class as:
class_<mine, shared_ptr<mine_w>, ...
to make both cases work?

> 
[...]

>>
>>Which has stuff like "get_override" and "public wrapper<>". Is this a
>>better way to do the python wrapping. 
> 
> 
> Yes, if you have the latest Boost CVS state.  If not, you can't use
> it.
> 
> 
>>It's not in the tutorial
> 
> 
> It will be, in the upcoming release.
> 
> 
>>and the documentation in general seems pretty weak. 
> 
> 
> What's weak about it?
> 

The documentation seems decent if you already know what to look for. 
Like once you told me about "register_ptr_to_python" it has a good 
example, and it fits what I need.

But there isn't a very good overview. The tutorial is very good for 
starting out, but doesn't cover the more advanced topics. I suppose one 
possibility is to just read *all* of the documentation, but when I first 
started out, it got so technical in places that it stopped making sense. 
It seemed like it was more for people who were trying to understand the 
implementation, rather than how to use it.

> 
>>I also didn't
>>find it in the documentation.
>>http://www.boost.org/libs/python/doc/v2/reference.html
> 
> 
> That's because it's not released yet.
> 

Thank you for your time. I'm interested in what 1.32 is going to look 
like. In general I'm very happy with boost, and boost::python. A lot of 
times the documentation feels like reading commented source code, rather 
than a document describing how things should be used. I suppose that's 
what tutorials and possibly wikis are for.

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20041031/61df3b4e/attachment.pgp>


More information about the Cplusplus-sig mailing list