[Gdal-dev] SWIG / TestCapability / Ruby
Charlie Savage
cfis at interserv.com
Sat Oct 1 04:03:39 EDT 2005
The various TestCapability methods in OGR have a return type of integer.
However, if you read the OGR C API documentation its says:
"Returns: TRUE if the layer has the requested capability, or FALSE
otherwise. OGRLayers will return FALSE for any unrecognized capabilities."
So it seems like the intent it to return a boolean. In C-like languages
returning an int is ok, since 0 evaluates to false.
This however, is not the case in all languages. In Ruby, for example,
false is either nil (same as NULL or PyNone) or false. Thus the value 0
does *not* evaluate to false. That means you can't do something what is
natural:
if lyr.test_capability( 'FastGetExtent')
It will always evaluate to true in Ruby!
I would like to change the SWIG wrapper code so that all the
testcapability methods return booleans. I think this is ok, since the
bindings are built using SWIG's C++ mode, so boolean is a supported data
type. That way I don't have to put in a separate mapping for these
methods just in the Ruby bindings.
Thanks,
Charlie
More information about the Gdal-dev
mailing list