summaryrefslogtreecommitdiff
path: root/Examples/test-suite/destructor_methodmodifiers.i
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2018-05-11 18:09:51 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2018-05-11 18:09:51 +0100
commitee17f8d04f40bfc25ecaf146a6ebe667eabcffb6 (patch)
tree5484f639a8a0625a090193e90df1c723063c7300 /Examples/test-suite/destructor_methodmodifiers.i
parent1f7689fa8f4e15bba03f7f7a279c5824e066208f (diff)
downloadswig-ee17f8d04f40bfc25ecaf146a6ebe667eabcffb6.tar.gz
C#, D, Java methodmodifiers on destructors
Add support so that the %csmethodmodifiers, %dmethodmodifiers, %javamethodmodifiers can modify the method modifiers for the destructor wrappers in the proxy class: dispose, Dispose, delete. With this feature, it is now possible to make a C# proxy class sealed, eg when wrapping a class X, the virtual method modifiers can be removed using: %typemap(csclassmodifiers) X "public sealed class" %csmethodmodifiers X::~X "public /*virtual*/";
Diffstat (limited to 'Examples/test-suite/destructor_methodmodifiers.i')
-rw-r--r--Examples/test-suite/destructor_methodmodifiers.i61
1 files changed, 61 insertions, 0 deletions
diff --git a/Examples/test-suite/destructor_methodmodifiers.i b/Examples/test-suite/destructor_methodmodifiers.i
new file mode 100644
index 000000000..93db7f2cc
--- /dev/null
+++ b/Examples/test-suite/destructor_methodmodifiers.i
@@ -0,0 +1,61 @@
+%module destructor_methodmodifiers
+
+// This test changes the proxy classes so that they cannot be inherited from in the target language
+// Previously the %csmethodmodifiers, %dmethodmodifiers, %javamethodmodifiers on destructors were ignored
+// Now they can control the dispose/Dispose/delete method modifiers
+
+#if defined(SWIGCSHARP)
+
+// remove all use of protected and virtual keywords
+%typemap(csclassmodifiers) NotForDeriving1, NotForDeriving2 "public sealed class"
+%csmethodmodifiers NotForDeriving1::~NotForDeriving1 "public /*not virtual nor override*/";
+%csmethodmodifiers NotForDeriving2::~NotForDeriving2 "public /*not virtual nor override*/";
+
+// remove protected keyword to remove compiler warning
+%typemap(csbody) NotForDeriving1, NotForDeriving2 %{
+ private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+ private /*protected*/ bool swigCMemOwn;
+
+ internal $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) {
+ swigCMemOwn = cMemoryOwn;
+ swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+ }
+
+ internal 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;
+ }
+%}
+
+#elif defined(SWIGD)
+
+%typemap(dclassmodifiers) NotForDeriving1, NotForDeriving2 "final class"
+%dmethodmodifiers NotForDeriving1::~NotForDeriving1 "public final";
+%dmethodmodifiers NotForDeriving2::~NotForDeriving2 "public final";
+
+#elif defined(SWIGJAVA)
+
+%typemap(javaclassmodifiers) NotForDeriving1, NotForDeriving2 "public final class"
+%javamethodmodifiers NotForDeriving1::~NotForDeriving1 "public synchronized final";
+%javamethodmodifiers NotForDeriving2::~NotForDeriving2 "public synchronized final";
+
+#endif
+
+%inline %{
+//#include <iostream>
+struct NotForDeriving1 {
+ void notvirtual() {}
+ ~NotForDeriving1() {
+// std::cout << "~NotForDeriving1 called" << std::endl;
+ }
+};
+struct NotForDeriving2 {
+ void notvirtual() {}
+#if defined(SWIG)
+%extend {
+ ~NotForDeriving2() {
+// std::cout << "~NotForDeriving2 called" << std::endl;
+ }
+}
+#endif
+};
+%}