%extend and default args tests
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6327 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8c081cbd4b
commit
2b742879a0
2 changed files with 332 additions and 0 deletions
107
Examples/test-suite/extend_default.i
Normal file
107
Examples/test-suite/extend_default.i
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
// Tests %extend with default arguments as well as %extend with default arguments with overloading
|
||||
|
||||
%module extend_default
|
||||
|
||||
// %extend before the class definition
|
||||
%extend Before {
|
||||
Before(int i = -1, double d = -1.0) {
|
||||
Before *self = new Before();
|
||||
self->i = i;
|
||||
self->d = d;
|
||||
return self;
|
||||
}
|
||||
static double AddedStaticMethod(int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(int i = -1, double d = -1.0) { return i+d; }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct Before {
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
%}
|
||||
|
||||
// %extend after the class definition
|
||||
%inline %{
|
||||
struct After {
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
%}
|
||||
|
||||
%extend After {
|
||||
After(int i = -1, double d = -1.0) {
|
||||
After *self = new After();
|
||||
self->i = i;
|
||||
self->d = d;
|
||||
return self;
|
||||
}
|
||||
static double AddedStaticMethod(int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(int i = -1, double d = -1.0) { return i+d; }
|
||||
}
|
||||
|
||||
|
||||
// %extend before the class definition - with overloading and default args
|
||||
%extend OverBefore {
|
||||
OverBefore(int i = -1, double d = -1.0) {
|
||||
OverBefore *self = new OverBefore("boo");
|
||||
self->i = i;
|
||||
self->d = d;
|
||||
return self;
|
||||
}
|
||||
static double AddedStaticMethod(int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(int i = -1, double d = -1.0) { return i+d; }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct OverBefore {
|
||||
OverBefore(const char *str, int i = -2, double d = -2.0) : d(d), i(i) { str=0; }
|
||||
static double AddedStaticMethod(const char*, int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(const char*, int i = -1, double d = -1.0) { return i+d; }
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
%}
|
||||
|
||||
// %extend after the class definition - with overloading and default args
|
||||
%extend OverAfter {
|
||||
OverAfter(int i = -1, double d = -1.0) {
|
||||
OverAfter *self = new OverAfter("boo");
|
||||
self->i = i;
|
||||
self->d = d;
|
||||
return self;
|
||||
}
|
||||
static double AddedStaticMethod(int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(int i = -1, double d = -1.0) { return i+d; }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct OverAfter {
|
||||
OverAfter(const char *str, int i = -2, double d = -2.0) : d(d), i(i) { str=0; }
|
||||
static double AddedStaticMethod(const char*, int i = -1, double d = -1) { return i+d; }
|
||||
double AddedMethod(const char*, int i = -1, double d = -1.0) { return i+d; }
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
#pragma SWIG nowarn=-302
|
||||
//%warnfilter(302) over; // why doesn't this work?
|
||||
|
||||
// %extend overrides the class definition
|
||||
%extend Override {
|
||||
int over(int a) { return a*a; } // SWIG should give a warning then choose this one over the real one
|
||||
int overload(int a) { return a*a; } // Similarly, but this one generated uncompileable code in SWIG-1.3.22
|
||||
}
|
||||
%inline %{
|
||||
struct Override {
|
||||
int over(int a = -1) { return a; }
|
||||
int ride(int a = -1) { return a; }
|
||||
int overload(int a) { return a; }
|
||||
int overload() { return -10; }
|
||||
};
|
||||
%}
|
||||
%extend Override {
|
||||
int ride(int a) { return a+a; } // SWIG should give a warning then ignore this one
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue