1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
/******************************************************************************
* $Id: typemaps_php.i 8582 2005-10-11 14:11:43Z kruland $
*
* Name: typemaps_php.i
* Project: GDAL PHP Interface
* Purpose: GDAL Core SWIG Interface declarations.
* Author: Kevin Ruland, kruland@ku.edu
*
*/
/*
* Include the typemaps from swig library for returning of
* standard types through arguments.
*/
%include "typemaps.i"
%apply (double *OUTPUT) { double *argout };
/*
* double *val, int*hasval, is a special contrived typemap used for
* the RasterBand GetNoDataValue, GetMinimum, GetMaximum, GetOffset, GetScale methods.
* In the python bindings, the variable hasval is tested. If it is 0 (is, the value
* is not set in the raster band) then Py_None is returned. If is is != 0, then
* the value is coerced into a long and returned.
*/
%typemap(in,numinputs=0) (double *val, int*hasval) ( double tmpval, int tmphasval ) {
/* %typemap(in,numinputs=0) (double *val, int*hasval) */
$1 = &tmpval;
$2 = &tmphasval;
}
%typemap(argout) (double *val, int*hasval) {
/* %typemap(argout) (double *val, int*hasval) */
if ( !*$2 ) {
RETVAL_NULL();
}
else {
RETVAL_DOUBLE( *$1 );
}
}
/*
*
* Define a simple return code typemap which checks if the return code from
* the wrapped method is non-zero. If non-zero, return None. Otherwise,
* return any argout or None.
*
* Applied like this:
* %apply (IF_ERR_RETURN_NONE) {CPLErr};
* CPLErr function_to_wrap( );
* %clear (CPLErr);
*/
%typemap(out) IF_FALSE_RETURN_NONE
{
/* %typemap(out) IF_FALSE_RETURN_NONE */
RETVAL_NULL();
}
%typemap(ret) IF_FALSE_RETURN_NONE
{
/* %typemap(ret) IF_FALSE_RETURN_NONE */
RETVAL_NULL();
}
/*
* Another output typemap which will raise an
* exception on error. If there is no error,
* and no other argout typemaps create a return value,
* then it will return 0.
*/
%fragment("OGRErrMessages","header") %{
static char *
OGRErrMessages( int rc ) {
switch( rc ) {
case 0:
return "OGR Error 0: None";
case 1:
return "OGR Error 1: Not enough data";
case 2:
return "OGR Error 2: Unsupported geometry type";
case 3:
return "OGR Error 3: Unsupported operation";
case 4:
return "OGR Error 4: Corrupt data";
case 5:
return "OGR Error 5: General Error";
case 6:
return "OGR Error 6: Unsupported SRS";
default:
return "OGR Error: Unknown";
}
}
%}
%typemap(out) OGRErr
{
/* %typemap(out) OGRErr */
if (result != 0 ) {
SWIG_PHP_Error(E_ERROR,OGRErrMessages(result));
}
}
%typemap(ret,fragment="OGRErrMessages") OGRErr
{
/* %typemap(ret) OGRErr */
RETVAL_LONG(0);
}
%fragment("CreateTupleFromDoubleArray","header") %{
zval *
CreateTupleFromDoubleArray( double *first, unsigned int size ) {
zval *tmp;
MAKE_STD_ZVAL(tmp);
array_init(tmp);
for( unsigned int i=0; i<size; i++ ) {
add_next_index_double( tmp, *first );
++first;
}
return tmp;
}
%}
%typemap(in,numinputs=0) ( double argout[ANY]) (double argout[$dim0])
{
/* %typemap(in,numinputs=0) (double argout[ANY]) */
$1 = argout;
}
%typemap(argout,fragment="CreateTupleFromDoubleArray,t_output_helper") ( double argout[ANY])
{
/* %typemap(argout) (double argout[ANY]) */
zval *t = CreateTupleFromDoubleArray( $1, $dim0 );
t_output_helper( &$result, t );
}
%typemap(in,numinputs=0) ( double *argout[ANY]) (double *argout)
{
/* %typemap(in,numinputs=0) (double *argout[ANY]) */
$1 = &argout;
}
%typemap(argout,fragment="CreateTupleFromDoubleArray,t_output_helper") ( double *argout[ANY])
{
/* %typemap(argout) (double *argout[ANY]) */
zval *t = CreateTupleFromDoubleArray( *$1, $dim0 );
t_output_helper( &$result, t);
}
%typemap(freearg) (double *argout[ANY])
{
/* %typemap(freearg) (double *argout[ANY]) */
CPLFree(*$1);
}
%typemap(in) (double argin[ANY]) (double argin[$dim0])
{
/* %typemap(in) (double argin[ANY]) */
$1 = argin;
for (unsigned int i=0; i<$dim0; i++) {
double val = 0.0; /* extract val from i-th position of $input */
$1[i] = val;
}
}
/*
* Typemap for counted arrays of ints <- PySequence
*/
%typemap(in,numinputs=1) (int nList, int* pList)
{
/* %typemap(in,numinputs=1) (int nList, int* pList)*/
zend_error(E_ERROR,"Typemap (in,numinputs=1) (int nList, int*pList) not properly defined");
/* check if is List */
// if ( !PySequence_Check($input) ) {
// PyErr_SetString(PyExc_TypeError, "not a sequence");
// SWIG_fail;
// }
// $1 = PySequence_Size($input);
// $2 = (int*) malloc($1*sizeof(int));
// for( int i = 0; i<$1; i++ ) {
// PyObject *o = PySequence_GetItem($input,i);
// if ( !PyArg_Parse(o,"i",&$2[i]) ) {
// SWIG_fail;
// }
// }
}
%typemap(freearg) (int nList, int* pList)
{
/* %typemap(freearg) (int nList, int* pList) */
if ($2) {
free((void*) $2);
}
}
/*
* Typemap for buffers with length <-> PyStrings
* Used in Band::ReadRaster() and Band::WriteRaster()
*
* This typemap has a typecheck also since the WriteRaster()
* methods are overloaded.
*/
%typemap(in,numinputs=0) (int *nLen, char **pBuf ) ( int nLen = 0, char *pBuf = 0 )
{
/* %typemap(in,numinputs=0) (int *nLen, char **pBuf ) */
$1 = &nLen;
$2 = &pBuf;
}
%typemap(argout) (int *nLen, char **pBuf )
{
/* %typemap(argout) (int *nLen, char **pBuf ) */
ZVAL_STRINGL( $result, *$2, *$1, 1 );
}
%typemap(freearg) (int *nLen, char **pBuf )
{
/* %typemap(freearg) (int *nLen, char **pBuf ) */
if( *$1 ) {
free( *$2 );
}
}
%typemap(in,numinputs=1) (int nLen, char *pBuf )
{
/* %typemap(in,numinputs=1) (int nLen, char *pBuf ) */
convert_to_string_ex($input);
$2 = Z_STRVAL_PP($input);
$1 = Z_STRLEN_PP($input);
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER)
(int nLen, char *pBuf)
{
/* %typecheck(SWIG_TYPECHECK_POINTER) (int nLen, char *pBuf) */
$1 = ($input)->type == IS_STRING;
}
/*
* Typemap argout of GDAL_GCP* used in Dataset::GetGCPs( )
*/
%typemap(in,numinputs=0) (int *nGCPs, GDAL_GCP const **pGCPs ) (int nGCPs=0, GDAL_GCP *pGCPs=0 )
{
/* %typemap(in,numinputs=0) (int *nGCPs, GDAL_GCP const **pGCPs ) */
$1 = &nGCPs;
$2 = &pGCPs;
}
%typemap(argout) (int *nGCPs, GDAL_GCP const **pGCPs )
{
/* %typemap(argout) (int *nGCPs, GDAL_GCP const **pGCPs ) */
zval *out;
MAKE_STD_ZVAL(out);
array_init(out);
for( int i = 0; i < *$1; i++ ) {
GDAL_GCP *o = new_GDAL_GCP( (*$2)[i].dfGCPX,
(*$2)[i].dfGCPY,
(*$2)[i].dfGCPZ,
(*$2)[i].dfGCPPixel,
(*$2)[i].dfGCPLine,
(*$2)[i].pszInfo,
(*$2)[i].pszId );
zval *t;
MAKE_STD_ZVAL(t);
SWIG_SetPointerZval(t,(void*)o,SWIGTYPE_p_GDAL_GCP,1);
add_next_index_zval(out,t);
}
$result = out;
zval_copy_ctor($result);
}
%typemap(in,numinputs=1) (int nGCPs, GDAL_GCP const *pGCPs ) ( GDAL_GCP *tmpGCPList )
{
/* %typemap(in,numinputs=1) (int nGCPs, GDAL_GCP const *pGCPs ) */
}
%typemap(freearg) (int nGCPs, GDAL_GCP const *pGCPs )
{
/* %typemap(freearg) (int nGCPs, GDAL_GCP const *pGCPs ) */
if ($2) {
free( (void*) $2 );
}
}
/*
* Typemap for GDALColorEntry* <-> tuple
*/
%typemap(out) GDALColorEntry*
{
/* %typemap(out) GDALColorEntry* */
array_init($result);
add_next_index_long($result,(*$1).c1);
add_next_index_long($result,(*$1).c2);
add_next_index_long($result,(*$1).c3);
add_next_index_long($result,(*$1).c4);
}
%typemap(in) GDALColorEntry*
{
/* %typemap(in) GDALColorEntry* */
GDALColorEntry ce = {255,255,255,255};
// Need to parse the array values from $input
$1 = &ce;
}
/*
* Typemap char ** -> dict
*/
%typemap(out) char **dict
{
/* %typemap(out) char **dict */
char **stringarray = $1;
array_init($result);
if ( stringarray != NULL ) {
while (*stringarray != NULL ) {
char const *valptr;
char *keyptr;
valptr = CPLParseNameValue( *stringarray, &keyptr );
if ( valptr != 0 ) {
add_assoc_string($result,keyptr,(char*)valptr,1);
CPLFree( keyptr );
}
stringarray++;
}
}
}
/*
* Typemap char **<- dict. This typemap actually supports lists as well,
* Then each entry in the list must be a string and have the form:
* "name=value" so gdal can handle it.
*/
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (char **dict)
{
/* %typecheck(SWIG_TYPECHECK_POINTER) (char **dict) */
$1 = 0; //(PyMapping_Check($input) || PySequence_Check($input) ) ? 1 : 0;
}
%typemap(in) char **dict
{
/* %typemap(in) char **dict */
zend_error(E_ERROR,"Typemap (in) char **dict not properly defined");
/* if ( PySequence_Check( $input ) ) {
int size = PySequence_Size($input);
for (int i = 0; i < size; i++) {
char *pszItem = NULL;
if ( ! PyArg_Parse( PySequence_GetItem($input,i), "s", &pszItem ) ) {
PyErr_SetString(PyExc_TypeError,"sequence must contain strings");
SWIG_fail;
}
$1 = CSLAddString( $1, pszItem );
}
}
*/
}
%typemap(freearg) char **dict
{
/* %typemap(freearg) char **dict */
CSLDestroy( $1 );
}
/*
* Typemap maps char** arguments from Python Sequence Object
*/
%typemap(in) char **options
{
/* %typemap(in) char **options */
zend_error(E_ERROR,"Typemap (in) char **options not properly defined");
// int size = PySequence_Size($input);
// for (int i = 0; i < size; i++) {
// char *pszItem = NULL;
// if ( ! PyArg_Parse( PySequence_GetItem($input,i), "s", &pszItem ) ) {
// PyErr_SetString(PyExc_TypeError,"sequence must contain strings");
// SWIG_fail;
// }
// $1 = CSLAddString( $1, pszItem );
// }
}
%typemap(freearg) char **options
{
/* %typemap(freearg) char **options */
CSLDestroy( $1 );
}
%typemap(out) char **options
{
/* %typemap(out) char ** -> ( string ) */
char **stringarray = $1;
if ( stringarray == NULL ) {
RETVAL_NULL();
}
else {
int len = CSLCount( stringarray );
array_init($result);
for ( int i = 0; i < len; ++i, ++stringarray ) {
add_next_index_string( $result, *stringarray, 1 );
}
}
}
/*
* Typemaps map mutable char ** arguments from PyStrings. Does not
* return the modified argument
*/
%typemap(in) (char **ignorechange) ( char *val )
{
/* %typemap(in) (char **ignorechange) */
convert_to_string_ex( $input );
$1 = NULL;
}
/*
* Typemap for char **argout.
*/
%typemap(in,numinputs=0) (char **argout) ( char *argout=0 )
{
/* %typemap(in,numinputs=0) (char **argout) */
$1 = &argout;
}
%typemap(argout,fragment="t_output_helper") (char **argout)
{
/* %typemap(argout) (char **argout) */
zval *t;
MAKE_STD_ZVAL(t);
if ( $1 ) {
ZVAL_STRING(t,*$1,strlen(*$1));
}
else {
ZVAL_NULL(t);
}
t_output_helper(&$result, t);
}
%typemap(freearg) (char **argout)
{
/* %typemap(freearg) (char **argout) */
if ( *$1 )
CPLFree( *$1 );
}
%typemap(in) (int *optional_int) ( $*1_ltype val )
{
/* %typemap(in) (int *optional_int) */
if ( ZVAL_IS_NULL(*$input) ) {
$1 = 0;
}
convert_to_long_ex($input);
val = ($*1_ltype) Z_LVAL_PP( $input );
$1 = &val;
}
%typemap(typecheck,precedence=0) (int *optional_int)
{
/* %typemap(typecheck,precedence=0) (int *optional_int) */
$1 = (($input->type == IS_NONE) || $input->type == IS_LONG ) ? 1 : 0;
}
/*
* Typedef const char * <- Any object.
*
* Formats the object using str and returns the string representation
*/
%typemap(in) (tostring argin)
{
/* %typemap(in) (tostring argin) */
convert_to_string_ex($input);
$1 = Z_STRVAL_PP( $input );
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (tostring argin)
{
/* %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (tostring argin) */
$1 = 1;
}
|