aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/destructor_methodmodifiers.i
diff options
context:
space:
mode:
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
+};
+%}