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

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

#
Swig | 107 lines | 83 code | 24 blank | 0 comment | 0 complexity | 319eefb2e08fb1a9119d3bbc07e791fd MD5 | raw file
  1%module extend_placement
  2
  3// Tests placement of %extend directives
  4
  5// Before the class
  6
  7%extend Foo {
  8  Foo(int a) { return new Foo(); }
  9  ~Foo() { delete $self;}
 10  int spam(int x) { return x; }
 11  int spam(int x, int y) { return x + y ; }
 12  int spam(int x, int y,int z) { return x + y ; }
 13  int spam(Foo f, double d = 10.0) { return 0; }
 14};
 15
 16%inline %{
 17class Foo {
 18public:
 19  Foo(){}
 20
 21#ifdef SWIG
 22%extend { Foo(int a, int b) { return new Foo(); } }  
 23#endif
 24
 25  int spam() { return 1; }
 26  int spam(const char* c) { return 2; }
 27};
 28%}
 29
 30// After the class
 31
 32%inline %{
 33class Bar {
 34public:
 35  Bar() { }
 36  int spam() { return 1; }
 37  int spam(const char* c) { return 2; }
 38};
 39%}
 40
 41
 42%extend Bar {
 43  Bar(int a) { return new Bar(); }
 44  ~Bar() { delete $self;}
 45  int spam() { return 1}
 46  int spam(int x) { return x; }
 47  int spam(int x, int y) { return x + y ; }
 48  int spam(int x, int y,int z) { return x + y ; }
 49  int spam(Bar b, double d = 10.0) { return 0; }
 50};
 51
 52
 53// testing templates
 54
 55// Before the class
 56
 57%extend FooT {
 58  FooT(int a) { return new FooT<T>(); }
 59  ~FooT() { delete $self;}
 60  int spam(int x) { return x; }
 61  int spam(int x, int y) { return x + y ; }
 62  int spam(int x, int y,int z) { return x + y ; }
 63  int spam(Foo f, double d = 10.0) { return 0; }
 64};
 65
 66%inline %{
 67template<class T>
 68class FooT {
 69public:
 70  FooT(){}
 71
 72#ifdef SWIG
 73%extend { FooT(int a, int b) { return new FooT<T>(); } }  
 74#endif
 75
 76  int spam() { return 1; }
 77  int spam(const char* c) { return 2; }
 78};
 79%}
 80
 81%template(FooTi) FooT<int>;
 82
 83
 84// After the class
 85
 86%inline %{
 87template<class T>
 88class BarT {
 89public:
 90  BarT() { }
 91  int spam() { return 1; }
 92  int spam(const char* c) { return 2; }
 93};
 94%}
 95
 96
 97%extend BarT {
 98  BarT(int a) { return new BarT<T>(); }
 99  ~BarT() { delete $self;}
100  int spam() { return 1}
101  int spam(int x) { return x; }
102  int spam(int x, int y) { return x + y ; }
103  int spam(int x, int y,int z) { return x + y ; }
104  int spam(Bar b, double d = 10.0) { return 0; }
105};
106
107%template(BarTi) BarT<int>;