[Gdal-dev] C# Bindings
Simon Perkins
sy at perkins.net
Thu Nov 2 19:56:03 EST 2006
Tamas Szekeres wrote:
> Since I would support VS2003 with FW 1.x and MONO the template
> approach is not realistic so far. Instead I would support overloading
> the functions with the generic data types. It will be mostly a C#
> interface specific solution. I will take care of it as soon as
> possible.
Fair enough. My initial thought was to suggest a signature like:
public void ReadRaster(int xOff, int yOff, int xSize, int ySize, byte*
buffer, int bufXSize, int bufYSize, int pixelSpace, int lineSpace)
and similarly for other data types (short, ushort, int, uint, long,
ulong, float, double). Using a pointer rather than an array for the
buffer allows the method to be used to fill Bitmaps without having to
copy into an intermediate array.
So, that would be 9 methods, and that's not even including signed bytes
or complex data types...
It would also be nice not to have to specify all the arguments in common
cases. Since we don't have default arguments in C#, we could use two
more overloads for each of the above with signatures like:
// bufXSize == xSize, bufYSize == ySize, pixelSpace ==
sizeof(datatype), lineSpace == sizeof(datatype) * bufXSize
public void ReadRaster(int xOff, int yOff, int xSize, int ySize, byte*
buffer)
// pixelSpace == sizeof(datatype), lineSpace == sizeof(datatype) *
bufXSize
public void ReadRaster(int xOff, int yOff, int xSize, int ySize, byte*
buffer, int bufXSize, int bufYSize)
So we're up to 27 different methods...
And then all over again for WriteRaster(). Making a grand total of 54
different method signatures for reading and writing data - not covering
all the possible data types! Hmmm...
OK, if that's way too many, how about this as an alternative: we follow
the GDAL pattern and pass an IntPtr buffer, along with an enum argument
that specifies the data type. We can probably also drop one of the above
overloads, since this is a low level API. In that case, we would have a
grand total of 4 signatures:
public void ReadRaster(int xOff, int yOff, int xSize, int ySize,
IntPtr buffer, int bufXSize, int bufYSize, GDALDataType type)
public void ReadRaster(int xOff, int yOff, int xSize, int ySize, IntPtr
buffer, int bufXSize, int bufYSize, GDALDataType type, int pixelSpace,
int lineSpace)
public void WriteRaster(int xOff, int yOff, int xSize, int ySize,
IntPtr buffer, int bufXSize, int bufYSize, GDALDataType type)
public void WriteRaster(int xOff, int yOff, int xSize, int ySize,
IntPtr buffer, int bufXSize, int bufYSize, GDALDataType type, int
pixelSpace, int lineSpace)
How does that sound? Maybe at some point in the future when generics are
the norm, we can add templated versions to get a modicum of type safety
and avoid having to specify a data type explicitly.
Cheers!
Sy
P.S. I've just checked in my manifest embedding changes to makefile.vc
More information about the Gdal-dev
mailing list