[Gdal-dev] SWIG / TestCapability / Ruby

Kevin Ruland kruland at ku.edu
Mon Oct 3 07:43:22 EDT 2005


> Anyway, the good news is that SWIG seems to define the appropriate
> bool typemaps already for each language, so I don't think we need to
> introduce a fake BOOLEAN type.  Instead, I think all we have to do is
> change the return type from int to bool on the appropriate methods.
>
Cool.

> Thus in ogr.i:
>
> int TestCapability (const char *cap) {
>     return OGR_Dr_TestCapability(self, cap);
> }
>
> Becomes:
>
> bool TestCapability (const char *cap) {
> }
>
Ok.

> In the wrapper method, SWIG then typecasts the results from
> OGR_Dr_TestCapability to a bool, and applies the languages bool
> typemap (which they seem to all have).  So:
>
> static PyObject *_wrap_Driver_TestCapability(PyObject *, PyObject *args) {
>     PyObject *resultobj = NULL;
>     ...
>     result = (bool)OGRDriverShadow_TestCapability(arg1,(char const
> *)arg2);
>     ...
>    /* language specific typemap here, this is python */
>       resultobj = SWIG_From_bool(static_cast<bool >(result));
> }
>
It inserts the cast for you?  If so, this is really the way to go.  This
is no longer C-99 code though.  Going to have to ask frank about that. 
If he wants C-99 then we'll have to cobble together our own typemap and
insert a #define bool int.

> I suppose we could do this:
>
> int TestCapability (const char *cap) {
>     if (result = OGR_Dr_TestCapability(self, cap))
>        return true;
>    else
>       return false;
> }
>
Yuck.  if we don't have to do this, we shouldn't.

> But I don't think we have to.
>
> The methods in ogr.i I changed are:
>
> Equal
> testcapability
> IsFieldSet
> Intersect
> Equal
> Disjoint
> Touches
> Crosses
> Within
> Contains
> Overlaps
>
> I'd be glad to check it in or send it to you if you want to take a
> look and test with Python.
>
>
> Charlie
>




More information about the Gdal-dev mailing list