PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/inherit_target_language.i

#
Swig | 79 lines | 62 code | 17 blank | 0 comment | 0 complexity | 3bd732bf020d970a5398054a17a1540c MD5 | raw file
 1// Test using a target language specified base class, primarily for Java/C#/D and possibly other single inheritance languages
 2
 3// Note the multiple inheritance warnings don't appear because of the two techniques used in here: typemaps and %ignore
 4
 5%module inherit_target_language
 6
 7#if defined(SWIGJAVA)
 8# define csbase javabase
 9#elif defined(SWIGD)
10# define csbase dbase
11#endif
12
13%pragma(csharp) moduleimports=%{
14using System;
15using System.Runtime.InteropServices;
16public class TargetLanguageBase { public virtual void targetLanguageBaseMethod() {} };
17public class TargetLanguageBase2 { public virtual void targetLanguageBase2Method() {} };
18%}
19
20%pragma(java) moduleimports=%{
21class TargetLanguageBase { public void targetLanguageBaseMethod() {} };
22class TargetLanguageBase2 { public void targetLanguageBase2Method() {} };
23%}
24
25%pragma(d) globalproxyimports=%{
26private class TargetLanguageBase { public void targetLanguageBaseMethod() {} };
27private class TargetLanguageBase2 { public void targetLanguageBase2Method() {} };
28%}
29
30%typemap(csbase) SWIGTYPE "TargetLanguageBase"
31
32// Two ways to replace a C++ base with a completely different target language base
33%ignore Base1; // another way to use the target language base
34%typemap(csbase, replace="1") Derived2 "TargetLanguageBase"
35
36%inline %{
37struct Base1 { virtual ~Base1() {} };
38struct Base2 { virtual ~Base2() {} };
39struct Derived1 : Base1 {};
40struct Derived2 : Base2 {};
41%}
42
43// Multiple inheritance
44%ignore MBase1a;
45%ignore MBase1b;
46%typemap(csbase, replace="1") MultipleDerived2 "TargetLanguageBase"
47
48%inline %{
49struct MBase1a { virtual ~MBase1a() {} virtual void a() {} };
50struct MBase1b { virtual ~MBase1b() {} virtual void b() {} };
51struct MBase2a { virtual ~MBase2a() {} virtual void c() {} };
52struct MBase2b { virtual ~MBase2b() {} virtual void d() {} };
53struct MultipleDerived1 : MBase1a, MBase1b {};
54struct MultipleDerived2 : MBase1a, MBase2b {};
55%}
56
57
58%ignore MBase3a;
59%ignore MBase4b;
60%typemap(csbase) MultipleDerived3 ""
61%typemap(csbase) MultipleDerived4 ""
62
63%inline %{
64struct MBase3a { virtual ~MBase3a() {} virtual void e() {} };
65struct MBase3b { virtual ~MBase3b() {} virtual void f() {} };
66struct MBase4a { virtual ~MBase4a() {} virtual void g() {} };
67struct MBase4b { virtual ~MBase4b() {} virtual void h() {} };
68struct MultipleDerived3 : MBase3a, MBase3b {};
69struct MultipleDerived4 : MBase4a, MBase4b {};
70%}
71
72// Replace a C++ base, but only classes that do not have a C++ base
73%typemap(csbase, notderived="1") SWIGTYPE "TargetLanguageBase2"
74
75%inline %{
76struct BaseX            { virtual ~BaseX() {}; void basex() {} };
77struct DerivedX : BaseX { void derivedx() {} };
78%}
79