aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/complex_conversions.h
blob: 0e5e2cfaf681dc23472cde027dff9ae22999b466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace Shiboken {
template<>
struct Converter<Complex>
{
    static inline bool checkType(PyObject* pyObj)
    {
        return PyComplex_Check(pyObj);
    }

    static inline bool isConvertible(PyObject* pyObj)
    {
        return PyComplex_Check(pyObj);
    }

    static inline PyObject* toPython(void* cppobj)
    {
        return toPython(*reinterpret_cast<Complex*>(cppobj));
    }

    static inline PyObject* toPython(const Complex& cpx)
    {
        return PyComplex_FromDoubles(cpx.real(), cpx.imag());
    }

    static inline Complex toCpp(PyObject* pyobj)
    {
        double real =  PyComplex_RealAsDouble(pyobj);
        double imag =  PyComplex_ImagAsDouble(pyobj);
        return Complex(real, imag);
    }
};
}