Conversion from Python to C++

View: New views
5 Messages — Rating Filter:   Alert me  

Conversion from Python to C++

by Michele De Stefano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello to everybody.

I was wondering if there is a general way to convert a C++ class
wrapped in Python into a C++ class not wrapped in Python.
I've not fully understood the documentation on this point.

For example, assume we have two C++ classes, A and B. A is exported to
Python with class_<>, while B is not exported to Python.
Assume also that, in C++, A is convertible to B (i.e. I can construct
a B object from an existing A object).

Assume I have a C++ function (f) which takes a B object as input and I
want to expose this function, but I don't want to expose the B class.

Is there a general way to create a converter from A to B in order to
be able to call f(A) from Python ?

Thank you in advance.

--
Michele De Stefano
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Conversion from Python to C++

by Stefan Seefeld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/02/2009 10:06 AM, Michele De Stefano wrote:

> For example, assume we have two C++ classes, A and B. A is exported to
> Python with class_<>, while B is not exported to Python.
> Assume also that, in C++, A is convertible to B (i.e. I can construct
> a B object from an existing A object).
>
> Assume I have a C++ function (f) which takes a B object as input and I
> want to expose this function, but I don't want to expose the B class.
>
> Is there a general way to create a converter from A to B in order to
> be able to call f(A) from Python ?
>    

Depending on how many such functions you have, you may either simply
write a wrapper function with the right signature (i.e. accepting an 'A'
and (implicitly) converting that to a 'B' when calling the actual
function), or you may write a custom from_python converter.

Regards,
         Stefan

--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Conversion from Python to C++

by Michele De Stefano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok.

I'd like to write a custom from_python converter, but the point is
that I've not understood how it works.

The explanation in the FAQs it's too obscure for me.

2009/10/2 Stefan Seefeld <seefeld@...>:

> On 10/02/2009 10:06 AM, Michele De Stefano wrote:
>>
>> For example, assume we have two C++ classes, A and B. A is exported to
>> Python with class_<>, while B is not exported to Python.
>> Assume also that, in C++, A is convertible to B (i.e. I can construct
>> a B object from an existing A object).
>>
>> Assume I have a C++ function (f) which takes a B object as input and I
>> want to expose this function, but I don't want to expose the B class.
>>
>> Is there a general way to create a converter from A to B in order to
>> be able to call f(A) from Python ?
>>
>
> Depending on how many such functions you have, you may either simply write a
> wrapper function with the right signature (i.e. accepting an 'A' and
> (implicitly) converting that to a 'B' when calling the actual function), or
> you may write a custom from_python converter.
>
> Regards,
>        Stefan
>
> --
>
>      ...ich hab' noch einen Koffer in Berlin...
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@...
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



--
Michele De Stefano
http://www.linkedin.com/in/micdestefano
http://xoomer.virgilio.it/michele_de_stefano
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Conversion from Python to C++

by Nat Goodspeed-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michele De Stefano wrote:

> I'd like to write a custom from_python converter, but the point is
> that I've not understood how it works.

Did you see Austin Bingham's recent post on another thread?

> If it's any help, I wrote a small bit on the details of writing
> converters. It might help clarify some of the mechanics which, I
> agree, are a bit mysterious:
>
>   http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Conversion from Python to C++

by Michele De Stefano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Honestly, no.

Thank you for pointing me to that. I will look at it and if I have
problems again, I will post again.

Thank you very much.

2009/10/2 Nat Goodspeed <nat@...>:

> Michele De Stefano wrote:
>
>> I'd like to write a custom from_python converter, but the point is
>> that I've not understood how it works.
>
> Did you see Austin Bingham's recent post on another thread?
>
>> If it's any help, I wrote a small bit on the details of writing
>> converters. It might help clarify some of the mechanics which, I
>> agree, are a bit mysterious:
>>
>>
>>  http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@...
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



--
Michele De Stefano
http://www.linkedin.com/in/micdestefano
http://xoomer.virgilio.it/michele_de_stefano
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig