PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/kwargs_feature.i

#
Swig | 112 lines | 73 code | 38 blank | 1 comment | 0 complexity | 728c51150751e69bb2106930b5bb9731 MD5 | raw file
  1%module kwargs_feature
  2
  3%nocopyctor;
  4%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
 36    virtual ~Foo() {
 37    }
 38    
 39  };
 40
 41%}
 42
 43
 44// Templated class
 45%extend Bar 
 46{
 47  T ebar(T a = 1, T b = 0) {return a + b; }
 48  static T sbar(T a = 1, T b = 0) { return a + b; }
 49}
 50
 51%inline %{
 52  template <typename T> struct Bar 
 53  {
 54    Bar(T a, T b = 0){}
 55
 56    T bar(T a = 1, T b = 0) {return a + b; }
 57    static T statbar(T a = 1, T b = 0) {return a + b; }
 58  };
 59
 60%}
 61
 62%template(BarInt) Bar<int>;
 63
 64
 65// Functions
 66%inline %{
 67  int foo(int a = 1, int b = 0) {return a + b; }
 68
 69  
 70  template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
 71%}
 72
 73%template(templatedfunction) templatedfunction<int>;
 74
 75
 76// Deafult args with references
 77%inline
 78%{
 79
 80  typedef int size_type;
 81  
 82  struct Hello 
 83  {
 84    static const size_type hello = 3;
 85  };
 86  
 87  
 88  
 89  int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
 90  {
 91    return x;
 92  }
 93  
 94%}
 95%{
 96  const int Hello::hello;
 97%}
 98  
 99
100// Functions with keywords
101%warnfilter(SWIGWARN_PARSE_KEYWORD);
102%inline %{
103  /* silently rename the parameter names in python */
104
105  int foo_kw(int from = 1, int except = 2) {return from + except; }
106
107
108  int foo_nu(int from = 1, int = 0) {return from; }
109
110  int foo_mm(int min = 1, int max = 2) {return min + max; }
111
112%}