2 Defines the As/From conversors for double/float complex, you need to
3 provide complex Type, the Name you want to use in the conversors,
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 conversor */
11 %define %swig_fromcplx_conv(Type, Real, Imag)
12 %fragment(SWIG_From_frag(Type),"header")
14 SWIGINTERNINLINE octave_value
15 SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
17 return octave_value(Complex(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) (const octave_value& ov, Type* val)
30 if (ov.is_complex_scalar()) {
32 Complex c(ov.complex_value());
33 *val=Constructor(c.real(),c.imag());
38 int res = SWIG_AddCast(SWIG_AsVal(double)(ov, &d));
41 *val = Constructor(d, 0.0);
45 return SWIG_TypeError;
48 %swig_fromcplx_conv(Type, Real, Imag);
52 %define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
53 %fragment(SWIG_AsVal_frag(Type),"header",
54 fragment=SWIG_AsVal_frag(float)) {
56 SWIG_AsVal(Type)(PyObject *o, Type *val)
58 if (ov.is_complex_scalar()) {
60 Complex c(ov.complex_value());
63 if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
65 *val = Constructor(%numeric_cast(re, float),
66 %numeric_cast(im, float));
69 return SWIG_OverflowError;
73 int res = SWIG_AddCast(SWIG_AsVal(float)(ov, &d));
76 *val = Constructor(d, 0.0);
80 return SWIG_TypeError;
84 %swig_fromcplx_conv(Type, Real, Imag);
87 #define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
88 %swig_cplxflt_conv(Type, Constructor, Real, Imag)
91 #define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
92 %swig_cplxdbl_conv(Type, Constructor, Real, Imag)