[ruby] add %typemap(directorin) for shared_ptr.
This commit is contained in:
parent
0f94b936e8
commit
0020fc97b0
3 changed files with 93 additions and 6 deletions
|
|
@ -23,6 +23,8 @@ struct Base {
|
|||
virtual int take_c_by_value(C c) = 0;
|
||||
virtual int take_c_shared_ptr_by_value(std::shared_ptr<C> c) = 0;
|
||||
virtual int take_c_shared_ptr_by_ref(std::shared_ptr<C>& c) = 0;
|
||||
virtual int take_c_shared_ptr_by_pointer(std::shared_ptr<C>* c) = 0;
|
||||
virtual int take_c_shared_ptr_by_pointer_ref(std::shared_ptr<C>*const&c) = 0;
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
|
|
@ -50,9 +52,39 @@ int call_take_c_shared_ptr_by_value(Base* b) {
|
|||
return b->take_c_shared_ptr_by_value(ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_value_with_null(Base* b) {
|
||||
std::shared_ptr<C> ptr;
|
||||
return b->take_c_shared_ptr_by_value(ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_ref(Base* b) {
|
||||
std::shared_ptr<C> ptr(new C(7));
|
||||
return b->take_c_shared_ptr_by_ref(ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_ref_with_null(Base* b) {
|
||||
std::shared_ptr<C> ptr;
|
||||
return b->take_c_shared_ptr_by_ref(ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_pointer(Base* b) {
|
||||
std::shared_ptr<C> ptr(new C(8));
|
||||
return b->take_c_shared_ptr_by_pointer(&ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_pointer_with_null(Base* b) {
|
||||
std::shared_ptr<C> ptr;
|
||||
return b->take_c_shared_ptr_by_pointer(&ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_pointer_ref(Base* b) {
|
||||
auto ptr = new std::shared_ptr<C>(new C(9));
|
||||
return b->take_c_shared_ptr_by_pointer_ref(ptr);
|
||||
}
|
||||
|
||||
int call_take_c_shared_ptr_by_pointer_ref_with_null(Base* b) {
|
||||
auto ptr = new std::shared_ptr<C>();
|
||||
return b->take_c_shared_ptr_by_pointer_ref(ptr);
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,35 @@ class Derived < Base
|
|||
end
|
||||
|
||||
def take_c_shared_ptr_by_value(c)
|
||||
c.get_m
|
||||
if c
|
||||
c.get_m
|
||||
else
|
||||
-2
|
||||
end
|
||||
end
|
||||
|
||||
def take_c_shared_ptr_by_ref(c)
|
||||
c.get_m
|
||||
if c
|
||||
c.get_m
|
||||
else
|
||||
-3
|
||||
end
|
||||
end
|
||||
|
||||
def take_c_shared_ptr_by_pointer(c)
|
||||
if c
|
||||
c.get_m
|
||||
else
|
||||
-4
|
||||
end
|
||||
end
|
||||
|
||||
def take_c_shared_ptr_by_pointer_ref(c)
|
||||
if c
|
||||
c.get_m
|
||||
else
|
||||
-5
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -42,7 +66,14 @@ raise unless call_ret_c_shared_ptr(a) == 1
|
|||
raise unless call_ret_c_shared_ptr(b) == -1
|
||||
raise unless call_ret_c_by_value(a) == 1
|
||||
|
||||
raise unless call_take_c_by_value(a) == 5
|
||||
raise unless call_take_c_shared_ptr_by_value(a) == 6
|
||||
raise unless call_take_c_shared_ptr_by_ref(a) == 7
|
||||
raise unless call_take_c_by_value(a) == 5
|
||||
raise unless call_take_c_shared_ptr_by_value(a) == 6
|
||||
raise unless call_take_c_shared_ptr_by_ref(a) == 7
|
||||
raise unless call_take_c_shared_ptr_by_pointer(a) == 8
|
||||
raise unless call_take_c_shared_ptr_by_pointer_ref(a) == 9
|
||||
|
||||
raise unless call_take_c_shared_ptr_by_value_with_null(a) == -2
|
||||
raise unless call_take_c_shared_ptr_by_ref_with_null(a) == -3
|
||||
raise unless call_take_c_shared_ptr_by_pointer_with_null(a) == -4
|
||||
raise unless call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -5
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue