I suppose that's true for Java, but in C# you could use the same name in all the interfaces, I think, thanks to explicit interface implementation:

interface IA { IntPtr getCPtr(); }
interface IB : IA { IntPtr getCPtr(); }
interface IC { IntPtr getCPtr(); }
class Foo : IA, IB, IC {
   ...
   IntPtr IA.getCPtr() { return ???; }
   IntPtr IB.getCPtr() { return ???; }
  IntPtr IC.getCPtr() { return ???; }
}


Foo foo = ...;
IntPtr aPtr = ((IA)foo).getCPtr();

Explicit interface implementations have the advantage that they are less visible (interface methods are always public, technically, but they are invisible on an object of type "Foo" until you cast to IA or IB or IC.)

Note that since these methods are public, there is greater reason to make it possible to rename them (it is very annoying that opaque pointers are hardcoded with the name SWIGTYPE_p_Xyz, so I %ignore everything that would cause an opaque pointer to be produced, or map opaque pointers to IntPtr instead, through typemaps.)



From:        Vladimir Kalinin <vkalinin@opendesign.com>
To:        David Piepgrass <David.Piepgrass@trapezegroup.com>
Cc:        <swig-devel@lists.sourceforge.net>
Date:        03/22/2013 01:25 PM
Subject:        Re: [Swig-devel] Abstract base classes to interfaces conversion




Thinking some more about the subject, it turns out that the only reliable way to obtain valid C pointer from the interface is to extend the interface with the corresponding function (like "internal IntPtr getCPtr();" ).
It cannot be called just getCPtr(), because if some class implements several interfaces, it has to implement several "getCPtr" functions. Interface name may be appended|prepended to the function name to distinguish them.
Implementation of these functions is the same as that of SwigUPCAST()

-----Original Message-----
I have one suggestion about interface support, if you implement this feature: it should be possible to wrap a class with BOTH a normal wrapper AND an interface. That is, don't limit interfaces to abstract base classes--also allow non-abstract base classes. For example, given a class hierarchy like:

struct A { int a; void fa(); }
struct B { int b; void fb(); }
struct C : A, B { int c; void fc(); }

It should be possible to create an interface "IB" in C#:

public interface IB {
 int b { get; set; }
 void fb();
}

But also a concrete class "B" that implements IB:

public class B : IB {
 public B(...) {...}
 public int b { get { ... } set { ... } }
 public void fb() { ... }
 ...
}

And then the wrapper for C would be:

public class C : A, IB {
 public C(...) {...}
 public int b { get { ... } set { ... } }
 public void fb() { ... }
 public int c { get { ... } set { ... } }
 public void fc() { ... }
 ...
}

This way, it is possible to create a standalone B that is not a C. Of course, if B is an abstract base class then an interface alone should suffice, i.e. only an interface IB is needed, not a class B.

It would also be nice if there were some way to request SWIG to create a property that returns a wrapper for B, e.g. in C#, C could have an operator for this:

 // C can convert to B implicitly
 public static implicit operator B(C c) { ??? }

But this feature is optional, since the user could add the necessary code manually, or (I assume) with help from a macro.




From:        
Vladimir Kalinin <vkalinin@opendesign.com>
To:        
<swig-devel@lists.sourceforge.net>
Date:        
03/19/2013 04:55 PM
Subject:        
[Swig-devel] Abstract base classes to interfaces conversion





As far as I know, currently there is no easy way to convert C++ abstract base
classes to Java/C# interfaces. (short of redeclaring the classes and
doing some more work)

I found the only reference to the attempt to implement that feature
here:
http://thread.gmane.org/gmane.comp.programming.swig.devel/18403
Is there any information about the status of that work?
(As I understand, the patch posted in that thread is far from
perfection)

Maybe there is some alternative solution being worked at in some SWIG branch?

If no one is planning to implement that feature in near future, I
will do it (in some way at least).
(Because, converting abstract base classes to interfaces is
currently the most time consuming feature in our
project wrappers (after nested classes were implemented)).

I think "feature:interface" syntax proposed by Zhiyang Jiang is ok.

Any suggestions, advices?


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:

http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Swig-devel mailing list
Swig-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/swig-devel

В этом сообщении вирусы не обнаружены.
Проверено AVG -
www.avg.com
Версия: 2012.0.2240 / Вирусная база данных: 2641/5694 - Дата выпуска: 21.03.2013
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar_______________________________________________
Swig-devel mailing list
Swig-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-devel