[C++-sig] Converting a python dictionary rvalue to a T* in boost.pyt

icsa investtcartier at yahoo.com
Mon Jul 31 16:31:56 CEST 2006


What is the preferred way to convert Python arguments(Esp. - dictionaries)
from Python to C++ instances (non-STL)? Assume that the C++ function can be
created with any necessary requirements. Could provide a complete example?

Thanks again.

David Abrahams wrote:
> 
> icsa writes:
> 
>> Hi all,
>>
>> I have a c++ class T that implements an extended
>> table. Additionally, I have a C++ function that takes
>> a T* as an argument void (E.g. - f(T* t) ). How do I
>> create converter to convert an 
>> arbitrary python dictionary in boost.python to a T* as
>> an argument?
> 
> There's no good way to do it.  Well, you could do this, if you want to
> do it a "bad" way:
> 
>    1. define an rvalue from_python converter that converts an arbitrary
>    dictionary to a T object.
> 
>    2. create a thin wrapper around f:
> 
>         void wrapf(T const& x) { f(&const_cast<T&>(x)); }
>         
>       and wrap that as f in PYthon.
> 
> 
> HTH,
> 
> -- 
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 
> 
-- 
View this message in context: http://www.nabble.com/-C%2B%2B-sig--Converting-a-python-dictionary-rvalue-to-a-T*-in-boost.python-tf2016635.html#a5576871
Sent from the Python - c++-sig forum at Nabble.com.




More information about the Cplusplus-sig mailing list