diff --git a/CHANGES.current b/CHANGES.current index c3acacee0..53088acf6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,5 +1,11 @@ Version 1.3.20 (In progress) ============================ +08/30/2003: mrose (Mark Rose) + Modified the director typemaps in python/std_complex.i to use the + new-style macro and conversion functions, which eliminated some + redundant code. Fixed a few bugs in these typemaps as well, although + more testing is needed. + 08/29/2003: mrose (Mark Rose) Completed initial support for wrapping abstract classes with directors. Constructor wrappers will be generated for abstract classes that have diff --git a/Lib/python/std_complex.i b/Lib/python/std_complex.i index dc052f2dd..b4e8095e2 100644 --- a/Lib/python/std_complex.i +++ b/Lib/python/std_complex.i @@ -67,42 +67,27 @@ SwigComplex_AsComplexDouble(PyObject *o) // C++ proxy class typemaps - %typemap(inv) complex { + %typemap(inv) Complex { $input = PyComplex_FromDoubles($1_name.real(), $1_name.imag()); } - %typemap(inv) const complex & { - $input = PyComplex_FromDoubles($1_name->real(), $1_name->imag()); + %typemap(inv) const Complex & { + $input = PyComplex_FromDoubles($1_name.real(), $1_name.imag()); } - %typemap(outv) complex { - if (PyComplex_Check($input)) { - $result = std::complex(PyComplex_RealAsDouble($input), - PyComplex_ImagAsDouble($input)); - } else if (PyFloat_Check($input)) { - $result = std::complex(PyFloat_AsDouble($input), 0); - } else if (PyInt_Check($input)) { - $result = std::complex(PyInt_AsLong($input), 0); - } - else { - throw SWIG_DIRECTOR_TYPE_MISMATCH("Expected a complex"); + %typemap(outv) Complex { + $result = SwigComplex_As< Complex >($input); + if (PyErr_Occurred()) { + throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type"); } } - %typemap(outv) const complex& (std::complex temp) { - if (PyComplex_Check($input)) { - temp = std::complex(PyComplex_RealAsDouble($input), - PyComplex_ImagAsDouble($input)); - $result = &temp; - } else if (PyFloat_Check($input)) { - temp = std::complex(PyFloat_AsDouble($input), 0); - $result = &temp; - } else if (PyInt_Check($input)) { - temp = std::complex(PyInt_AsLong($input), 0); - $result = &temp; - } else { - throw SWIG_DIRECTOR_TYPE_MISMATCH("Expected a complex"); + %typemap(outv) const complex& (Complex temp) { + temp = SwigComplex_As< Complex >($input); + if (PyErr_Occurred()) { + throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type"); } + $result = &temp; }