[mapserver-commits] r7207 - in trunk/mapserver/mapscript: . csharp swiginc

svn at osgeo.org svn at osgeo.org
Sat Dec 22 15:32:11 EST 2007


Author: tamas
Date: 2007-12-22 15:32:11 -0500 (Sat, 22 Dec 2007)
New Revision: 7207

Added:
   trunk/mapserver/mapscript/csharp/swig_csharp_extensions.i
Modified:
   trunk/mapserver/mapscript/csharp/csmodule.i
   trunk/mapserver/mapscript/mapscript.i
   trunk/mapserver/mapscript/swiginc/class.i
   trunk/mapserver/mapscript/swiginc/layer.i
   trunk/mapserver/mapscript/swiginc/map.i
Log:
Implement parent reference in the C# classes MS-RFC-24 item 3.2 (#2442)

Modified: trunk/mapserver/mapscript/csharp/csmodule.i
===================================================================
--- trunk/mapserver/mapscript/csharp/csmodule.i	2007-12-22 17:44:04 UTC (rev 7206)
+++ trunk/mapserver/mapscript/csharp/csmodule.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -14,6 +14,8 @@
  *
  *****************************************************************************/
 
+
+
 /*Uncomment the following lines if you want to receive subsequent exceptions as
 inner exceptions. Otherwise the exception message will be concatenated*/
 //#if SWIG_VERSION >= 0x010329
@@ -169,7 +171,7 @@
       outputFormatObj[] ret = new outputFormatObj[this.numoutputformats];
       for(int cx = 0; cx < this.numoutputformats; cx++) {
           objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
-          ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false);
+          ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false, ThisOwn_false());
       }
       $excode
       return ret;
@@ -182,7 +184,7 @@
       outputFormatObj[] ret = new outputFormatObj[this.numoutputformats];
       for(int cx = 0; cx < this.numoutputformats; cx++) {
           objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
-          ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false);
+          ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false, ThisOwn_false());
       }
       $excode
       return ret;
@@ -326,15 +328,21 @@
  * with parent objects (causing nullreference exception, Bug 1743)
  *****************************************************************************/
 
-%typemap(csconstruct, excode=SWIGEXCODE) layerObj(mapObj map) %{: this($imcall, true) {
-  if (map != null) this.swigCMemOwn = false;$excode
+%typemap(csconstruct, excode=SWIGEXCODE) layerObj(mapObj map) %{: this($imcall, (map == null) , map) {
+  $excode
 }
 %}
-%typemap(csconstruct, excode=SWIGEXCODE) classObj(layerObj layer) %{: this($imcall, true) {
-  if (layer != null) this.swigCMemOwn = false;$excode
+%typemap(csconstruct, excode=SWIGEXCODE) classObj(layerObj layer) %{: this($imcall, (layer == null), layer) {
+  $excode
 }
 %}
-%typemap(csconstruct, excode=SWIGEXCODE) styleObj(classObj parent_class) %{: this($imcall, true) {
-  if (parent_class != null) this.swigCMemOwn = false;$excode
+%typemap(csconstruct, excode=SWIGEXCODE) styleObj(classObj parent_class) %{: this($imcall, (parent_class == null), parent_class) {
+  $excode
 }
 %}
+
+%typemap(csout, excode=SWIGEXCODE) classObj* getClass, layerObj* getLayer, layerObj *getLayerByName, styleObj* getStyle {
+    IntPtr cPtr = $imcall;
+    $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_false());$excode
+    return ret;
+  }

Added: trunk/mapserver/mapscript/csharp/swig_csharp_extensions.i
===================================================================
--- trunk/mapserver/mapscript/csharp/swig_csharp_extensions.i	                        (rev 0)
+++ trunk/mapserver/mapscript/csharp/swig_csharp_extensions.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -0,0 +1,149 @@
+
+/******************************************************************************
+ * $Id: swig_csharp_extensions.i 10898 2007-03-08 21:17:42Z tamas $
+ *
+ * Name:     swig_csharp_extensions.i
+ * Purpose:  Fix for the SWIG Interface problems (early GC) 
+ *           and implementing SWIGTYPE *DISOWN 
+ * Author:   Tamas Szekeres
+ *
+*/
+
+%typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
+    $&csclassname ret = new $&csclassname($imcall, true, null);$excode
+    return ret;
+  }
+
+%typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE & {
+    $csclassname ret = new $csclassname($imcall, $owner, ThisOwn_$owner());$excode
+    return ret;
+  }
+%typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) {
+    IntPtr cPtr = $imcall;
+    $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_$owner());$excode
+    return ret;
+  }
+%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & %{
+    get {
+      $csclassname ret = new $csclassname($imcall, $owner, ThisOwn_$owner());$excode
+      return ret;
+    } %}
+%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
+    get {
+      IntPtr cPtr = $imcall;
+      $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_$owner());$excode
+      return ret;
+    } %}
+%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& {
+    IntPtr cPtr = $imcall;
+    $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner, ThisOwn_$owner());$excode
+    return ret;
+  }
+// Proxy classes (base classes, ie, not derived classes)
+%typemap(csbody) SWIGTYPE %{
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+  protected object swigParentRef;
+  
+  protected static object ThisOwn_true() { return null; }
+  protected object ThisOwn_false() { return this; }
+
+  internal $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) {
+    swigCMemOwn = cMemoryOwn;
+    swigParentRef = parent;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr($csclassname obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+  internal static HandleRef getCPtrAndDisown($csclassname obj, object parent) {
+    obj.swigCMemOwn = false;
+    obj.swigParentRef = parent;
+    return getCPtr(obj);
+  }
+%}
+
+// Derived proxy classes
+%typemap(csbody_derived) SWIGTYPE %{
+  private HandleRef swigCPtr;
+
+  internal $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) : base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn, parent) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr($csclassname obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+  internal static HandleRef getCPtrAndDisown($csclassname obj, bool cMemoryOwn, object parent) {
+    obj.swigCMemOwn = cMemoryOwn;
+    obj.swigParentRef = parent;
+    return getCPtr(obj);
+  }
+%}
+
+// Typewrapper classes
+%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
+  private HandleRef swigCPtr;
+
+  internal $csclassname(IntPtr cPtr, bool futureUse, object parent) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected $csclassname() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr($csclassname obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+%}
+
+%typemap(csfinalize) SWIGTYPE %{
+  ~$csclassname() {
+    Dispose();
+  }
+%}
+
+%typemap(csconstruct, excode=SWIGEXCODE) SWIGTYPE %{: this($imcall, true, null) {$excode
+  }
+%}
+
+%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
+  lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        $imcall;
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      swigParentRef = null;
+      GC.SuppressFinalize(this);
+    }
+  }
+
+%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
+  lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        $imcall;
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      swigParentRef = null;
+      GC.SuppressFinalize(this);
+      base.Dispose();
+    }
+  }
+
+%typemap(csin) SWIGTYPE *DISOWN "$csclassname.getCPtrAndDisown($csinput, ThisOwn_false())"
+
+%pragma(csharp) modulecode=%{
+  internal class $moduleObject : IDisposable {
+	public virtual void Dispose() {
+      
+    }
+  }
+  internal static $moduleObject the$moduleObject = new $moduleObject();
+  protected static object ThisOwn_true() { return null; }
+  protected static object ThisOwn_false() { return the$moduleObject; }
+%}
+

