swig/Lib/python/complex_common.i
Marcelo Matus 68024b15ce Reducing pyrun.swg and splitting python.swg into different files
for clarity and for easier maintainance.

pyrun.swg almost the same than 1.3.20, therefore there will be
compatible again.

code generated is reduced by the use and reuse of %fragments.

as usual, all the test-suite is compiling and a much bigger
"test project" too.

with the new typemaps definition should be much eaiser and
uniform add stl/std and user types.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5706 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2004-02-10 09:50:24 +00:00

73 lines
1.7 KiB
OpenEdge ABL

#ifndef __python_complex_common_i__
#define __python_complex_common_i__
/*
Defines the As/From conversors for double/float complex, you need to
provide complex Type, the Name you want to use in the conversors,
the complex Constructor method, and the Real and Imag complex
accesor methods.
See the std_complex.i and ccomplex.i for concret examples.
*/
/* the common from conversor */
%define %swig_fromcplx_conv(Type, Name, Real, Imag)
%fragment("SWIG_From"#Name,"header")
%{
SWIGSTATIC(PyObject*)
SWIG_From##Name(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")
%{
SWIGSTATIC(Type)
SWIG_As##Name(PyObject *o)
{
Type c = PyComplex_Check(o) ?
Constructor(PyComplex_RealAsDouble(o),
PyComplex_ImagAsDouble(o)) :
Constructor(SWIG_AsDouble(o), 0);
if (PyErr_Occurred()){
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "a Type is expected");
}
return c;
}
%}
%swig_fromcplx_conv(Type, Name, 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")
%{
SWIGSTATIC(Type)
SWIG_As##Name(PyObject *o)
{
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();
PyErr_SetString(PyExc_TypeError, "a Type is expected");
}
return c;
}
%}
%swig_fromcplx_conv(Type, Name, Real, Imag);
%enddef
#endif //__python_complex_common_i__