[C++-sig] void* cast to a specific type based on string name

Roman Yakovenko roman.yakovenko at gmail.com
Fri Oct 3 20:32:30 CEST 2008


On Fri, Oct 3, 2008 at 4:29 PM, Renato Araujo <renatox at gmail.com> wrote:
> Hi all,
>
> This question is about a problem I have in my implementation during
> the use of : boost::python::object(),
> my code is like this (this is a simple example how I receive the args
> from the C++ library):
>
>
> void call_Pyfunction(char **types /* contains the types names*/, void
> **args /* contains the pointers to values */ )
> {
>       /* type contains values like that: type ={"int", "double",
> "char*", "MyObject", ...}
>       /* args contains values like that: args = {10, 5.5,  "my string", ...}
>       /* here I need convert the args to PyObjects */
>
>       /* I'm using boost::python::object() but I need cast the value
> to specific type based on types names */
>       // the main question here is how to convert char* to a c++ type
>
>       // I can use a switch to native types but i would like to know
> if there is a best way to solve this
> }

Why don't you pass boost::python::object directly?
Later you can use
http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/extract.html#extract-spec
class and check what type the object contains?

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list