-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tamuratak-fix_ruby_director_and_shared_ptr'
* tamuratak-fix_ruby_director_and_shared_ptr: Rename shared_ptr testcase [ruby] use boost/shared_ptr and boost_shared_ptr.i. not use auto. [ruby] delete unnecessary changes. [ruby] add %typemap(directorin) for shared_ptr. [ruby] enable a test, cpp11_shared_ptr_director. [ruby] add %typemap(directorin) and %typemap(directorout) for shared_ptr. [ruby] add %typemap(directorout) for shared_ptr. add a test for shared_ptr with director Conflicts: CHANGES.current
- Loading branch information
Showing
5 changed files
with
249 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
%module(directors="1") "li_boost_shared_ptr_director" | ||
|
||
%{ | ||
#include <boost/shared_ptr.hpp> | ||
%} | ||
|
||
%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; }; | ||
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_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 ~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_shared_ptr_by_value(Base* b) { | ||
boost::shared_ptr<C> ptr(new C(6)); | ||
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(7)); | ||
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(8)); | ||
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(9)); | ||
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); | ||
} | ||
|
||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Examples/test-suite/ruby/li_boost_shared_ptr_director_runme.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'li_boost_shared_ptr_director' | ||
|
||
include Li_boost_shared_ptr_director | ||
|
||
class Derived < Base | ||
|
||
def initialize(flag) | ||
@return_none = flag | ||
super() | ||
end | ||
|
||
def ret_c_shared_ptr | ||
if @return_none | ||
nil | ||
else | ||
C.new | ||
end | ||
end | ||
|
||
def ret_c_by_value | ||
C.new | ||
end | ||
|
||
def take_c_by_value(c) | ||
c.get_m | ||
end | ||
|
||
def take_c_shared_ptr_by_value(c) | ||
if c | ||
c.get_m | ||
else | ||
-2 | ||
end | ||
end | ||
|
||
def take_c_shared_ptr_by_ref(c) | ||
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 | ||
|
||
a = Derived.new(false) | ||
b = Derived.new(true) | ||
|
||
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_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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters