summaryrefslogtreecommitdiff
path: root/Examples/test-suite/li_boost_shared_ptr_director.i
blob: b2d9fc131d4368726486a202583394af2c985a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%module(directors="1") "li_boost_shared_ptr_director"

%{
#include <boost/shared_ptr.hpp>
%}

#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)

%include <boost_shared_ptr.i>
%shared_ptr(C);
%feature("director") Base;

%inline %{
struct C {
  C() : m(1) {}
  C(int n) : m(n) {}
  int get_m() { return m; }
private:
  int m;
};

struct Base {
  Base() {}
  virtual boost::shared_ptr<C> ret_c_shared_ptr() = 0;
  virtual C ret_c_by_value() = 0;
  virtual int take_c_by_value(C c) = 0;
  virtual int take_c_by_ref(C& c) = 0;
  virtual int take_c_by_pointer(C* c) = 0;
  virtual int take_c_by_pointer_ref(C*const& c) = 0;
  virtual int take_c_shared_ptr_by_value(boost::shared_ptr<C> c) = 0;
  virtual int take_c_shared_ptr_by_ref(boost::shared_ptr<C>& c) = 0;
  virtual int take_c_shared_ptr_by_pointer(boost::shared_ptr<C>* c) = 0;
  virtual int take_c_shared_ptr_by_pointer_ref(boost::shared_ptr<C>*const&c) = 0;
  virtual int take_many_args(
    C v1, C v2,
    C &r1, C &r2,
    C *p1, C *p2,
    C *const& cr1, C *const& cr2,
    boost::shared_ptr<C> sv1, boost::shared_ptr<C> sv2,
    boost::shared_ptr<C> &sr1, boost::shared_ptr<C> &sr2,
    boost::shared_ptr<C> *sp1, boost::shared_ptr<C> *sp2,
    boost::shared_ptr<C> *const& spr1, boost::shared_ptr<C> *const& spr2
  ) = 0;
  virtual ~Base() {}
};

int call_ret_c_shared_ptr(Base* b) {
  boost::shared_ptr<C> ptr = b->ret_c_shared_ptr();
  if (ptr) {
    return ptr->get_m();
  } else {
    return -1;
  }
}

int call_ret_c_by_value(Base* b) {
  C c = b->ret_c_by_value();
  return c.get_m();
}

int call_take_c_by_value(Base* b) {
  C c(5);
  return b->take_c_by_value(c);
}

int call_take_c_by_ref(Base* b) {
  C c(6);
  return b->take_c_by_ref(c);
}

int call_take_c_by_pointer(Base* b) {
  C c(7);
  return b->take_c_by_pointer(&c);
}

int call_take_c_by_pointer_ref(Base* b) {
  C c(8);
  C* p(&c);
  return b->take_c_by_pointer_ref(p);
}

int call_take_c_by_pointer_with_null(Base* b) {
  C* p = NULL;
  return b->take_c_by_pointer(p);
}

int call_take_c_by_pointer_ref_with_null(Base* b) {
  C* p = NULL;
  return b->take_c_by_pointer_ref(p);
}

int call_take_c_shared_ptr_by_value(Base* b) {
  boost::shared_ptr<C> ptr(new C(9));
  return b->take_c_shared_ptr_by_value(ptr);
}

int call_take_c_shared_ptr_by_value_with_null(Base* b) {
  boost::shared_ptr<C> ptr;
  return b->take_c_shared_ptr_by_value(ptr);
}

int call_take_c_shared_ptr_by_ref(Base* b) {
  boost::shared_ptr<C> ptr(new C(10));
  return b->take_c_shared_ptr_by_ref(ptr);
}

int call_take_c_shared_ptr_by_ref_with_null(Base* b) {
  boost::shared_ptr<C> ptr;
  return b->take_c_shared_ptr_by_ref(ptr);
}

int call_take_c_shared_ptr_by_pointer(Base* b) {
  boost::shared_ptr<C> ptr(new C(11));
  return b->take_c_shared_ptr_by_pointer(&ptr);
}

int call_take_c_shared_ptr_by_pointer_with_null(Base* b) {
  boost::shared_ptr<C> ptr;
  return b->take_c_shared_ptr_by_pointer(&ptr);
}

int call_take_c_shared_ptr_by_pointer_ref(Base* b) {
  boost::shared_ptr<C> *ptr = new boost::shared_ptr<C>(new C(12));
  return b->take_c_shared_ptr_by_pointer_ref(ptr);
}

int call_take_c_shared_ptr_by_pointer_ref_with_null(Base* b) {
  boost::shared_ptr<C> *ptr = new boost::shared_ptr<C>();
  return b->take_c_shared_ptr_by_pointer_ref(ptr);
}

%}

#endif