[gdal-dev] Exposing constants and enums to the SWIG interface

Tamas Szekeres szekerest at gmail.com
Wed Dec 12 17:41:34 EST 2007


Dear SWIG maintainers,

Currently we extensively use the following way to expose the constants
to the SWIG interface

%constant char *SRS_UL_US_FOOT = SRS_UL_US_FOOT;

that doesn't work equally well for all of the target languages.
In case of the csharp (and the java) bindings SWIG considers the right
side of the definition as the value itself and quotes the value in the
generated code. Therefore the caller will get  "SRS_UL_US_FOOT"
instead of it's underlying value ("U.S. Foot")

There's another fundamental problem how the constants are handled
right now that should be cleared up.
Most of the constants are defined in many places that might be out of
sync easily. For example we can find such definitions in both of
ogr_srs_api.h and gdalbridge.h. Most of these definitions are repeated
in osr.i but not all of them like

SRS_PT_BONNE, SRS_PT_ECKERT_I, SRS_PT_ECKERT_II, SRS_PT_ECKERT_III and
many more are completely missing and therefore not exposed to the SWIG
interface right now.

I would suggest to define the constants in a common place instead. We
could create a separate file like ogr_srs_const.h that would contain
all of the constants (and enums) to expose. Then ogr_srs_api.h,
gdalbridge.h would include this file directly and osr.i would use
%include  ogr_srs_api.h
for generating the wrappers. I consider %include is working equally
well for all of the SWIG languages, definitely.
I would also propose to expose the enum definitions this way.

How about these issues?


Best regards,

Tamas


More information about the gdal-dev mailing list