S
Steve Knight
Hello,
I'm new to Boost & Python and I'm diving straight in by trying to
write an extension module to a third party library. Foolishness
probably, but I don't have much choice!
My question is how can I write a C++ method that will either return a
boost wrapped C++ class or a Python object type depending on some
internal value?
So I want to do something like:
PyObject* Variant::getValue() {
switch (type) {
case INT:
return Py_BuildValue("i", union.int);
break;
case SOMECLASS:
??????
}
}
But I can't work out how to get my switch to construct and return my
boost C++ wrapped object in this scheme. I'm getting round it by:
SomeClass Variant::getSomeClass() {
SomeClass s(*reinterpret_cast<SomeClass*>(union.p_void));
return s;
}
But it seems a bit nasty. Any ideas?
I'm new to Boost & Python and I'm diving straight in by trying to
write an extension module to a third party library. Foolishness
probably, but I don't have much choice!
My question is how can I write a C++ method that will either return a
boost wrapped C++ class or a Python object type depending on some
internal value?
So I want to do something like:
PyObject* Variant::getValue() {
switch (type) {
case INT:
return Py_BuildValue("i", union.int);
break;
case SOMECLASS:
??????
}
}
But I can't work out how to get my switch to construct and return my
boost C++ wrapped object in this scheme. I'm getting round it by:
SomeClass Variant::getSomeClass() {
SomeClass s(*reinterpret_cast<SomeClass*>(union.p_void));
return s;
}
But it seems a bit nasty. Any ideas?