Discussion:
mapping c++ abstract class to c# Interface
stefano ruberto
2008-05-08 14:33:04 UTC
Permalink
Hi there...

The problem "... Multiple inheritance is not supported in C#."


In order to translate multiple inheritance into c# I think would be
usefull to use the c# interface.

SWIG only take the first base class in my c++ code but anyway insert the
inherited method from all
the base class in the cs proxy class...

So I tought to add a c# interface for each abstract c++ base class.

//c++ side
class abstarctCppBase1{ void mth1Base1()=0 ; void mth2Base1(){} ... }

class abstarctCppBase2{ void mth1Base2()=0 ; void mth2Base1() {}...}

class CppInherited : abstarctCppBase1 , abstarctCppBase2
{ }

//c# side


interface Ibase2 { mth1Base2(); mth2Base1(); }

class csBase1{ ... }

class csInherited : csBase1, Ibase2 { void mth1Base1(){} void
mth2Base1(){} void mth1Base2(){} void mth2Base1() {} }

Is this the correct way ... ??
I'm so new to swig so that any help will be appreciated!

Thank you for your help
By
Rubio
Rubyo
2008-05-08 15:42:39 UTC
Permalink
Hi there...

The problem "... Multiple inheritance is not supported in C#."


In order to translate multiple inheritance into c# I think would be
usefull to use the c# interface.

SWIG only take the first base class in my c++ code but anyway insert the
inherited method from all
the base class in the cs proxy class...

So I tought to add a c# interface for each abstract c++ base class.

//c++ side
class abstarctCppBase1{ void mth1Base1()=0 ; void mth2Base1(){} ... }

class abstarctCppBase2{ void mth1Base2()=0 ; void mth2Base1() {}...}

class CppInherited : abstarctCppBase1 , abstarctCppBase2
{ }

//c# side


interface Ibase2 { mth1Base2(); mth2Base1(); }

class csBase1{ ... }

class csInherited : csBase1, Ibase2 { void mth1Base1(){} void
mth2Base1(){} void mth1Base2(){} void mth2Base1() {} }

Is this the correct way ... ??
I'm so new to swig so that any help will be appreciated!

Thank you for your help
By
Rubio





-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
zhiyang jiang
2008-05-11 04:25:17 UTC
Permalink
Message: 4
Date: Thu, 8 May 2008 16:33:04 +0200
Subject: [Swig-user] mapping c++ abstract class to c# Interface
Content-Type: text/plain; charset="iso-8859-1"
Hi there...
The problem "... Multiple inheritance is not supported in C#."
In order to translate multiple inheritance into c# I think would be
usefull to use the c# interface.
SWIG only take the first base class in my c++ code but anyway insert the
inherited method from all
the base class in the cs proxy class...
So I tought to add a c# interface for each abstract c++ base class.
//c++ side
class abstarctCppBase1{ void mth1Base1()=0 ; void mth2Base1(){} ... }
class abstarctCppBase2{ void mth1Base2()=0 ; void mth2Base1() {}...}
class CppInherited : abstarctCppBase1 , abstarctCppBase2
{ }
//c# side
interface Ibase2 { mth1Base2(); mth2Base1(); }
class csBase1{ ... }
class csInherited : csBase1, Ibase2 { void mth1Base1(){} void
mth2Base1(){} void mth1Base2(){} void mth2Base1() {} }
Is this the correct way ... ??
I'm so new to swig so that any help will be appreciated!
Thank you for your help
By
Rubio
it is good way to transform the abstract classes into interfaces in
c#,but the swig does not know which should be transformed, if you define the
interfaces manually , there may be some map problems between the proxy
classes and wrapper classes.
The multiple inheritance will be completely supported in future ,as you
said ,the abstract classs will be interfaces in c# or java, and a new
directives like %feature(interface) will be added into swig for showing what
are interfaces.
Hope it is useful to you!

Jiang
Rubyo
2008-05-12 09:03:34 UTC
Permalink
Post by zhiyang jiang
Message: 4
Date: Thu, 8 May 2008 16:33:04 +0200
Subject: [Swig-user] mapping c++ abstract class to c# Interface
Content-Type: text/plain; charset="iso-8859-1"
Hi there...
The problem "... Multiple inheritance is not supported in C#."
In order to translate multiple inheritance into c# I think would be
usefull to use the c# interface.
SWIG only take the first base class in my c++ code but anyway insert the
inherited method from all
the base class in the cs proxy class...
So I tought to add a c# interface for each abstract c++ base class.
//c++ side
class abstarctCppBase1{ void mth1Base1()=0 ; void mth2Base1(){}
... }
class abstarctCppBase2{ void mth1Base2()=0 ; void mth2Base1() {}...}
class CppInherited : abstarctCppBase1 , abstarctCppBase2
{ }
//c# side
interface Ibase2 { mth1Base2(); mth2Base1(); }
class csBase1{ ... }
class csInherited : csBase1, Ibase2 { void mth1Base1(){} void
mth2Base1(){} void mth1Base2(){} void mth2Base1() {} }
Is this the correct way ... ??
I'm so new to swig so that any help will be appreciated!
Thank you for your help
By
Rubio
it is good way to transform the abstract classes into interfaces in
c#,but the swig does not know which should be transformed, if you
define the interfaces manually , there may be some map problems
between the proxy classes and wrapper classes.
The multiple inheritance will be completely supported in future ,as
you said ,the abstract classs will be interfaces in c# or java, and a
new directives like %feature(interface) will be added into swig for
showing what are interfaces.
Hope it is useful to you!
Jiang
------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
https://lists.sourceforge.net/lists/listinfo/swig-user
Thank you for your replay ... before doing some more experimet.. I
would like to know how far is this (beautiful :-) ) future ...
can you give some good news?

Rubio


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Continue reading on narkive:
Loading...