1
// Lots of tests for methods with default parameters / default arguments
5
%include "std_string.i"
10
// Anonymous arguments
11
int anonymous(int = 7771);
12
int anonymous(int x) { return x; }
14
// Bug [548272] Default arguments
15
bool booltest(bool x = true) { return x; }
18
enum flavor { BITTER, SWEET };
21
enum speed { FAST, SLOW };
22
// Note: default values should be EnumClass::FAST and SWEET
23
bool blah(speed s = FAST, flavor f = SWEET) { return (s == FAST && f == SWEET); };
27
const char * casts1(const char *m = (const char *) NULL) {
30
ret = new char[strlen(m+1)];
35
const char * casts2(const char *m = (const char *) "Hello") {
38
ret = new char[strlen(m+1)];
45
char chartest1(char c = 'x') { return c; }
46
char chartest2(char c = '\0') { return c; }
50
enum AType { NoType };
52
void dummy(AType::AType aType = AType::NoType) {}
57
int function(int i = B::CONST_NUM) { return i; }
61
int reftest1(const int &x = 42) { return x; }
62
std::string reftest2(const std::string &x = "hello") { return x; }
67
enum types {Oak, Fir, Cedar};
68
void chops(enum types type) {}
69
void test(int x = Oak + Fir + Cedar) {}
71
enum Tree::types chops(enum Tree::types type) { return type; }
75
// Rename a class member
76
%rename(bar2) Foo::bar;
77
%rename(newname) Foo::oldname(int x = 1234);
78
%ignore Foo::Foo(int x, int y = 0, int z = 0);
79
%ignore Foo::meth(int x, int y = 0, int z = 0);
80
%rename(renamed3arg) Foo::renameme(int x, double d) const;
81
%rename(renamed2arg) Foo::renameme(int x) const;
82
%rename(renamed1arg) Foo::renameme() const;
94
Foo(int x, int y = 0, int z = 0){}
96
void meth(int x, int y = 0, int z = 0){}
98
// Use a renamed member as a default argument. SWIG has to resolve
99
// bar to Foo::bar and not Foo::spam. SWIG-1.3.11 got this wrong.
100
// (Different default parameter wrapping in SWIG-1.3.23 ensures SWIG doesn't have to resolve these symbols).
101
void method1(int x = bar) {}
103
// Use unrenamed member as default
104
void method2(int x = spam) {}
106
// test the method itself being renamed
107
void oldname(int x = 1234) {}
108
void renameme(int x = 1234, double d=123.4) const {}
115
// tests valuewrapper
117
enum MyType { Val1, Val2 };
122
MyClass1(MyType myType) {}
128
void set(MyClass1 cl1 = Val1) {}
129
// This could have been written : set(MyClass1 cl1 = MyClass1(Val1))
130
// But it works in C++ since there is a "conversion" constructor in MyClass1.
135
// Default parameters with exception specifications
137
void exceptionspec(int a = -1) throw (int, const char*) {
144
Except(bool throwException, int a = -1) throw (int) {
148
void exspec(int a = 0) throw (int, const char*) {
154
// Default parameters in static class methods
156
namespace SpaceName {
158
static int staticmethod(int a=10, int b=20, int c=30) { return a+b+c; }
164
// Tests which could never be wrapped prior to changes in default argument wrapping implemented in SWIG-1.3.23:
167
static int getDefault() { return 500; }
168
enum { privatevalue = 200 };
169
static const char charvalue;
171
int privatedefault(int val = privatevalue) { return val; }
172
int protectedint(int val = intvalue) { return val; }
173
double protecteddouble(double val = doublevalue) { return val; }
174
int functiondefault(int val = Tricky::getDefault()) { return val; }
175
char contrived(const char *c = &charvalue) { return *c; }
177
static const int intvalue = 2000;
178
static const double doublevalue;
180
const char Tricky::charvalue = 'X';
181
const double Tricky::doublevalue = 987.654;
184
// tests default argument which is a constructor call within namespace
185
// also tests default constructor (from defaulted parameter)
189
Klass(int val = -1) : val(val) {}
191
Klass constructorcall(const Klass& k = Klass()) { return k; }
197
struct ConstMethods {
198
int coo(double d = 0.0) { return 10; }
199
int coo(double d = 0.0) const { return 20; }
204
// runtime test needed to check that the const method is called
205
struct ConstMethods {
206
int coo(double d = 0.0) const;
211
// Default args with C linkage
214
extern "C" double cfunc1(double x,double p = 1) {
219
double cfunc2(double x,double p = 2) {
223
double cfunc3(double x,double p = 3) {
227
typedef struct Pointf {