Complex director typemap fixes (python)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5026 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Rose 2003-08-30 08:08:43 +00:00
commit c14abb83fe
2 changed files with 18 additions and 27 deletions

View file

@ -1,5 +1,11 @@
Version 1.3.20 (In progress) 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) 08/29/2003: mrose (Mark Rose)
Completed initial support for wrapping abstract classes with directors. Completed initial support for wrapping abstract classes with directors.
Constructor wrappers will be generated for abstract classes that have Constructor wrappers will be generated for abstract classes that have

View file

@ -67,42 +67,27 @@ SwigComplex_AsComplexDouble(PyObject *o)
// C++ proxy class typemaps // C++ proxy class typemaps
%typemap(inv) complex<T> { %typemap(inv) Complex {
$input = PyComplex_FromDoubles($1_name.real(), $1_name.imag()); $input = PyComplex_FromDoubles($1_name.real(), $1_name.imag());
} }
%typemap(inv) const complex<T> & { %typemap(inv) const Complex & {
$input = PyComplex_FromDoubles($1_name->real(), $1_name->imag()); $input = PyComplex_FromDoubles($1_name.real(), $1_name.imag());
} }
%typemap(outv) complex<T> { %typemap(outv) Complex {
if (PyComplex_Check($input)) { $result = SwigComplex_As< Complex >($input);
$result = std::complex<T>(PyComplex_RealAsDouble($input), if (PyErr_Occurred()) {
PyComplex_ImagAsDouble($input)); throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
} else if (PyFloat_Check($input)) {
$result = std::complex<T>(PyFloat_AsDouble($input), 0);
} else if (PyInt_Check($input)) {
$result = std::complex<T>(PyInt_AsLong($input), 0);
}
else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expected a complex");
} }
} }
%typemap(outv) const complex<T>& (std::complex<T> temp) { %typemap(outv) const complex<T>& (Complex temp) {
if (PyComplex_Check($input)) { temp = SwigComplex_As< Complex >($input);
temp = std::complex<T>(PyComplex_RealAsDouble($input), if (PyErr_Occurred()) {
PyComplex_ImagAsDouble($input)); throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
$result = &temp;
} else if (PyFloat_Check($input)) {
temp = std::complex<T>(PyFloat_AsDouble($input), 0);
$result = &temp;
} else if (PyInt_Check($input)) {
temp = std::complex<T>(PyInt_AsLong($input), 0);
$result = &temp;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expected a complex");
} }
$result = &temp;
} }