Scilab: add support of STL vector<string>
This commit is contained in:
parent
8ca085b528
commit
8ee91b4352
2 changed files with 54 additions and 41 deletions
|
|
@ -1,26 +1,25 @@
|
||||||
/*
|
/*
|
||||||
* C++ type: std::vector<string>
|
* C++ type: std::vector<std::string>
|
||||||
* Scilab 5 type: double matrix
|
* Scilab 5 type: string matrix
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%include <scidouble.swg>
|
%include <scichar.swg>
|
||||||
|
|
||||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>(std::vector<string> temp)
|
%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector<std::string>(std::vector<std::string> temp)
|
||||||
{
|
{
|
||||||
double* dmatrix;
|
char** charArray;
|
||||||
int nbRows;
|
int charArraySize;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname);
|
||||||
|
if (ret == SWIG_OK)
|
||||||
|
{
|
||||||
$1 = temp;
|
$1 = temp;
|
||||||
$1.reserve(nbRows * nbCols);
|
$1.reserve(charArraySize);
|
||||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector<string>&)$1));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -28,22 +27,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>&(std::vector<string> temp)
|
%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector<std::string>&(std::vector<std::string> temp)
|
||||||
{
|
{
|
||||||
double* dmatrix;
|
char** charArray;
|
||||||
int nbRows;
|
int charArraySize;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname);
|
||||||
|
if (ret == SWIG_OK)
|
||||||
|
{
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
$1->reserve(nbRows * nbCols);
|
$1->reserve(charArraySize);
|
||||||
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1));
|
std::copy(charArray, charArray + charArraySize, std::back_inserter(*$1));
|
||||||
|
|
||||||
|
for (int i=0; i<charArraySize; i++)
|
||||||
|
free(charArray[i]);
|
||||||
|
free(charArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -51,14 +49,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>
|
%typemap(out, fragment="SwigScilabStringFromCharPtrArray") std::vector<std::string>
|
||||||
{
|
{
|
||||||
int nbCols = $1.size();
|
int pCharArraySize = $1.size();
|
||||||
double* dmatrix = new double[nbCols];
|
char** pCharArray = new char*[pCharArraySize];
|
||||||
std::copy($1.begin(), $1.end(), dmatrix);
|
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 = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize);
|
||||||
delete[] dmatrix;
|
delete[] pCharArray;
|
||||||
|
|
||||||
if (ret != SWIG_ERROR)
|
if (ret != SWIG_ERROR)
|
||||||
{
|
{
|
||||||
|
|
@ -70,14 +75,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>&
|
%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") std::vector<std::string>&
|
||||||
{
|
{
|
||||||
int nbCols = $1->size();
|
int pCharArraySize = $1->size();
|
||||||
double* dmatrix = new double[nbCols];
|
char** pCharArray = new char*[pCharArraySize];
|
||||||
std::copy($1->begin(), $1->end(), dmatrix);
|
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 = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
|
int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize);
|
||||||
delete[] dmatrix;
|
delete[] pCharArray;
|
||||||
|
|
||||||
if (ret != SWIG_ERROR)
|
if (ret != SWIG_ERROR)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
%include <scivectordouble.swg>
|
%include <scivectordouble.swg>
|
||||||
%include <scivectorint.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