[ruby] add %typemap(directorout) for shared_ptr.
This commit is contained in:
parent
1c968b3695
commit
b3c2b1c51c
3 changed files with 25 additions and 4 deletions
|
|
@ -9,7 +9,10 @@
|
|||
%feature("director") Creator;
|
||||
|
||||
%inline %{
|
||||
struct Created {};
|
||||
struct Created {
|
||||
Created() {};
|
||||
int get_m() { return 1; };
|
||||
};
|
||||
|
||||
struct Creator {
|
||||
Creator() {};
|
||||
|
|
@ -17,7 +20,13 @@ struct Creator {
|
|||
virtual ~Creator() {}
|
||||
};
|
||||
|
||||
void crash(Creator* creator) {
|
||||
int crash(Creator* creator) {
|
||||
std::shared_ptr<Created> ptr = creator->create();
|
||||
if (ptr) {
|
||||
return ptr->get_m();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ class Derived < Creator
|
|||
|
||||
end
|
||||
|
||||
crash(Derived.new(false))
|
||||
crash(Derived.new(true))
|
||||
p crash(Derived.new(false))
|
||||
p crash(Derived.new(true))
|
||||
|
||||
|
|
|
|||
|
|
@ -197,6 +197,18 @@
|
|||
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
|
||||
}
|
||||
|
||||
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void * swig_argp, int swig_res = 0) {
|
||||
if (NIL_P($input)) {
|
||||
$result = $ltype();
|
||||
} else {
|
||||
swig_res = SWIG_ConvertPtr($input,&swig_argp,$&descriptor, %convertptr_flags);
|
||||
if (!SWIG_IsOK(swig_res)) {
|
||||
%dirout_fail(swig_res,"$type");
|
||||
}
|
||||
$result = *(%reinterpret_cast(swig_argp, $<ype));
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
|
||||
swig_ruby_owntype newmem = {0, 0};
|
||||
void *argp = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue