import source from 1.3.40
[external/swig.git] / Examples / test-suite / extend_placement.i
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 %{
17 class Foo {
18 public:
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 %{
33 class Bar {
34 public:
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 %{
67 template<class T>
68 class FooT {
69 public:
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 %{
87 template<class T>
88 class BarT {
89 public:
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>;