PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/ocaml/std_complex.i

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