import source from 1.3.40
[external/swig.git] / Examples / test-suite / refcount.i
1 %module refcount
2
3 %warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,SWIGWARN_LANG_IDENTIFIER);
4
5 %{ 
6 #include <iostream> 
7 #include "refcount.h"
8 %}
9
10 //
11 // using the %refobject/%unrefobject directives you can active the
12 // ref. counting for RCObj and all its descendents at once
13 //
14
15 %refobject   RCObj "$this->addref();"
16 %unrefobject RCObj "$this->delref();"
17
18 %include "refcount.h"
19
20 %newobject B::create(A* a);
21 %newobject B::cloner();
22
23
24  
25 %inline %{
26
27   struct A : RCObj
28   {
29     A() {}
30     
31     ~A() 
32     {
33       // std::cout << "deleting a" << std::endl;
34     }
35
36 #ifdef SWIGRUBY 
37     // fix strange ruby + virtual derivation problem
38     using RCObjBase::ref_count;
39 #endif
40   };
41
42   struct A1 : A 
43   {
44   protected:
45     A1() {}
46   };
47
48   struct A2 : A
49   {
50   };
51
52   struct A3 : A1, private A2
53   {    
54   };
55
56 %}
57
58 #if defined(SWIGPYTHON)
59 %extend_smart_pointer(RCPtr<A>);
60 %template(RCPtr_A) RCPtr<A>;
61 #endif
62
63 %inline %{
64   
65   struct B : RCObj
66   {
67     B(A* a) : _a(a) {}
68     
69     A* get_a() 
70     {
71       return _a;
72     }
73     
74     static B* create(A* a)
75     {
76       return new B(a);
77     }
78     
79     B* cloner() 
80     {
81       return new B(_a);
82     }
83
84     ~B() 
85     {
86       // std::cout << "deleting b" << std::endl;
87     }
88
89     RCPtr<A> get_rca() {
90       return _a;      
91     }
92
93   private:
94     RCPtr<A> _a;
95   };
96
97 %}
98
99 #if defined(SWIGPYTHON) || defined(SWIGOCTAVE)
100
101 %include <std_vector.i>
102 %template(vector_A) std::vector<RCPtr<A> >;
103
104 #endif