// -*- C++ -*- #ifndef SWIG_STD_COMPLEX_I_ #define SWIG_STD_COMPLEX_I_ #ifdef SWIG %{ #include %} namespace std { template class complex; %define specialize_std_complex(T) %typemap(in) complex { if (PyComplex_Check($input)) { $1 = std::complex(PyComplex_RealAsDouble($input), PyComplex_ImagAsDouble($input)); } else if (PyFloat_Check($input)) { $1 = std::complex(PyFloat_AsDouble($input), 0); } else if (PyInt_Check($input)) { $1 = std::complex(PyInt_AsLong($input), 0); } else { PyErr_SetString(PyExc_TypeError,"Expected a complex"); SWIG_fail; } } %typemap(in) const complex& (std::complex temp) { if (PyComplex_Check($input)) { temp = std::complex(PyComplex_RealAsDouble($input), PyComplex_ImagAsDouble($input)); $1 = &temp; } else if (PyFloat_Check($input)) { temp = std::complex(PyFloat_AsDouble($input), 0); $1 = &temp; } else if (PyInt_Check($input)) { temp = std::complex(PyInt_AsLong($input), 0); $1 = &temp; } else { PyErr_SetString(PyExc_TypeError,"Expected a complex"); SWIG_fail; } } %typemap(out) complex { $result = PyComplex_FromDoubles($1.real(), $1.imag()); } %typemap(out) const complex & { $result = PyComplex_FromDoubles($1->real(), $1->imag()); } %enddef specialize_std_complex(double); specialize_std_complex(float); } #endif // SWIG #endif //SWIG_STD_COMPLEX_I_