[C++-sig] Re: Conversion of C++ return type.

David Abrahams dave at boost-consulting.com
Fri Feb 27 01:34:32 CET 2004


Hanz Meizer <steam at nurfuerspam.de> writes:

> Hello,
>
> I've realized that one of the C++-classes of my project will be very
> hard to wrap. Basically, it's a generic container type that holds a
> pointer to some object (similar to auto_ptr<>). The class is called
> Any' because it can contain a pointer to anything (nice eh? :( ).

Err, like boost::any?

> What I want to do is avoid this class entirely from python, that
> means, I want to have the wrapped object returned directly without the
> Any class wrapper. Functions that take an Any as rgument should be
> callable as well, of course.
>
> My question: Is it possible to shado this Any class entirely, and if
> yes, has this been done or where can I get some hints as to how this
> could work? I've searched some and my guess is to_python_converter,
> but I currently don't see the way how to achive my goal.

Good guess.

Unfortunately I can't track down the details for you, but here's the
gist: you need to register a custom to_python_converter for Any.
Then, inside its conversion function, you need to get the typeid of
the type stored by the Any (if you can't get that you're out of luck),
and invoke the registry's lookup function to get the to-python
conversion chain for the stored type.  Then you need to "manually"
invoke that converter. Expect the resulting code to be fairly ugly
and low-level.  Sorry :(


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list