Fix STL vector typemaps (supports vector<int> and vector<double>)
This commit is contained in:
parent
a9f366b142
commit
c61f9b233d
5 changed files with 282 additions and 124 deletions
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
Vectors typemaps
|
||||
*/
|
||||
|
||||
// Typemap for input arguments of type const std::vector<double> &
|
||||
%typecheck(SWIG_TYPECHECK_POINTER)
|
||||
const std::vector<double> &
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
%typemap(in)
|
||||
const std::vector<double> &
|
||||
(int is_new_object=0, std::vector<double> arrayv)
|
||||
{
|
||||
{
|
||||
SciErr sciErr;
|
||||
int iRows = 0;
|
||||
int iCols = 0;
|
||||
int *piAddrVar = NULL;
|
||||
double *pdblTmp = NULL;
|
||||
|
||||
/* Scilab value must be a double vector */
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) {
|
||||
sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
} else {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if ((iRows!=1) && (iCols!=1)) {
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
/* Copy vector contents into new allocated std::vector<double> */
|
||||
arrayv = std::vector<double>(iRows*iCols);
|
||||
$1 = &arrayv;
|
||||
{
|
||||
int arr_i = 0;
|
||||
for (arr_i = 0; arr_i < iRows*iCols; ++arr_i)
|
||||
arrayv[arr_i] = pdblTmp[arr_i];
|
||||
}
|
||||
}
|
||||
}
|
||||
%typemap(freearg)
|
||||
const std::vector<double> &
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Typemap for return values of type std::vector<double>
|
||||
%typemap(out) std::vector<double>
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
94
Lib/scilab/scivectordouble.swg
Normal file
94
Lib/scilab/scivectordouble.swg
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* C++ type: std::vector<double>
|
||||
* Scilab 5 type: double matrix
|
||||
*/
|
||||
|
||||
%include <scidouble.swg>
|
||||
|
||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<double>(std::vector<double> temp)
|
||||
{
|
||||
double* dmatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = temp;
|
||||
$1.reserve(nbRows * nbCols);
|
||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector<double>&)$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<double>&(std::vector<double> temp)
|
||||
{
|
||||
double* dmatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = &temp;
|
||||
$1->reserve(nbRows * nbCols);
|
||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<double>
|
||||
{
|
||||
int nbCols = $1.size();
|
||||
double* dmatrix = new double[nbCols];
|
||||
std::copy($1.begin(), $1.end(), dmatrix);
|
||||
|
||||
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
||||
delete[] dmatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<double>&
|
||||
{
|
||||
int nbCols = $1->size();
|
||||
double* dmatrix = new double[nbCols];
|
||||
std::copy($1->begin(), $1->end(), dmatrix);
|
||||
|
||||
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
||||
delete[] dmatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
91
Lib/scilab/scivectorint.swg
Normal file
91
Lib/scilab/scivectorint.swg
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* C++ type: std::vector<int>
|
||||
* Scilab 5 type: integer matrix
|
||||
*/
|
||||
|
||||
%include <sciint.swg>
|
||||
|
||||
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector<int>(std::vector<int> temp)
|
||||
{
|
||||
int* imatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = temp;
|
||||
$1.reserve(nbRows * nbCols);
|
||||
std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter((std::vector<int>&)$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector<int>&(std::vector<int> temp)
|
||||
{
|
||||
int* imatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = &temp;
|
||||
$1->reserve(nbRows * nbCols);
|
||||
std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter(*$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector<int>
|
||||
{
|
||||
int nbCols = $1.size();
|
||||
int* imatrix = new int[nbCols];
|
||||
std::copy($1.begin(), $1.end(), imatrix);
|
||||
|
||||
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
|
||||
delete[] imatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector<int>&
|
||||
{
|
||||
int nbCols = $1->size();
|
||||
int* imatrix = new int[nbCols];
|
||||
std::copy($1->begin(), $1->end(), imatrix);
|
||||
|
||||
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
|
||||
delete[] imatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
94
Lib/scilab/scivectorstring.swg
Normal file
94
Lib/scilab/scivectorstring.swg
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* C++ type: std::vector<string>
|
||||
* Scilab 5 type: double matrix
|
||||
*/
|
||||
|
||||
%include <scidouble.swg>
|
||||
|
||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>(std::vector<string> temp)
|
||||
{
|
||||
double* dmatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = temp;
|
||||
$1.reserve(nbRows * nbCols);
|
||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector<string>&)$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>&(std::vector<string> temp)
|
||||
{
|
||||
double* dmatrix;
|
||||
int nbRows;
|
||||
int nbCols;
|
||||
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
|
||||
{
|
||||
if ((nbRows > 1) && (nbCols > 1))
|
||||
{
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
$1 = &temp;
|
||||
$1->reserve(nbRows * nbCols);
|
||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>
|
||||
{
|
||||
int nbCols = $1.size();
|
||||
double* dmatrix = new double[nbCols];
|
||||
std::copy($1.begin(), $1.end(), dmatrix);
|
||||
|
||||
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
||||
delete[] dmatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>&
|
||||
{
|
||||
int nbCols = $1->size();
|
||||
double* dmatrix = new double[nbCols];
|
||||
std::copy($1->begin(), $1->end(), dmatrix);
|
||||
|
||||
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
||||
delete[] dmatrix;
|
||||
|
||||
if (ret != SWIG_ERROR)
|
||||
{
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::vector<T> > {
|
||||
static SciObject *from(const std::vector<T>& vec) {
|
||||
|
|
@ -23,66 +23,9 @@
|
|||
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
|
||||
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
|
||||
|
||||
// Typemap for input arguments of type const std::vector<double> &
|
||||
%typecheck(SWIG_TYPECHECK_POINTER)
|
||||
const std::vector<double> &
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
%typemap(in)
|
||||
const std::vector<double> &
|
||||
(int is_new_object=0, std::vector<double> arrayv)
|
||||
{
|
||||
{
|
||||
SciErr sciErr;
|
||||
int iRows = 0;
|
||||
int iCols = 0;
|
||||
int *piAddrVar = NULL;
|
||||
double *pdblTmp = NULL;
|
||||
|
||||
/* Scilab value must be a double vector */
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) {
|
||||
sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
} else {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if ((iRows!=1) && (iCols!=1)) {
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
/* Copy vector contents into new allocated std::vector<double> */
|
||||
arrayv = std::vector<double>(iRows*iCols);
|
||||
$1 = &arrayv;
|
||||
{
|
||||
int arr_i = 0;
|
||||
for (arr_i = 0; arr_i < iRows*iCols; ++arr_i)
|
||||
arrayv[arr_i] = pdblTmp[arr_i];
|
||||
}
|
||||
}
|
||||
}
|
||||
%typemap(freearg)
|
||||
const std::vector<double> &
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Typemap for return values of type std::vector<double>
|
||||
%typemap(out) std::vector<double>
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
%include <scivectordouble.swg>
|
||||
%include <scivectorint.swg>
|
||||
|
||||
%include <std/std_vector.i>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue