[Gdal-dev] On Feature.setGeometryDirectly SWIG bindings
Tamas Szekeres
szekerest at gmail.com
Sun Mar 18 17:55:57 EDT 2007
2007/3/18, Andrea Aime <aaime at openplans.org>:
>
> Both java and c# bindings do have a delete() method that allows
> to deallocate the native pointer, and the object finalizers
> do call delete() always. I don't see that typemap making any difference
> there...
>
I've just generated the gdal java wrappers and I can see the following
implementation of the delete method for Geometry class:
public void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
swigCMemOwn = false;
ogrJNI.delete_Geometry(swigCPtr);
}
swigCPtr = 0;
}
So if you can set swigCMemOwn to false the native pointer referenced
memory wil not be deallocated by this wrapper.
To achieve this operation you might want to implement the
SetGeometryDirectly function this way:
public int SetGeometryDirectly(Geometry geom) {
return ogrJNI.Feature_SetGeometryDirectly(swigCPtr,
Geometry.getCPtrAndDisown(geom));
}
And for the Geometry class getCPtrAndDisown should be implemented as:
protected static long getCPtrAndDisown(Geometry obj) {
if (obj != null) obj.swigCMemOwn= false;
return getCPtr(obj);
}
Hopefully, this implementation can be achieved as:
%typemap(javacode) SWIGTYPE %{
protected static long getCPtrAndDisown($javaclassname obj) {
if (obj != null) obj.swigCMemOwn= false;
return getCPtr(obj);
}
%}
%typemap(javain) SWIGTYPE *DISOWN "$javaclassname.getCPtrAndDisown($javainput)"
This code haven't been tested though.
If you implement these changes you will also eliminate the following
warnings when creating the java interface:
.\swig_lib\..\..\..\include\ogr.i(672): Warning(453): Can't apply
(SWIGTYPE *DISOWN). No typemaps are defined.
.\swig_lib\..\..\..\include\ogr.i(837): Warning(453): Can't apply
(SWIGTYPE *DISOWN). No typemaps are defined.
.\swig_lib\..\..\..\include\ogr.i(1305): Warning(453): Can't apply
(SWIGTYPE *DISOWN). No typemaps are defined.
Best regards,
Tamas
More information about the Gdal-dev
mailing list