From: david r. m. <dav...@gm...> - 2007-06-20 09:44:14
|
Hi Nitro. I have a new problem in my code swig. I have a function in C++ and have values complex ( complex<double> * ) complex is a class of C++ (include<complex>). When I create my wrapper I have a problem overload function My cuestion is:Is possible solve my problem? I create a Typemap but doesn't solve anything Is possible that I call the function from python, i call bad? example: /**********************my swigexample .h*******************************/ using namespace std; #include <iostream> #include <fstream> #include <complex> #include <cstdlib> #include <cstdio> #include <string> void RealImag2Complex(const int _real, const int _imag, complex< double >* _complex, int length) { int aux_real = (int) _real; int aux_imag = (int) _imag; std::cout<<*_complex<<std::endl; } /*****************my swigexample .i*************************/ %module swigexample %include cpointer.i %include std_complex.i %pointer_class(double,doubleP); %{ #include "swigexample.h" #include <complex> %} %typemap(python,in) complex <double> * { if (!PyList_Check($input)) { PyErr_SetString(PyExc_TypeError, "expected a list"); return NULL; }; int arrsize = PyList_Size($input); $1 = new complex <double> [arrsize]; for (int i=0; i<arrsize; i++) { PyObject *item = PyList_GetItem($input, i); if (PyComplex_Check(item)) $1[i] = complex <double>(PyComplex_RealAsDouble(item), PyComplex_ImagAsDouble(item)); else { free ((complex <double> *) $input); PyErr_SetString(PyExc_TypeError, "expected complex numbers in list"); return NULL; }; } } %typemap (python,freearg) complex <double> * { delete [] $1; }; %typemap (python,out) complex<double> *{ $result = PyInt_FromLong($1); } %include "swigexample.h" Please I need to konw the solution for the excepted a pointer >>> z=complex(1+1j) >>> swigfuncs.RealImag2Complex(2,2,z,3) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: No matching function for overloaded 'RealImag2Complex' It is possible to solve it or if you have a other solution, I accept all solutions. Thanks for your time and sorry for my English |