PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Lib/python/std_complex.i

#
Swig | 64 lines | 52 code | 12 blank | 0 comment | 0 complexity | 3babacfb43138f3bd6b0b6a5605ddd15 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #ifndef __swig_std_complex_i__
  2. #define __swig_std_complex_i__
  3. #ifdef SWIG
  4. %{
  5. #include <complex>
  6. %}
  7. namespace std
  8. {
  9. template <class T> class complex;
  10. %define specialize_std_complex(T)
  11. %typemap(in) complex<T> {
  12. if (PyComplex_Check($input)) {
  13. $1 = std::complex<T>(PyComplex_RealAsDouble($input),
  14. PyComplex_ImagAsDouble($input));
  15. } else if (PyFloat_Check($input)) {
  16. $1 = std::complex<T>(PyFloat_AsDouble($input), 0);
  17. } else if (PyInt_Check($input)) {
  18. $1 = std::complex<T>(PyInt_AsLong($input), 0);
  19. }
  20. else {
  21. PyErr_SetString(PyExc_TypeError,"Expected a complex");
  22. SWIG_fail;
  23. }
  24. }
  25. %typemap(in) const complex<T>& (std::complex<T> temp) {
  26. if (PyComplex_Check($input)) {
  27. temp = std::complex<T>(PyComplex_RealAsDouble($input),
  28. PyComplex_ImagAsDouble($input));
  29. $1 = &temp;
  30. } else if (PyFloat_Check($input)) {
  31. temp = std::complex<T>(PyFloat_AsDouble($input), 0);
  32. $1 = &temp;
  33. } else if (PyInt_Check($input)) {
  34. temp = std::complex<T>(PyInt_AsLong($input), 0);
  35. $1 = &temp;
  36. } else {
  37. PyErr_SetString(PyExc_TypeError,"Expected a complex");
  38. SWIG_fail;
  39. }
  40. }
  41. %typemap(out) complex<T> {
  42. $result = PyComplex_FromDoubles($1.real(), $1.imag());
  43. }
  44. %typemap(out) const complex<T> & {
  45. $result = PyComplex_FromDoubles($1->real(), $1->imag());
  46. }
  47. %enddef
  48. specialize_std_complex(double);
  49. specialize_std_complex(float);
  50. }
  51. #endif // SWIG
  52. #endif //__swig_std_complex_i__