summaryrefslogtreecommitdiff
path: root/Examples/test-suite/proxycode.i
blob: 02dab9ade492264f1ce9f8b5afc5f14fa2260334 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
%module proxycode

%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Proxy4::Proxy4Nested;

#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)

%{
struct Proxy1 {};
%}
struct Proxy1 {
%proxycode %{
  public int proxycode1(int i) {
    return i+1;
  }
%}
};

%proxycode %{
  this should be ignored as it is not in scope of a class
%}

%extend Proxy2 {
%proxycode %{
  public int proxycode2a(int i) {
    return i+2;
  }
%}
}

%extend Proxy2 {
%proxycode %{
  public int proxycode2b(int i) {
    return i+2;
  }
%}
}

%inline %{
struct Proxy2 {};
struct Proxy3 {};
struct Proxy4 {
  struct Proxy4Nested {};
};
%}

%extend Proxy3 {
%proxycode %{
  public int proxycode3(int i) {
    return i+3;
  }
%}
}

%extend Proxy4 {
%proxycode %{
  public int proxycode4(int i) {
    return i+4;
  }
%}
}
%extend Proxy4::Proxy4Nested {
%proxycode %{
  public int proxycode4nested(int i) {
    return i+44;
  }
%}
}

%extend TemplateProxy {
%proxycode %{
  public T proxycode5(T i) {
    return i;
  }
%}
}

%extend TemplateProxy<int> {
%proxycode %{
  public int proxycode5(int i, int j) {
    return i+j+55;
  }
%}
}

%inline %{
template <typename T> struct TemplateProxy {};
%}

%template(Proxy5a) TemplateProxy<short>;
%template(Proxy5b) TemplateProxy<int>;

%inline %{
template <typename T> struct TypemapProxy {
  T useT(T t1, T const& t2) {
    return t1+t2;
  }
};
%}

%extend TypemapProxy {
#if defined(SWIGJAVA)
%proxycode %{
  public $javaclassname proxyUseT(long t1,  long t2) {
    $typemap(jstype, unsigned int) tt1 = t1;
    $typemap(jstype, unsigned int const&) tt2 = t2;
    long ret = useT(tt1, tt2);
    if (ret != t1+t2)
      throw new RuntimeException("wrong sum");
    return this;
  }
%}
#elif defined(SWIGCSHARP)
%proxycode %{
  public $csclassname proxyUseT(uint t1,  uint t2) {
    $typemap(cstype, unsigned int) tt1 = t1;
    $typemap(cstype, unsigned int const&) tt2 = t2;
    uint ret = useT(tt1, tt2);
    if (ret != t1+t2)
      throw new System.Exception("wrong sum");
    return this;
  }
%}
#elif defined(SWIGD)
%proxycode %{
  public $dclassname proxyUseT(uint t1,  uint t2) {
    $typemap(dtype, unsigned int) tt1 = t1;
    $typemap(dtype, unsigned int const&) tt2 = t2;
    uint ret = useT(tt1, tt2);
    if (ret != t1+t2)
      throw new Exception("wrong sum");
    return this;
  }
%}
#else
#error "missing test"
#endif
}

%template(Proxy6) TypemapProxy<unsigned int>;

#endif