add castmode in python and cleaning the castdispatch mechanism
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8051 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
485ccd5809
commit
6bf5187168
16 changed files with 461 additions and 101 deletions
|
|
@ -103,9 +103,9 @@ or you can use the %apply directive :
|
|||
}
|
||||
%typemap(typecheck,noblock=1,precedence=code,fragment=asval_frag) Type *INPUT, Type &INPUT {
|
||||
void *ptr;
|
||||
int res = asval_meth($input, 0);
|
||||
int res = SWIG_CastRank(asval_meth($input, 0));
|
||||
if (SWIG_IsOK(res)) {
|
||||
$1 = SWIG_GetCastRank(res);
|
||||
$1 = res;
|
||||
} else {
|
||||
$1 = %check_input_ptr($input,&ptr,$1_descriptor,0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,6 +197,40 @@ SWIG_AsVal_dec(ptrdiff_t)(SWIG_Object obj, ptrdiff_t *val)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_CanCastAsInteger","header",
|
||||
fragment=SWIG_AsVal_frag(double),
|
||||
fragment="<float.h>",
|
||||
fragment="<math.h>") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_CanCastAsInteger(double *d, double min, double max) {
|
||||
double x = *d;
|
||||
if (min <= x && x <= max) {
|
||||
%#ifndef SWIG_HAS_NO_RINT
|
||||
/* Use the python mechanism to round, or so */
|
||||
double rd = (x < 0) ? ceil(x) : floor(x);
|
||||
%#else
|
||||
double rd = rint(x);
|
||||
%#endif
|
||||
if ((errno == EDOM) || (errno == ERANGE)) {
|
||||
errno = 0;
|
||||
} else {
|
||||
if (rd == x) {
|
||||
return 1;
|
||||
} else {
|
||||
double diff = rd - x;
|
||||
double summ = rd + x;
|
||||
double reps = diff/summ;
|
||||
if (fabs(reps) < 8*DBL_EPSILON) {
|
||||
*d = rd;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Generate the typemaps for primitive type
|
||||
* ------------------------------------------------------------ */
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@
|
|||
|
||||
%define %value_typecheck_typemap(check,asval_meth,frag,Type...)
|
||||
%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
|
||||
int res = asval_meth($input, NULL);
|
||||
$1 = SWIG_GetCastRank(res);
|
||||
int res = SWIG_CastRank(asval_meth($input, NULL));
|
||||
$1 = SWIG_IsOK(res) ? res : 0;
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue