PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 144 lines | 102 code | 42 blank | 0 comment | 0 complexity | a199155be73b4e578c48c81fcd5df7a3 MD5 | raw file
  1 %module(directors="1") director_basic
  2 #pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR
  3
  4 %{
  5 #include <string>
  6
  7 class Foo {
  8 public:
  9   virtual ~Foo() {}
 10   virtual std::string ping() { return "Foo::ping()"; }
 11   virtual std::string pong() { return "Foo::pong();" + ping(); }
 12
 13   static Foo* get_self(Foo *slf) {return slf;}
 14   
 15 };
 16
 17 %}
 18
 19 %include <std_string.i>
 20
 21 %feature("director") Foo;
 22
 23
 24 class Foo {
 25 public:
 26   virtual ~Foo();
 27   virtual std::string ping();
 28   virtual std::string pong();
 29   
 30   static Foo* get_self(Foo *slf);
 31   
 32 };
 33
 34 %{
 35 #include <complex> 
 36 %}
 37 %feature("director") A;
 38
 39 // basic renaming
 40 %rename(rg) A::gg;
 41 %feature("nodirector") hi::A1::gg;
 42
 43 %inline %{
 44
 45 struct A{
 46     A(std::complex<int> i, double d=0.0) {}
 47     A(int i, bool j=false) {}
 48     virtual ~A() {}
 49
 50     virtual int f(int i=0) {return i;}
 51     virtual int gg(int i=0) {return i;}
 52 };
 53
 54 namespace hi  {
 55
 56   struct A1 : public A {
 57     A1(std::complex<int> i, double d=0.0) : A(i, d) {}
 58     A1(int i, bool j=false) : A(i, j) {}
 59
 60     virtual int ff(int i = 0) {return i;}  
 61   };
 62 }
 63
 64
 65 %}
 66
 67
 68 %feature("director") MyClass;
 69
 70 %inline %{
 71
 72 typedef void VoidType;
 73
 74  struct Bar
 75  {
 76    int x;
 77    Bar(int _x = 0) : x(_x)
 78    {
 79    }
 80 };
 81 
 82 
 83
 84class MyClass {
 85public:
 86  MyClass(int a = 0) 
 87  {
 88  }
 89  
 90  virtual void method(VoidType *)
 91  {
 92  }
 93  
 94  virtual ~MyClass()
 95  {
 96  }
 97
 98  virtual Bar vmethod(Bar b)
 99  {
100    b.x += 13;
101    return b;
102  }  
103
104  virtual Bar* pmethod(Bar *b)
105  {
106    b->x += 12;
107    return b;
108  }  
109
110  Bar cmethod(const Bar &b)
111  {
112    return vmethod(b);
113  }  
114
115  static MyClass *get_self(MyClass *c) 
116  {
117    return c;
118  }
119
120  static Bar * call_pmethod(MyClass *myclass, Bar *b) {
121    return myclass->pmethod(b);
122  }
123};
124
125template<class T>
126class MyClassT {
127public:
128  MyClassT(int a = 0) 
129  {
130  }
131  
132  virtual void method(VoidType *)
133  {
134  }
135  
136  virtual ~MyClassT()
137  {
138  }
139  
140};
141
142%}
143
144%template(MyClassT_i) MyClassT<int>;