1 %module kwargs_feature 2 3 %nocopyctor; 4 %feature("kwargs"); 5 6 %rename(myDel) del; 7 %inline 8 { 9 struct s { int del; }; 10 } 11 12 13 // Simple class 14 %extend Foo 15 { 16 int efoo(int a = 1, int b = 0) {return a + b; } 17 static int sfoo(int a = 1, int b = 0) { return a + b; } 18 } 19 20 %newobject Foo::create; 21 22 %inline %{ 23 24 struct Foo 25 { 26 Foo(int a, int b = 0) {} 27 28 virtual int foo(int a = 1, int b = 0) {return a + b; } 29 static int statfoo(int a = 1, int b = 0) {return a + b; } 30 31 static Foo *create(int a = 1, int b = 0) 32 { 33 return new Foo(a, b); 34 } 35 ~FooFoo36 virtual ~Foo() { 37 } 38 }; 39 %} 40 41 42 // Templated class 43 %extend Bar 44 { 45 T ebar(T a = 1, T b = 0) {return a + b; } 46 static T sbar(T a = 1, T b = 0) { return a + b; } 47 } 48 49 %inline %{ 50 template <typename T> struct Bar 51 { 52 Bar(T a, T b = 0){} 53 54 T bar(T a = 1, T b = 0) {return a + b; } 55 static T statbar(T a = 1, T b = 0) {return a + b; } 56 }; 57 58 %} 59 60 %template(BarInt) Bar<int>; 61 62 63 // Functions 64 %inline %{ 65 int foo_fn(int a = 1, int b = 0) {return a + b; } 66 67 template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; } 68 %} 69 70 %template(templatedfunction) templatedfunction<int>; 71 72 73 // Default args with references 74 %inline %{ 75 typedef int size_type; 76 77 struct Hello 78 { 79 static const size_type hello = 3; 80 }; 81 82 int rfoo( int n = 0, const size_type& x = Hello::hello, const Hello& y = Hello() ) 83 { 84 return n - x; 85 } 86 %} 87 %{ 88 const int Hello::hello; 89 %} 90 91 92 // Functions with keywords 93 %warnfilter(SWIGWARN_PARSE_KEYWORD); 94 %inline %{ 95 /* silently rename the parameter names in python */ 96 97 int foo_kw(int from = 1, int except = 2) {return from + except; } 98 99 int foo_nu(int from = 1, int = 0) {return from; } 100 101 int foo_mm(int min = 1, int max = 2) {return min + max; } 102 %} 103 104 105 // Extended constructors 106 %extend Extending0 { Extending0()107 Extending0() { return new Extending0(); } 108 } 109 %extend Extending1 { Extending1(int one)110 Extending1(int one) { return new Extending1(); } 111 } 112 %extend Extending2 { Extending2(int one,const char * two)113 Extending2(int one, const char *two) { return new Extending2(); } 114 } 115 %extend ExtendingOptArgs1 { 116 ExtendingOptArgs1(int one = 0) { return new ExtendingOptArgs1(); } 117 } 118 %extend ExtendingOptArgs2 { 119 ExtendingOptArgs2(int one = 0, const char* two = NULL) { return new ExtendingOptArgs2(); } 120 } 121 122 %inline %{ 123 struct Extending0 {}; 124 struct Extending1 {}; 125 struct Extending2 {}; 126 struct ExtendingOptArgs1 {}; 127 struct ExtendingOptArgs2 {}; 128 %} 129