Scilab: generic support for STL vector
This commit is contained in:
parent
cdb6554fba
commit
983af237b0
4 changed files with 6 additions and 301 deletions
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* 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> &INOUT
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
* 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> &INOUT
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* C++ type: std::vector<std::string>
|
|
||||||
* Scilab 5 type: string matrix
|
|
||||||
*/
|
|
||||||
|
|
||||||
%include <scichar.swg>
|
|
||||||
|
|
||||||
%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector<std::string> (std::vector<std::string> temp)
|
|
||||||
{
|
|
||||||
char** charArray;
|
|
||||||
int charArraySize;
|
|
||||||
|
|
||||||
int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname);
|
|
||||||
if (ret == SWIG_OK)
|
|
||||||
{
|
|
||||||
$1 = temp;
|
|
||||||
$1.reserve(charArraySize);
|
|
||||||
std::copy(charArray, charArray + charArraySize, std::back_inserter((std::vector<std::string>&)$1));
|
|
||||||
|
|
||||||
for (int i=0; i<charArraySize; i++)
|
|
||||||
free(charArray[i]);
|
|
||||||
free(charArray);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SWIG_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector<std::string>& (std::vector<std::string> temp)
|
|
||||||
{
|
|
||||||
char** charArray;
|
|
||||||
int charArraySize;
|
|
||||||
|
|
||||||
int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname);
|
|
||||||
if (ret == SWIG_OK)
|
|
||||||
{
|
|
||||||
$1 = &temp;
|
|
||||||
$1->reserve(charArraySize);
|
|
||||||
std::copy(charArray, charArray + charArraySize, std::back_inserter(*$1));
|
|
||||||
|
|
||||||
for (int i=0; i<charArraySize; i++)
|
|
||||||
free(charArray[i]);
|
|
||||||
free(charArray);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SWIG_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(out, fragment="SwigScilabStringFromCharPtrArray") std::vector<std::string>
|
|
||||||
{
|
|
||||||
int pCharArraySize = $1.size();
|
|
||||||
char** pCharArray = new char*[pCharArraySize];
|
|
||||||
char** p = pCharArray;
|
|
||||||
for (std::vector<std::string>::iterator it = $1.begin(); it != $1.end(); it++)
|
|
||||||
{
|
|
||||||
char* pChar = new char(it->size()+1);
|
|
||||||
strcpy(pChar, it->c_str());
|
|
||||||
*p = pChar;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize);
|
|
||||||
delete[] pCharArray;
|
|
||||||
|
|
||||||
if (ret != SWIG_ERROR)
|
|
||||||
{
|
|
||||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SWIG_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") std::vector<std::string> &INOUT
|
|
||||||
{
|
|
||||||
int pCharArraySize = $1->size();
|
|
||||||
char** pCharArray = new char*[pCharArraySize];
|
|
||||||
char** p = pCharArray;
|
|
||||||
for (std::vector<std::string>::iterator it = $1->begin(); it != $1->end(); it++)
|
|
||||||
{
|
|
||||||
char* pChar = new char(it->size()+1);
|
|
||||||
strcpy(pChar, it->c_str());
|
|
||||||
*p = pChar;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize);
|
|
||||||
delete[] pCharArray;
|
|
||||||
|
|
||||||
if (ret != SWIG_ERROR)
|
|
||||||
{
|
|
||||||
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SWIG_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
/*
|
/*
|
||||||
Vectors
|
*
|
||||||
|
* C++ type : STL vector
|
||||||
|
* Scilab type : matrix (for vectors of primitive types) or list (for sets of all other types : pointers...)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
|
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
|
||||||
%{
|
%{
|
||||||
namespace swig {
|
namespace swig {
|
||||||
|
|
@ -14,7 +18,7 @@
|
||||||
template <class T>
|
template <class T>
|
||||||
struct traits_from<std::vector<T> > {
|
struct traits_from<std::vector<T> > {
|
||||||
static SciObject from(const std::vector<T>& vec) {
|
static SciObject from(const std::vector<T>& vec) {
|
||||||
return traits_from_stdseq<std::vector<T> >::from(vec);
|
return traits_from_stdseq<std::vector<T> >::from(vec);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -24,10 +28,5 @@
|
||||||
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
|
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
|
||||||
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
|
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
|
||||||
|
|
||||||
|
|
||||||
%include <scivectordouble.swg>
|
|
||||||
%include <scivectorint.swg>
|
|
||||||
%include <scivectorstring.swg>
|
|
||||||
|
|
||||||
%include <std/std_vector.i>
|
%include <std/std_vector.i>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue