File: extend_default.i

package info (click to toggle)
swig1.3 1.3.24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,336 kB
  • ctags: 10,604
  • sloc: cpp: 27,917; ansic: 24,160; yacc: 4,412; python: 4,255; java: 4,156; makefile: 3,735; sh: 3,552; cs: 2,250; ruby: 2,150; lisp: 1,605; tcl: 1,136; perl: 980; php: 879; ml: 825
file content (108 lines) | stat: -rw-r--r-- 2,973 bytes parent folder | download
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
// Tests %extend with default arguments as well as %extend with default arguments with overloading

%module extend_default

%warnfilter(302) Override::over; 
%warnfilter(302) Override::overload; 
%warnfilter(302) 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 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
}