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

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

#
Swig | 74 lines | 64 code | 10 blank | 0 comment | 0 complexity | fb1e769945ad02171ace5071eca49fb5 MD5 | raw file
 1%module smart_pointer_const_overload
 2
 3%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->;      // Overloaded method Bar::operator ->() ignored
 4%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->;     // Overloaded method Bar2::operator ->() ignored
 5
 6%inline %{
 7int CONST_ACCESS = 1;
 8int MUTABLE_ACCESS = 2;
 9
10int *new_int(int ivalue) {
11  int *i = (int *) malloc(sizeof(ivalue));
12  *i = ivalue;
13  return i;
14}
15
16int get_int(int *i) {
17  return *i;
18}
19
20void set_int(int *i, int ivalue) {
21  *i = ivalue;
22}
23
24void delete_int(int *i) {
25  free(i);
26}
27
28struct Foo {
29   int x;
30   int * const xp;
31   const int y;
32   const int *yp;
33   int access;
34   Foo() : x(0), xp(&x), y(0), yp(&y), access(0) { }
35   int getx() const { return x; }
36   void setx(int x_) { x = x_; }
37   static void stat() {}
38};
39%}
40
41%extend Foo {
42   int getx2() const { return self->x; }
43   void setx2(int x_) { self->x = x_; }
44};
45
46%inline %{
47class Bar {
48   Foo *f;
49public:
50   Bar(Foo *f) : f(f) { }
51   const Foo *operator->() const {
52       f->access = CONST_ACCESS;
53       return f;
54   }
55   Foo *operator->() {
56       f->access = MUTABLE_ACCESS;
57       return f;
58   }
59};
60
61class Bar2 {
62   Foo *f;
63public:
64   Bar2(Foo *f) : f(f) { }
65   Foo *operator->() {
66       f->access = MUTABLE_ACCESS;
67       return f;
68   }
69   const Foo *operator->() const {
70       f->access = CONST_ACCESS;
71       return f;
72   }
73};
74%}