Change the wrapping to marshall directly to the .net System.Numerics.Complex type instead of using an intermediate std::complex .net type.
77 lines
2.1 KiB
OpenEdge ABL
77 lines
2.1 KiB
OpenEdge ABL
%{
|
|
#include <complex>
|
|
%}
|
|
|
|
%fragment("SwigSystemNumericsComplex", "header") {
|
|
// Identical to the layout of System.Numerics.Complex, but does assume that it is
|
|
// LayoutKind.Sequential on the managed side
|
|
struct SwigSystemNumericsComplex {
|
|
double real;
|
|
double imag;
|
|
SwigSystemNumericsComplex(double r = 0.0, double i = 0.0) : real(r), imag(i) {}
|
|
};
|
|
}
|
|
|
|
namespace std {
|
|
|
|
%naturalvar complex;
|
|
|
|
template<typename T>
|
|
class complex
|
|
{
|
|
public:
|
|
complex(T re = T(), T im = T());
|
|
};
|
|
|
|
}
|
|
|
|
%define swig_complex_typemaps(T)
|
|
%typemap(ctype, fragment="SwigSystemNumericsComplex") std::complex<T>, const std::complex<T> & "SwigSystemNumericsComplex"
|
|
%typemap(imtype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
|
|
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
|
|
|
|
%typemap(in) std::complex<T>($*1_ltype temp), const std::complex<T> &($*1_ltype temp)
|
|
%{temp = std::complex< double >($input.real, $input.imag);
|
|
$1 = &temp;%}
|
|
|
|
%typemap(out) std::complex<T>
|
|
%{$result = SwigSystemNumericsComplex($1.real(), $1.imag());%}
|
|
|
|
%typemap(out) const std::complex<T> &
|
|
%{$result = SwigSystemNumericsComplex($1->real(), $1->imag());%}
|
|
|
|
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
|
|
|
|
%typemap(csin) std::complex<T>, const std::complex<T> & "$csinput"
|
|
|
|
%typemap(csout, excode=SWIGEXCODE) std::complex<T>, const std::complex<T> & {
|
|
System.Numerics.Complex ret = $imcall;$excode
|
|
return ret;
|
|
}
|
|
|
|
%typemap(csvarin, excode=SWIGEXCODE2) const std::complex<T> & %{
|
|
set {
|
|
$imcall;$excode
|
|
}
|
|
%}
|
|
|
|
%typemap(csvarout, excode=SWIGEXCODE2) const std::complex<T> & %{
|
|
get {
|
|
System.Numerics.Complex ret = $imcall;$excode
|
|
return ret;
|
|
}
|
|
%}
|
|
|
|
%template() std::complex<T>;
|
|
%enddef
|
|
|
|
// By default, typemaps for both std::complex<double> and std::complex<float>
|
|
// are defined, but one of them can be disabled by predefining the
|
|
// corresponding symbol before including this file.
|
|
#ifndef SWIG_NO_STD_COMPLEX_DOUBLE
|
|
swig_complex_typemaps(double)
|
|
#endif
|
|
|
|
#ifndef SWIG_NO_STD_COMPLEX_FLOAT
|
|
swig_complex_typemaps(float)
|
|
#endif
|