Complex director typemap fixes (python)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5026 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c3f1a4a180
commit
94e1afc19d
2 changed files with 18 additions and 27 deletions
|
|
@ -67,42 +67,27 @@ SwigComplex_AsComplexDouble(PyObject *o)
|
|||
|
||||
// C++ proxy class typemaps
|
||||
|
||||
%typemap(inv) complex<T> {
|
||||
%typemap(inv) Complex {
|
||||
$input = PyComplex_FromDoubles($1_name.real(), $1_name.imag());
|
||||
}
|
||||
|
||||
%typemap(inv) const complex<T> & {
|
||||
$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<T> {
|
||||
if (PyComplex_Check($input)) {
|
||||
$result = std::complex<T>(PyComplex_RealAsDouble($input),
|
||||
PyComplex_ImagAsDouble($input));
|
||||
} 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) Complex {
|
||||
$result = SwigComplex_As< Complex >($input);
|
||||
if (PyErr_Occurred()) {
|
||||
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(outv) const complex<T>& (std::complex<T> temp) {
|
||||
if (PyComplex_Check($input)) {
|
||||
temp = std::complex<T>(PyComplex_RealAsDouble($input),
|
||||
PyComplex_ImagAsDouble($input));
|
||||
$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");
|
||||
%typemap(outv) const complex<T>& (Complex temp) {
|
||||
temp = SwigComplex_As< Complex >($input);
|
||||
if (PyErr_Occurred()) {
|
||||
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
|
||||
}
|
||||
$result = &temp;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue