PageRenderTime 33ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 4ms 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
 4#ifdef SWIG
 5
 6%{
 7#include <complex>
 8%} 
 9
10namespace std 
11{
12  template <class T> class complex;  
13  
14  %define specialize_std_complex(T)
15  
16  %typemap(in) complex<T> {
17    if (PyComplex_Check($input)) {
18      $1 = std::complex<T>(PyComplex_RealAsDouble($input),
19			   PyComplex_ImagAsDouble($input));
20    } else if (PyFloat_Check($input)) {
21      $1 = std::complex<T>(PyFloat_AsDouble($input), 0);
22    } else if (PyInt_Check($input)) {
23      $1 = std::complex<T>(PyInt_AsLong($input), 0);
24    }
25    else {
26      PyErr_SetString(PyExc_TypeError,"Expected a complex");
27      SWIG_fail;
28    }
29  }  
30  
31  %typemap(in) const complex<T>& (std::complex<T> temp) {
32    if (PyComplex_Check($input)) {
33      temp = std::complex<T>(PyComplex_RealAsDouble($input),
34			     PyComplex_ImagAsDouble($input));
35      $1 = &temp;
36    } else if (PyFloat_Check($input)) {
37      temp = std::complex<T>(PyFloat_AsDouble($input), 0);
38      $1 = &temp;
39    } else if (PyInt_Check($input)) {
40      temp = std::complex<T>(PyInt_AsLong($input), 0);
41      $1 = &temp;
42    } else {	
43      PyErr_SetString(PyExc_TypeError,"Expected a complex");
44      SWIG_fail;
45    }
46  }
47  
48  %typemap(out) complex<T> {
49    $result = PyComplex_FromDoubles($1.real(), $1.imag());
50  }
51  
52  %typemap(out) const complex<T> & {
53    $result = PyComplex_FromDoubles($1->real(), $1->imag());
54  }
55
56  %enddef  
57     
58  specialize_std_complex(double);
59  specialize_std_complex(float);
60}
61  
62#endif // SWIG
63
64#endif //__swig_std_complex_i__