2 Defines the As/From converters for double/float complex, you need to
3 provide complex Type, the Name you want to use in the converters,
4 the complex Constructor method, and the Real and Imag complex
7 See the std_complex.i and ccomplex.i for concret examples.
10 /* the common from converter */
11 %define %swig_fromcplx_conv(Type, Real, Imag)
12 %fragment(SWIG_From_frag(Type),"header")
14 SWIGINTERNINLINE PyObject*
15 SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
17 return PyComplex_FromDoubles(Real(c), Imag(c));
23 %define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
24 %fragment(SWIG_AsVal_frag(Type),"header",
25 fragment=SWIG_AsVal_frag(double))
28 SWIG_AsVal(Type) (PyObject *o, Type* val)
30 if (PyComplex_Check(o)) {
31 if (val) *val = Constructor(PyComplex_RealAsDouble(o), PyComplex_ImagAsDouble(o));
35 int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
37 if (val) *val = Constructor(d, 0.0);
41 return SWIG_TypeError;
44 %swig_fromcplx_conv(Type, Real, Imag);
48 %define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
49 %fragment(SWIG_AsVal_frag(Type),"header",
50 fragment=SWIG_AsVal_frag(float)) {
52 SWIG_AsVal(Type)(PyObject *o, Type *val)
54 if (PyComplex_Check(o)) {
55 double re = PyComplex_RealAsDouble(o);
56 double im = PyComplex_ImagAsDouble(o);
57 if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
58 if (val) *val = Constructor(%numeric_cast(re, float),
59 %numeric_cast(im, float));
62 return SWIG_OverflowError;
66 int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
68 if (val) *val = Constructor(re, 0.0);
72 return SWIG_TypeError;
76 %swig_fromcplx_conv(Type, Real, Imag);
79 #define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
80 %swig_cplxflt_conv(Type, Constructor, Real, Imag)
83 #define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
84 %swig_cplxdbl_conv(Type, Constructor, Real, Imag)