in reply to Re: XS typemap and C++ multiple inheritance
in thread XS typemap and C++ multiple inheritance

Thank you John,
Your analysys is the same than mine. But my problem is how to put into the void* my true type.

I really don't see how. Except if the void* that I put in my T_X_PTR would be a little encapsualted C Struct like:
enum MyType {D1_TYPE, B1_TYPE, B2_TYPE, D2_TYPE};
struct XS_TypeInfo
{
void* info;
enum MyType trueType;
};

But even with that means that I would have to rewrite my typemap. and to hard-code in it the decoding of the void* info depending on trueType.

TIA,
~Xavier

  • Comment on Re: Re: XS typemap and C++ multiple inheritance

Replies are listed 'Best First'.
Re: Re: Re: XS typemap and C++ multiple inheritance
by John M. Dlugosz (Monsignor) on Aug 06, 2001 at 18:02 UTC
    If they are not all related into a single concrete derived class, then yes that's the way to do it. Your question showed an example of multiple inheritance, though, so the fix there is to always be consistant as to what you cast it to before sticking it in the void*.

    —John

      Hi John, My problem with this kind of solution is that all the type and inheritance hierarchy are hard-coded in the typemap.
      So if you add a new derived class or if you modify the inheritance (remove a base class) I will have to modify the typemap. If I miss one modification or do a wrong modif I would end up with really bad stuff.

      Don't you a automatic way of doing it or maybe a more extensible way than the enum Type ?

      TIA again,

      ~Xavier

        So define one base class whose only purpose is to serve as the hook to XS. Everything is dynamic_cast to that before storing in a void*, every void* is static_cast to that to restore it to the type system.

        Since it has no members but lives only for this purpose, it would be an error to remove it. Adding to the type hiarachy is not an issue. Any new code must still conform to this protocol.

        —John