summaryrefslogtreecommitdiff
path: root/Examples/test-suite/overload_simple.i
blob: fa2e335bb362e84ca016af9a0efd5fe74ac41f4a (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Simple tests of overloaded functions
%module overload_simple

#ifdef SWIGLUA
// lua only has one numeric type, so most of the overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) bar;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Spam;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) num;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fid;
#endif

#ifdef SWIGGO
%warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype'
%rename(Foos) Foo;
#endif

#ifdef SWIGOCAML
%warnfilter(SWIGWARN_PARSE_KEYWORD) type;
#endif

%immutable Spam::type;

%inline %{

struct Foo {
};

class Bar {
public:
  Bar(int i = 0) { num = i; }

  static int foo(int a=0, int b=0) {return 0;}

  int num;
};

char *foo() {
   return (char *) "foo:";
}
char *foo(int) {
   return (char*) "foo:int";
}

char *foo(double) {
   return (char*) "foo:double";
}

char *foo(char *) {
   return (char*) "foo:char *";
}

char *foo(Foo *) {
   return (char*) "foo:Foo *";
}
char *foo(Bar *) {
   return (char *) "foo:Bar *";
}
char *foo(void *) {
   return (char *) "foo:void *";
}
char *foo(Foo *, int) {
   return (char *) "foo:Foo *,int";
}
char *foo(double, Bar *) {
   return (char *) "foo:double,Bar *";
}

char *blah(double) {
   return (char *) "blah:double";
}

char *blah(char *) {
   return (char *) "blah:char *";
}

class Spam {
public:
    Spam() { type = "none"; }
    Spam(int) { type = "int"; }
    Spam(double) { type = "double"; }
    Spam(char *) { type = "char *"; }
    Spam(Foo *) { type = "Foo *"; }
    Spam(Bar *) { type = "Bar *"; }
    Spam(void *) { type = "void *"; }
    const char *type;

char *foo(int) {
   return (char*) "foo:int";
}
char *foo(double) {
   return (char*) "foo:double";
}
char *foo(char *) {
   return (char*) "foo:char *";
}
char *foo(Foo *) {
   return (char*) "foo:Foo *";
}
char *foo(Bar *) {
   return (char *) "foo:Bar *";
}
char *foo(void *) {
   return (char *) "foo:void *";
}

static char *bar(int) {
   return (char*) "bar:int";
}
static char *bar(double) {
   return (char*) "bar:double";
}
static char *bar(char *) {
   return (char*) "bar:char *";
}
static char *bar(Foo *) {
   return (char*) "bar:Foo *";
}
static char *bar(Bar *) {
   return (char *) "bar:Bar *";
}
static char *bar(void *) {
   return (char *) "bar:void *";
}
};


bool fbool(bool b) {
   return b;
}

int fbool(int b) {
   return b;
}

char *fint(int) {
   return (char*) "fint:int";
}

char *fdouble(double) {
   return (char*) "fdouble:double";
}

char *num(int) {
   return (char*) "num:int";
}
char *num(double) {
   return (char*) "num:double";
}

char *fid(int, int) {
   return (char*) "fid:intint";
}
char *fid(int, double) {
   return (char*) "fid:intdouble";
}

char *fid(double, int) {
   return (char*) "fid:doubleint";
}

char *fid(double, double) {
   return (char*) "fid:doubledouble";
}

%}

%inline %{
unsigned long long ull() { return 0ULL; }
unsigned long long ull(unsigned long long ull) { return ull; }
long long ll() { return 0LL; }
long long ll(long long ull) { return ull; }
%}

%include cmalloc.i
%malloc(void);
%free(void);


%inline {  
  class ClassA
  {
  public:
    ClassA() {}  
    int method1( ) {return 0;}
    int method1( int arg1 ) {return arg1;}
  protected:
    int method1( int arg1, int arg2 ) {return arg1 + arg2;}
    
  };
}

#ifdef SWIGPYTHON
%inline 
{
  class Graph {
  public:
    int val;
    Graph(int i) : val(i) {};
  };
}

%extend Graph {
  Graph(PyObject* p) { return new Graph(123);}
} 

#endif

%inline %{
  int int_object(Spam *s) { return 999; }
  int int_object(int c) { return c; }
%}