Modified: trunk/mapserver/mapscript/mapscript.i
===================================================================
--- trunk/mapserver/mapscript/mapscript.i	2007-12-22 17:44:04 UTC (rev 7206)
+++ trunk/mapserver/mapscript/mapscript.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -32,6 +32,11 @@
 
 %module mapscript
 
+#ifdef SWIGCSHARP
+%ignore frompointer;
+%include swig_csharp_extensions.i
+#endif
+
 %{
 #include "../../mapserver.h"
 #include "../../maptemplate.h"

Modified: trunk/mapserver/mapscript/swiginc/class.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/class.i	2007-12-22 17:44:04 UTC (rev 7206)
+++ trunk/mapserver/mapscript/swiginc/class.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -192,9 +192,15 @@
         }
     }
 
+#ifdef SWIGCSHARP
+%apply SWIGTYPE *DISOWN {styleObj *style};
+#endif
     int insertStyle(styleObj *style, int index=-1) {
         return msInsertStyle(self, style, index);
     }
+#ifdef SWIGCSHARP 
+%clear styleObj *style;
+#endif
 
     %newobject removeStyle;
     styleObj *removeStyle(int index) {

Modified: trunk/mapserver/mapscript/swiginc/layer.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/layer.i	2007-12-22 17:44:04 UTC (rev 7206)
+++ trunk/mapserver/mapscript/swiginc/layer.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -122,10 +122,16 @@
         return msUpdateLayerFromString(self, snippet, MS_FALSE);
     }
 
+#ifdef SWIGCSHARP   
+%apply SWIGTYPE *DISOWN {classObj *classobj};
+#endif
     int insertClass(classObj *classobj, int index=-1)
     {
         return msInsertClass(self, classobj, index);
     }
+#ifdef SWIGCSHARP
+%clear classObj *classobj;
+#endif
     
     /* removeClass() */
     %newobject removeClass;

Modified: trunk/mapserver/mapscript/swiginc/map.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/map.i	2007-12-22 17:44:04 UTC (rev 7206)
+++ trunk/mapserver/mapscript/swiginc/map.i	2007-12-22 20:32:11 UTC (rev 7207)
@@ -63,10 +63,16 @@
         return dstMap;
     }
 
+#ifdef SWIGCSHARP
+%apply SWIGTYPE *DISOWN {layerObj *layer};
+#endif
     int insertLayer(layerObj *layer, int index=-1) 
     {
         return msInsertLayer(self, layer, index);  
     }
+#ifdef SWIGCSHARP
+%clear layerObj *layer;
+#endif
     
     %newobject removeLayer;
     layerObj *removeLayer(int index) 



More information about the mapserver-commits mailing list