better STL support, see CHANGES.current

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5755 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-17 09:41:19 +00:00
commit 1d5529bcfc
25 changed files with 3572 additions and 4193 deletions

View file

@ -11,63 +11,96 @@
*/
/* the common from conversor */
%define %swig_fromcplx_conv(Type, Name, Real, Imag)
%fragment("SWIG_From"#Name,"header")
%define %swig_fromcplx_conv(Type, Real, Imag)
%fragment(SWIG_From_frag(Type),"header")
%{
SWIGSTATIC(PyObject*)
SWIG_From##Name(Type c)
SWIGSTATICINLINE(PyObject*)
SWIG_From_meth(Type)(SWIG_cplusplus(const Type&, Type) c)
{
return PyComplex_FromDoubles(Real(c), Imag(c));
}
%}
%enddef
/* the double case */
%define %swig_cplxdbl_conv(Type, Name, Constructor, Real, Imag)
%fragment("SWIG_As"#Name,"header",
fragment="SWIG_AsDouble")
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(double))
%{
SWIGSTATIC(Type)
SWIG_As##Name(PyObject *o)
SWIGSTATICINLINE(int)
SWIG_AsVal_meth(Type) (PyObject *o, Type* val)
{
Type c = PyComplex_Check(o) ?
Constructor(PyComplex_RealAsDouble(o),
PyComplex_ImagAsDouble(o)) :
Constructor(SWIG_AsDouble(o), 0);
if (PyErr_Occurred()){
PyErr_Clear();
if (PyComplex_Check(o)) {
if (val) *val = Constructor(PyComplex_RealAsDouble(o),
PyComplex_ImagAsDouble(o));
return 1;
} else {
double d;
if (SWIG_AsVal_meth(double)(o, &d)) {
if (val) *val = Constructor(d, 0);
return 1;
} else {
PyErr_Clear();
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a Type is expected");
}
return c;
return 0;
}
%}
%swig_fromcplx_conv(Type, Name, Real, Imag);
%swig_fromcplx_conv(Type, Real, Imag);
%enddef
/* the float case */
%define %swig_cplxflt_conv(Type, Name, Constructor, Real, Imag)
%fragment("SWIG_As"#Name,"header",
fragment="SWIG_CheckFloat",
fragment="SWIG_AsDouble")
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment="SWIG_CheckDoubleInRange",
fragment=SWIG_AsVal_frag(float))
%{
SWIGSTATIC(Type)
SWIG_As##Name(PyObject *o)
SWIGSTATICINLINE(int)
SWIG_AsVal_meth(Type)(PyObject *o, Type *val)
{
Type c = PyComplex_Check(o) ?
Constructor(SWIG_CheckFloat(PyComplex_RealAsDouble(o)),
SWIG_CheckFloat(PyComplex_RealAsDouble(o))) :
Constructor(SWIG_CheckFloat(SWIG_AsDouble(o)),0);
if (PyErr_Occurred()) {
PyErr_Clear();
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_MIN, FLT_MAX, errmsg)
&& SWIG_CheckDoubleInRange(im, FLT_MIN, FLT_MAX, errmsg)) {
if (val) *val = Constructor(swig_numeric_cast(re, float),
swig_numeric_cast(im, float));
return 1;
} else {
return 0;
}
} else {
double re;
if (SWIG_AsVal_meth(double)(o, &re)) {
if (SWIG_CheckDoubleInRange(re, FLT_MIN, FLT_MAX, errmsg)) {
if (val) *val = Constructor(swig_numeric_cast(re,float), 0);
return 1;
} else {
return 0;
}
} else {
PyErr_Clear();
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a Type is expected");
}
return c;
}
return 0;
}
%}
%swig_fromcplx_conv(Type, Name, Real, Imag);
%swig_fromcplx_conv(Type, Real, Imag);
%enddef
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
%swig_cplxflt_conv(Type, Constructor, Real, Imag)
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
#endif //__python_complex_common_i__