Add C# support std::unique_ptr inputs

Based on Java implementation.
This commit is contained in:
William S Fulton 2022-07-15 17:41:58 +01:00
commit c737bd5713
5 changed files with 103 additions and 4 deletions

View file

@ -913,6 +913,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
if (obj != null) {
if (!obj.swigCMemOwn)
throw new global::System.ApplicationException("Cannot release ownership as memory is not owned");
global::System.Runtime.InteropServices.HandleRef ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.Dispose();
return ptr;
} else {
return new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
}
%}
// Derived proxy classes
@ -926,6 +939,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
if (obj != null) {
if (!obj.swigCMemOwn)
throw new global::System.ApplicationException("Cannot release ownership as memory is not owned");
global::System.Runtime.InteropServices.HandleRef ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.Dispose();
return ptr;
} else {
return new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
}
%}
%enddef
@ -945,6 +971,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csbody) TYPE (CLASS::*) %{

View file

@ -9,7 +9,7 @@
%define %auto_ptr(TYPE)
%typemap (ctype) std::auto_ptr< TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::auto_ptr< TYPE > "HandleRef"
%typemap (imtype, out="System.IntPtr") std::auto_ptr< TYPE > "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) std::auto_ptr< TYPE > "$typemap(cstype, TYPE)"
%typemap (out) std::auto_ptr< TYPE > %{
$result = (void *)$1.release();

View file

@ -9,8 +9,14 @@
%define %unique_ptr(TYPE)
%typemap (ctype) std::unique_ptr< TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::unique_ptr< TYPE > "HandleRef"
%typemap (imtype, out="System.IntPtr") std::unique_ptr< TYPE > "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) std::unique_ptr< TYPE > "$typemap(cstype, TYPE)"
%typemap(in) std::unique_ptr< TYPE >
%{ $1.reset((TYPE *)$input); %}
%typemap(csin) std::unique_ptr< TYPE > "$typemap(cstype, TYPE).swigRelease($csinput)"
%typemap (out) std::unique_ptr< TYPE > %{
$result = (void *)$1.release();
%}
@ -23,5 +29,5 @@
%enddef
namespace std {
template <class T> class unique_ptr {};
template <class T> class unique_ptr {};
}