📄 typemaps_perl.i
字号:
SWIG_ConvertPtr( *sv, (void**)&item, SWIGTYPE_p_GDAL_GCP, 0 ); if ( ! item ) { SWIG_fail; } memcpy( (void*) tmpGCPList, (void*) item, sizeof( GDAL_GCP ) ); ++tmpGCPList; }}%typemap(freearg) (int nGCPs, GDAL_GCP const *pGCPs ){ /* %typemap(freearg) (int nGCPs, GDAL_GCP const *pGCPs ) */ if ($2) { free( (void*) $2 ); }}/* * Typemap for GDALColorEntry* <-> AV * GDALColorEntry* may be a return value and both input and output param */%typemap(out) GDALColorEntry*{ /* %typemap(out) GDALColorEntry* */ if (result == NULL) croak("GetColorEntry failed at index %i",result); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result->c1); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result->c2); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result->c3); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result->c4);}%typemap(in,numinputs=0) GDALColorEntry*(GDALColorEntry e){ /* %typemap(in,numinputs=0) GDALColorEntry*(GDALColorEntry e) */ $1 = &e;}%typemap(argout) GDALColorEntry*{ /* %typemap(argout) GDALColorEntry* */ if (result == FALSE) croak("GetColorEntryAsRGB failed at index %i",result); argvi--; $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) e3.c1); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) e3.c2); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) e3.c3); $result = sv_newmortal(); sv_setiv(ST(argvi++), (IV) e3.c4);}%typemap(argout) const GDALColorEntry*{ /* %typemap(argout) const GDALColorEntry* */}%typemap(in,numinputs=1) const GDALColorEntry*(GDALColorEntry e){ /* %typemap(in,numinputs=1) const GDALColorEntry*(GDALColorEntry e) */ $1 = &e3; if (! (SvROK($input) && (SvTYPE(SvRV($input))==SVt_PVAV))) { croak("argument is not an array ref"); SWIG_fail; } AV *av = (AV*)(SvRV($input)); int seq_size = av_len(av); if ( seq_size != 3 ) { croak("color entry argument array must have length 4 (it is %i)",seq_size+1); SWIG_fail; } SV **sv = av_fetch(av, 0, 0); $1->c1 = SvIV(*sv); sv = av_fetch(av, 1, 0); $1->c2 = SvIV(*sv); sv = av_fetch(av, 2, 0); $1->c3 = SvIV(*sv); sv = av_fetch(av, 3, 0); $1->c4 = SvIV(*sv);}/* * Typemap char ** <-> HV * */%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (char **dict){ /* %typecheck(SWIG_TYPECHECK_POINTER) (char **dict) */ $1 = (SvROK($input) && (SvTYPE(SvRV($input))==SVt_PVHV)) ? 1 : 0;}%typemap(in) char **dict{ /* %typemap(in) char **dict */ HV *hv = (HV*)SvRV($input); SV *sv; char *key; I32 klen; $1 = NULL; hv_iterinit(hv); while(sv = hv_iternextsv(hv,&key,&klen)) { $1 = CSLAddNameValue( $1, key, SvPV_nolen(sv) ); }}%typemap(out) char **dict{ /* %typemap(out) char **dict */ char **stringarray = $1; HV *hv = (HV*)sv_2mortal((SV*)newHV()); if ( stringarray != NULL ) { while (*stringarray != NULL ) { char const *valptr; char *keyptr; valptr = CPLParseNameValue( *stringarray, &keyptr ); if ( valptr != 0 ) { hv_store(hv, keyptr, strlen(keyptr), newSVpv(valptr, strlen(valptr)), 0); CPLFree( keyptr ); } stringarray++; } } $result = newRV_noinc((SV*)hv); argvi++;}%typemap(freearg) char **dict{ /* %typemap(freearg) char **dict */ CSLDestroy( $1 );}/* * Typemap char **options <-> AV */%typemap(in) char **options{ /* %typemap(in) char **options */ if ( ! (SvROK($input) && (SvTYPE(SvRV($input))==SVt_PVAV)) ) { croak("argument is not an array ref"); SWIG_fail; } AV *av = (AV*)(SvRV($input)); for (int i = 0; i < av_len(av)-1; i++) { char *pszItem = SvPV_nolen(*(av_fetch(av, i, 0))); $1 = CSLAddString( $1, pszItem ); }}%typemap(freearg) char **options{ /* %typemap(freearg) char **options */ CSLDestroy( $1 );}%typemap(out) char **options{ /* %typemap(out) char ** -> ( string ) */ AV* av = (AV*)sv_2mortal((SV*)newAV()); char **stringarray = $1; if ( stringarray != NULL ) { for ( int i = 0; i < CSLCount( stringarray ); ++i, ++stringarray ) { av_store(av, i, newSVpv(*stringarray, strlen(*stringarray))); } } $result = newRV_noinc((SV*)av); argvi++;}/* * Typemaps map mutable char ** arguments from AV. Does not * return the modified argument */%typemap(in) (char **ignorechange) ( char *val ){ /* %typemap(in) (char **ignorechange) */ val = SvPV_nolen($input); $1 = &val;}/* * Typemap for char **argout. */%typemap(in,numinputs=0) (char **argout) ( char *argout=0 ){ /* %typemap(in,numinputs=0) (char **argout) */ $1 = &argout;}%typemap(argout) (char **argout){ /* %typemap(argout) (char **argout) */ $result = sv_newmortal(); if ( $1 ) sv_setpv($result, *$1); argvi++;}%typemap(freearg) (char **argout){ /* %typemap(freearg) (char **argout) */ if ( *$1 ) CPLFree( *$1 );}/* * Typemap for an optional POD argument. * Declare function to take POD *. If the parameter * is NULL then the function needs to define a default * value. */%typemap(in) (int *optional_int) ( int val ){ /* %typemap(in) (int *optional_int) */ if ( !SvOK($input) ) { $1 = 0; } else { val = SvIV($input); $1 = ($1_type)&val; }}/* * Typedef const char * <- Any object. * * Formats the object using str and returns the string representation */%typemap(in) (tostring argin){ /* %typemap(in) (tostring argin) */ $1 = SvPV_nolen( $input ); }%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (tostring argin){ /* %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) (tostring argin) */ $1 = 1;}/* * Typemap for CPLErr. * This typemap will use the wrapper C-variable * int UseExceptions to determine proper behavour for * CPLErr return codes. * If UseExceptions ==0, then return the rc. * If UseExceptions ==1, then if rc >= CE_Failure, raise an exception. */%typemap(out) CPLErr{ /* %typemap(out) CPLErr */ $result = sv_2mortal(newSViv($1)); argvi++;}/* * Typemap for OGRErr. */%import "ogr_error_map.i"%typemap(out,fragment="OGRErrMessages") OGRErr{ /* %typemap(out) OGRErr */ if ( result != 0 ) { if (CPLGetLastErrorMsg()) croak( CPLGetLastErrorMsg() ); /* this is usually better */ croak( OGRErrMessages(result) ); }}/* * Typemaps for minixml: CPLXMLNode* input, CPLXMLNode *ret */%fragment("AVToXMLTree","header") %{/************************************************************************//* AVToXMLTree() *//************************************************************************/static CPLXMLNode *AVToXMLTree( AV *av ){ int nChildCount = 0, iChild, nType; CPLXMLNode *psThisNode; CPLXMLNode *psChild; char *pszText = NULL; nChildCount = av_len(av) - 1; if( nChildCount < 0 ) { croak("Error in input XMLTree."); return NULL; } nType = SvIV(*(av_fetch(av,0,0))); pszText = SvPV_nolen(*(av_fetch(av,1,0))); psThisNode = CPLCreateXMLNode( NULL, (CPLXMLNodeType) nType, pszText ); for( iChild = 0; iChild < nChildCount; iChild++ ) { psChild = AVToXMLTree( (AV *)(*(av_fetch(av,iChild+2,0))) ); CPLAddXMLChild( psThisNode, psChild ); } return psThisNode;}%}%typemap(in,fragment="AVToXMLTree") (CPLXMLNode* xmlnode ){ /* %typemap(in) (CPLXMLNode* xmlnode ) */ if ( ! (SvROK($input) && (SvTYPE(SvRV($input))==SVt_PVAV)) ) { croak("argument is not an array ref"); SWIG_fail; } AV *av = (AV*)(SvRV($input)); $1 = AVToXMLTree( av ); if ( !$1 ) SWIG_fail;}%typemap(freearg) (CPLXMLNode *xmlnode){ /* %typemap(freearg) (CPLXMLNode *xmlnode) */ if ( $1 ) CPLDestroyXMLNode( $1 );}%fragment("XMLTreeToAV","header") %{/************************************************************************//* XMLTreeToAV() *//************************************************************************/static AV *XMLTreeToAV( CPLXMLNode *psTree ){ AV *av; int nChildCount = 0, iChild; CPLXMLNode *psChild; for( psChild = psTree->psChild; psChild != NULL; psChild = psChild->psNext ) nChildCount++; av = (AV*)sv_2mortal((SV*)newAV()); av_store(av,0,newSViv((int) psTree->eType)); av_store(av,1,newSVpv(psTree->pszValue, strlen(psTree->pszValue))); for( psChild = psTree->psChild, iChild = 2; psChild != NULL; psChild = psChild->psNext, iChild++ ) { av_store(av, iChild, newRV_noinc((SV*)(XMLTreeToAV( psChild ))) ); } return av;}%}%typemap(out,fragment="XMLTreeToAV") (CPLXMLNode*){ /* %typemap(out) (CPLXMLNode*) */ $result = newRV_noinc((SV*)XMLTreeToAV( $1 )); argvi++;}%typemap(ret) (CPLXMLNode*){ /* %typemap(ret) (CPLXMLNode*) */ if ( $1 ) CPLDestroyXMLNode( $1 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -