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
|
// Tests %extend with default arguments as well as %extend with default arguments with overloading
%module extend_default
%warnfilter(SWIGWARN_PARSE_REDEFINED) Override::over;
%warnfilter(SWIGWARN_PARSE_REDEFINED) Override::overload;
%warnfilter(SWIGWARN_PARSE_REDEFINED) Override::ride;
// %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 ii = -2, double dd = -2.0) : d(dd), i(ii) { str=0; }
static double AddedStaticMethod(const char*, int ii = -1, double dd = -1) { return ii+dd; }
double AddedMethod(const char*, int ii = -1, double dd = -1.0) { return ii+dd; }
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 ii = -2, double dd = -2.0) : d(dd), i(ii) { str=0; }
static double AddedStaticMethod(const char*, int ii = -1, double dd = -1) { return ii+dd; }
double AddedMethod(const char*, int ii = -1, double dd = -1.0) { return ii+dd; }
double d;
int i;
};
%}
// %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 uncompilable 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
}
// %extend in class hierarchy
%extend Base {
virtual int * virtualmethod(int a = 0) { return 0; }
int * nonvirtual(int a = 0) { return 0; }
static int * static_method(int a = 0) { return 0; }
}
%extend Derived {
int * virtualmethod(int a = 0) { return 0; }
int * nonvirtual(int a = 0) { return 0; }
static int * static_method(int a = 0) { return 0; }
int * realvirtual(int a = 0) { return 0; }
}
%inline %{
struct Base {
virtual ~Base() {}
virtual int * realvirtual(int a = 0) { return 0; }
};
struct Derived : Base {
};
%}
|