[C++-sig] Extract
Stefan Seefeld
seefeld at sympatico.ca
Wed May 30 20:39:07 CEST 2007
Sean Ross-Ross wrote:
> And yes I could create a method to use only a limited number of types
> but I would like to pass a python object in as "value" and have boost
> try and extract a c++ object to pass to set.
Python isn't statically typed, but it is strongly typed. Thus, you
have to write a (possibly big) series of if/else statements (or conceptually equivalent)
that lets you dispatch to the appropriate set<whatever>() method. There is
no way to automatize that and let boost handle it.
void my_set(ParameterList &list, std::string const &name, object value)
{
if (is<foo>(value)) list.set(name, extract<foo>(value));
else if (is<bar>(value)) list.set(name, extract<bar>(value));
else if (is<baz>(value)) list.set(name, extract<baz>(value));
etc., you get the idea. (it is up to you to implement the is<T>(object) function...)
Regards,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig
mailing list