massive typemap unification

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-18 13:24:15 +00:00
commit 7e5e4fd1f9
144 changed files with 6378 additions and 7248 deletions

View file

@ -10,42 +10,36 @@
/* the common from conversor */
%define %swig_fromcplx_conv(Type, Real, Imag)
%fragment(SWIG_From_frag(Type),"header")
%{
{
SWIGINTERNINLINE PyObject*
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
{
return PyComplex_FromDoubles(Real(c), Imag(c));
}
%}
}
%enddef
/* the double case */
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(double))
%{
{
SWIGINTERN int
SWIG_AsVal(Type) (PyObject *o, Type* val)
SWIG_AsVal(Type) (PyObject *o, Type* val)
{
if (PyComplex_Check(o)) {
if (val) *val = Constructor(PyComplex_RealAsDouble(o),
PyComplex_ImagAsDouble(o));
return 1;
if (val) *val = Constructor(PyComplex_RealAsDouble(o), PyComplex_ImagAsDouble(o));
return SWIG_OK;
} else {
double d;
if (SWIG_AsVal(double)(o, &d)) {
if (SWIG_AsVal(double)(o, &d) == SWIG_OK) {
if (val) *val = Constructor(d, 0.0);
return 1;
} else {
PyErr_Clear();
return SWIG_OK;
}
}
if (val) {
SWIG_type_error("Type", o);
}
return 0;
return SWIG_TypeError;
}
}
%}
%swig_fromcplx_conv(Type, Real, Imag);
%enddef
@ -55,37 +49,26 @@ SWIGINTERN int
fragment="SWIG_CheckDoubleInRange",
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal(Type)(PyObject *o, Type *val)
SWIG_AsVal(Type)(PyObject *o, Type *val)
{
const char* errmsg = val ? #Type : 0;
if (PyComplex_Check(o)) {
double re = PyComplex_RealAsDouble(o);
double im = PyComplex_ImagAsDouble(o);
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)
&& SWIG_CheckDoubleInRange(im, -FLT_MAX, FLT_MAX, errmsg)) {
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
if (val) *val = Constructor(SWIG_numeric_cast(re, float),
SWIG_numeric_cast(im, float));
return 1;
return SWIG_OK;
} else {
return 0;
return SWIG_TypeError;
}
} else {
double re;
if (SWIG_AsVal(double)(o, &re)) {
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)) {
if (val) *val = Constructor(SWIG_numeric_cast(re,float), 0.0);
return 1;
} else {
return 0;
}
} else {
PyErr_Clear();
float re;
if (SWIG_AsVal(float)(o, &re) == SWIG_OK) {
if (val) *val = Constructor(re, 0.0);
return SWIG_OK;
}
}
if (val) {
SWIG_type_error("Type", o);
}
return 0;
return SWIG_TypeError;
}
}