in reply to XS typemap and C++ multiple inheritance
One way to do this would be to have a base object class, and use dynamic_cast<>(). You can do this even if you're wrapping a set of classes that don't already have common base class. Say you have classes Foo and Bar, and a class Baz which is derived from Foo and Bar. You then derive classes
class Obj {...}; class MyFoo : public Foo, virtual public Obj {...}; class MyBar : public Bar, virtual public Obj {...}; class MyBaz : public Baz, virtual public Obj {...};
You have to wrap the constructors, but otherwise these objects act just like your original classes. Be sure to give Obj a virtual destructor.
Whenever you pass a blessed object to Perl, static_cast<>() it to Obj before casting to void.
void *ptr = (void*) static_cast<Obj*>(foo);
Reverse the cast when you get a method call
The blessing into the correct class should even work automatically, but check the XSUB code to be sure.Foo* foo = dynamic_cast<MyFoo*>((Obj*) ptr);
|
---|