[C++-sig] how to extract an instance of arbitrary c++ class from python object?
Alexey Akimov
alexey.akimov85 at gmail.com
Sun Jul 5 01:50:34 CEST 2009
Hi,
Here is a question.(see Subject title) I am particularly interested in such
implementation using python.boost library.
For simple cases I've seen examples, such as:
int x = extract<int>(obj.attr("Attribute_name"))
However, when a type T in extract<T>() becomes user-specified things become
harder. For example,
suppose I have a type Vector wich is something like:
class Vector{
public:
double x,y,z;
};
and want to extract information from python object obj to c++ obect of class
Vector IN ONE OPERATION.
I've found that there are some converters for some standard types, but I'm
not able to manage how to do this
for my class. What should I do in order to make the extract<> function to
understand how it should convert a python
object (represented as boost::python::object - something like this) into
Vector object?
Again, variant like:
Vector r;
r.x = extract<double>(obj.attr("x"))
... and so on
are not interested. I need to make it in one operation.
Thanks
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090704/090e877f/attachment.htm>
More information about the Cplusplus-sig
mailing list