[Gdal-dev] SWIG and CSharp

Kevin Ruland kruland at ku.edu
Mon Sep 26 10:15:04 EDT 2005


Ari Jolma wrote:

> Frank Warmerdam wrote:
>
>>    but not too Band.WriteRaster().  Would it be ok for me to change
>>    Band.i to use the exact same argument names for buf_len and
>> buf_string
>>    as Dataset.i?   I forsee some other specific naming conventions being
>>    needed for some other cases that I want to handle pretty
>> specially  in
>>    c#.  Other than obvious special names like argin and argout how much
>>    dependence is there on argument names in the .i files?
>>  
>>
>
> Nothing I believe. Typemaps are written for _type_ patterns. argin and
> argout in typemaps are just conventions. I may be wrong of course.
> Kevin, please correct me if I am.
>
> Ari
>

Ari,

it works like this:

If you specify argument names in the typemap, then the typemap selection
process will match argument names in the wrapped functions.  If you
don't specify argument names in the typemap, then they are not used in
selection process.  Here's a simple example:

%typemap(in) (int specialname) "/* Using specialname */"
%typemap(in) (int) "/* Using general typemap */"

void func1( int avariable );
void func2( int specialname);

This will use the "general typemap" for argument 1 (avariable) of func1
and will use "specialname typemap" for argument 1 (specialname) of func2.

All of the typemaps which we've defined have argument names.  This
prevents them from being used unless they are intended.   There are many
times when we force a typemap to be used by using the %apply directive.

%apply (int specialname) { (int differentname) };
void func3 (int differentname);
%clear (int differentname);

This will use the "specialname" typemap for argument 1 of func3.  We use
%clear immediately afterwards, because %apply is global and will be used
from that point on otherwise.  Again, this is to prevent mis application
of typemaps.

There are problems with the "out" typemaps because returned values do
not have names in C delcs.  We've used two different tricks to get these
to apply correctly.  The latest is to leverage the fact that most
returned values are CPLErr or OGRErr which even though they are ints are
treated as different types in SWIG.  These typemaps actually apply globally.

Kevin



More information about the Gdal-dev mailing list