From eddbb8f59e3e7190b9787476baca208b71478344 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 19 Jun 2013 09:35:42 +0200 Subject: [PATCH 01/41] Scilab: SWIG exception raise macro : rethrow exceptions --- Lib/scilab/sciruntime.swg | 13 +++++++++++-- Lib/scilab/scitypemaps.swg | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index 956a8094a..9b9d9b3d2 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -69,7 +69,7 @@ SWIG_Scilab_ErrorMsg(int code, const char *mesg) #define SWIG_fail return SWIG_ERROR; -#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code) +#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code) #define SWIG_Error(code, msg) SWIG_Scilab_ErrorMsg(code,msg) /* Used for C++ enums */ @@ -218,7 +218,16 @@ SWIG_Scilab_SetOutput(void *_pvApiCtx, SciObject _output) { return SWIG_OK; } -#define SwigScilabRaise(OBJ, TYPE, DESC) Scierror(999, "C++ side threw an exception of type %s.\n", TYPE) +#define SWIG_Scilab_Raise(obj, type, desc) SwigScilabRaise(type) + +SWIGRUNTIME int +SwigScilabRaise(const char *type) { + Scierror(999, "An exception of type %s has been thrown.\n", type); +#ifdef __cplusplus + throw; +#endif +} + %} //%insert(init) "swiginit.swg" diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index 537bb43d5..657717cda 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -12,7 +12,7 @@ #define %append_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR // Name is managed by the the function name -#define %raise(obj, type, desc) SwigScilabRaise(obj, type, desc) +#define %raise(obj, type, desc) SWIG_Scilab_Raise(obj, type, desc) #define %set_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_varoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_argoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR From e42055dcc4788ffb5ae18d4b7105568159a66234 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 18 Jun 2013 12:20:18 +0200 Subject: [PATCH 02/41] Scilab: fix SWIG_NewPointerObj & SWIG_NewFunctionPtrObj error --- Lib/scilab/scipointer.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/scilab/scipointer.swg b/Lib/scilab/scipointer.swg index 3a50e6f31..a80dbcd1c 100644 --- a/Lib/scilab/scipointer.swg +++ b/Lib/scilab/scipointer.swg @@ -6,7 +6,7 @@ } %fragment("SWIG_NewPointerObj", "header") { -#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, $result, pointer, pointerDescriptor, flags) +#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, flags) } /* @@ -17,7 +17,7 @@ } %fragment("SWIG_NewFunctionPtrObj", "header") { -#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, $result, pointer, pointerDescriptor, 0) +#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, 0) } // No fragment used here, the functions "SwigScilabPtrToObject" and "SwigScilabPtrFromObject" are defined in sciruntime.swg From f268b0564ab10ee72f82271e2aaa58b392b830bb Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 18 Jun 2013 12:32:52 +0200 Subject: [PATCH 03/41] Scilab: remove SwigScilabStringFromCharPtrAndSize (same as SwigScilabStringFromCharPtr) --- Lib/scilab/scichar.swg | 29 +++++++---------------------- Lib/scilab/std_string.i | 4 ++-- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index cfc3e353a..f43c71198 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -2,6 +2,10 @@ * C-type: char * Scilab type: string */ + +/* + * CHAR +*/ %fragment(SWIG_AsVal_frag(char), "header", fragment="SwigScilabStringToChar") { #define SWIG_AsVal_char(scilabValue, valuePointer) SwigScilabStringToChar(pvApiCtx, scilabValue, valuePointer, fname) } @@ -86,9 +90,10 @@ SwigScilabStringFromChar(void *_pvApiCtx, int _iVarOut, char _chValue) { %fragment("SWIG_FromCharPtr", "header", fragment = "SwigScilabStringFromCharPtr") { #define SWIG_FromCharPtr(charPtr) SwigScilabStringFromCharPtr(pvApiCtx, $result, charPtr) } -%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SwigScilabStringFromCharPtrAndSize") { -#define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SwigScilabStringFromCharPtrAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) +%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SwigScilabStringFromCharPtr") { +#define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) } + %fragment("SwigScilabStringToCharPtr", "header") { SWIGINTERN int SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLength, char *_fname) { @@ -220,23 +225,3 @@ SwigScilabStringFromCharPtr(void *_pvApiCtx, int _iVarOut, const char *_pchValue return Rhs + _iVarOut; } } -%fragment("SwigScilabStringFromCharPtrAndSize", "header") { -SWIGINTERN int -SwigScilabStringFromCharPtrAndSize(void *_pvApiCtx, int _iVarOut, const char *_pchValue) { - SciErr sciErr; - char **pstData = NULL; - - pstData = (char **)malloc(sizeof(char *)); - pstData[0] = strdup(_pchValue); - - sciErr = createMatrixOfString(_pvApiCtx, Rhs + _iVarOut, 1, 1, (char **)pstData); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - free(pstData[0]); - - return Rhs + _iVarOut; -} -} diff --git a/Lib/scilab/std_string.i b/Lib/scilab/std_string.i index 3a0106a70..7a20d5afa 100644 --- a/Lib/scilab/std_string.i +++ b/Lib/scilab/std_string.i @@ -29,10 +29,10 @@ SWIG_AsPtr_dec(std::string)(int _iVar, std::string **_pstValue) { } } -%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromCharPtrAndSize") { +%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromCharPtr") { SWIGINTERN int SWIG_From_dec(std::string)(std::string _pstValue) { - return SwigScilabStringFromCharPtrAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str()); + return SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str()); } } From 6280dd2d1a8ff7946d6240440a301ee579e01fb0 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 18 Jun 2013 12:33:46 +0200 Subject: [PATCH 04/41] Scilab: fix SWIG_FromCharPtr error --- Lib/scilab/scichar.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index f43c71198..9901359be 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -88,7 +88,7 @@ SwigScilabStringFromChar(void *_pvApiCtx, int _iVarOut, char _chValue) { #define SWIG_AsCharPtrAndSize(scilabValue, charPtrPointer, charPtrLength, allocMemory) SwigScilabStringToCharPtrAndSize(pvApiCtx, scilabValue, charPtrPointer, charPtrLength, allocMemory, fname) } %fragment("SWIG_FromCharPtr", "header", fragment = "SwigScilabStringFromCharPtr") { -#define SWIG_FromCharPtr(charPtr) SwigScilabStringFromCharPtr(pvApiCtx, $result, charPtr) +#define SWIG_FromCharPtr(charPtr) SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) } %fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SwigScilabStringFromCharPtr") { #define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) From 1efaa1ae676eb56276dc784517187d5c56c187bc Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 18 Jun 2013 16:40:12 +0200 Subject: [PATCH 05/41] Scilab: refactor SwigScilabStringToCharPtr (use String API getAllocatedString()) --- Lib/scilab/scichar.swg | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index 9901359be..d1269366a 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -98,49 +98,23 @@ SwigScilabStringFromChar(void *_pvApiCtx, int _iVarOut, char _chValue) { SWIGINTERN int SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLength, char *_fname) { SciErr sciErr; - int iRows = 0; - int iCols = 0; - int iType = 0; int *piAddrVar = NULL; - char *pstStrings = NULL; - int piLength = 0; + int iRet; - sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - sciErr = getVarType(pvApiCtx, piAddrVar, &iType); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iType != sci_strings) { - Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), _fname, _iVar); + if (_pcValue == NULL) { return SWIG_ERROR; } - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, NULL); - if (sciErr.iErr) { - printError(&sciErr, 0); + iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &_pcValue); + if (iRet) { return SWIG_ERROR; } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - - pstStrings = (char *)malloc(sizeof(char) * (piLength + 1)); - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&pstStrings); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - strcpy(_pcValue, pstStrings); - - free(pstStrings); return SWIG_OK; } From 347dee5cda1a46021785e57ff4cc1cb8f07ef1d8 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 18 Jun 2013 16:43:16 +0200 Subject: [PATCH 06/41] Scilab: refactor SwigScilabStringToCharPtrAndSize (use String API getAllocatedString) --- Lib/scilab/scichar.swg | 46 ++++++++++-------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index d1269366a..4b84c21fd 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -123,57 +123,33 @@ SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLeng SWIGINTERN int SwigScilabStringToCharPtrAndSize(void *_pvApiCtx, int _iVar, char **_pcValue, size_t *_piLength, int *alloc, char *_fname) { SciErr sciErr; - int iRows = 0; - int iCols = 0; - int iType = 0; int *piAddrVar = NULL; - char *_pstStrings = NULL; - int piLength = 0; + int iRet; + char *pstStrings = NULL; - sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - sciErr = getVarType(pvApiCtx, piAddrVar, &iType); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iType != sci_strings) { - Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), _fname, _iVar); + iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &pstStrings); + if (iRet) { return SWIG_ERROR; } - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, NULL); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), _fname, _iVar); - return SWIG_ERROR; + // TODO: return SWIG_ERROR if _pcValue NULL (now returning SWIG_ERROR fails some typechecks) + if (_pcValue) + { + *_pcValue = pstStrings; } - _pstStrings = (char *)malloc(sizeof(char) * (piLength + 1)); - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&_pstStrings); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - if (alloc) { - *_pcValue = %new_copy_array(_pstStrings, piLength + 1, char); + if (alloc != NULL) { *alloc = SWIG_NEWOBJ; - } else if (_pcValue) { - *_pcValue = _pstStrings; } - free(_pstStrings); - if (_piLength != NULL) { - *_piLength = (size_t) piLength; + *_piLength = strlen(*_pcValue); } return SWIG_OK; From 9b270b9f6a1ccf195f0c0107c54ef7f3c616eba9 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 19 Jun 2013 16:28:57 +0200 Subject: [PATCH 07/41] Scilab: fix matrix typemap parameter names --- Lib/scilab/scimatrixdouble.swg | 76 +++++++++++++++++++--------------- Lib/scilab/scimatrixint.swg | 74 ++++++++++++++++----------------- 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/Lib/scilab/scimatrixdouble.swg b/Lib/scilab/scimatrixdouble.swg index 52823bf50..585d10e99 100644 --- a/Lib/scilab/scimatrixdouble.swg +++ b/Lib/scilab/scimatrixdouble.swg @@ -5,7 +5,9 @@ %include -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixAsInput, int rows, int cols) +// in (double* matrixIn, int matrixInRowCount, int matrixInColCount) + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixIn, int matrixInRowCount, int matrixInColCount) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) { @@ -13,7 +15,9 @@ } } -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int rows, int cols, double* matrixAsInput) +// in (int matrixInRowCount, int matrixInColCount, double* matrixIn) + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int matrixInRowCount, int matrixInColCount, double* matrixIn) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) { @@ -21,13 +25,15 @@ } } -%typemap(in) (double* matrixAsInput, int size) +// in (double* vectorIn, int vectorInSize) + +%typemap(in) (double* vectorIn, int vectorInSize) { - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) != SWIG_ERROR) { - $2 = nbRows * nbCols; + $2 = rowCount * colCount; } else { @@ -35,13 +41,15 @@ } } -%typemap(in) (int size, double* matrixAsInput) +// in (int vectorInSize, double* vectorIn) + +%typemap(in) (int vectorInSize, double* vectorIn) { - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) != SWIG_ERROR) { - $1 = nbRows * nbCols; + $1 = rowCount * colCount; } else { @@ -49,18 +57,20 @@ } } -%typemap(in, numinputs=0) (double** matrixAsOutput, int* rows, int* cols) +// out (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) + +%typemap(in, numinputs=0) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { } -%typemap(arginit) (double** matrixAsOutput, int* rows, int* cols) +%typemap(arginit) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { $1 = (double**) malloc(sizeof(double*)); $2 = (int*) malloc(sizeof(int)); $3 = (int*) malloc(sizeof(int)); } -%typemap(freearg) (double** matrixAsOutput, int* rows, int* cols) +%typemap(freearg) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { free(*$1); free($1); @@ -68,7 +78,7 @@ free($3); } -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixAsOutput, int* rows, int* cols) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) { @@ -80,22 +90,22 @@ } } -// (int* rows, int* cols, double** matrixAsOutput) +// out (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) -%typemap(in, numinputs=0) (int* rows, int* cols, double** matrixAsOutput) +%typemap(in, numinputs=0) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { } -%typemap(arginit) (int* rows, int* cols, double** matrixAsOutput) +%typemap(arginit) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int*) malloc(sizeof(int)); $3 = (double**) malloc(sizeof(double*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* rows, int* cols, double** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int* matrixInRowCount, int* matrixInColCount, double** matrixOut) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); } @@ -105,7 +115,7 @@ } } -%typemap(freearg) (int* rows, int* cols, double** matrixAsOutput) +%typemap(freearg) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { free($1); free($2); @@ -114,21 +124,20 @@ } -// (double** matrixAsOutput, int* size) +// out (double** vectorOut, int* vectorOutSize) -%typemap(in, numinputs=0) (double** matrixAsOutput, int* size) +%typemap(in, numinputs=0) (double** vectorOut, int* vectorOutSize) { } -%typemap(arginit) (double** matrixAsOutput, int* size) +%typemap(arginit) (double** vectorOut, int* vectorOutSize) { $1 = (double**) malloc(sizeof(double*)); $2 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (double** matrixAsOutput, int* size) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** vectorOut, int* vectorOutSize) { - if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -139,7 +148,7 @@ } } -%typemap(freearg) (double** matrixAsOutput, int* size) +%typemap(freearg) (double** vectorOut, int* vectorOutSize) { free(*$1); free($1); @@ -147,21 +156,20 @@ } -// (int* size, double** matrixAsOutput) +// out (int* vectorOutSize, double** vectorOut) -%typemap(in, numinputs=0) (int* size, double** matrixAsOutput) +%typemap(in, numinputs=0) (int* vectorOutSize, double** vectorOut) { } -%typemap(arginit) (int* size, double** matrixAsOutput) +%typemap(arginit) (int* vectorOutSize, double** vectorOut) { $1 = (int*) malloc(sizeof(int)); $2 = (double**) malloc(sizeof(double*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, double** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int* vectorOutSize, double** vectorOut) { - if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -172,7 +180,7 @@ } } -%typemap(freearg) (int* size, double** matrixAsOutput) +%typemap(freearg) (int* vectorOutSize, double** vectorOut) { free($1); free(*$2); diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg index 435f40875..fe02c30c7 100644 --- a/Lib/scilab/scimatrixint.swg +++ b/Lib/scilab/scimatrixint.swg @@ -5,9 +5,9 @@ %include -// (int* matrixAsInput, int rows, int cols) +// in (int* matrixIn, int matrixInRowCount, int matrixInColCount) -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int* matrixAsInput, int rows, int cols) +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int* matrixIn, int matrixInRowCount, int matrixInColCount) { if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) { @@ -16,9 +16,9 @@ } -// (int rows, int cols, int* matrixAsInput) +// in (int matrixInRowCount, int matrixInColCount, int* matrixIn) -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int rows, int cols, int* matrixAsInput) +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int matrixInRowCount, int matrixInColCount, int* matrixIn) { if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) { @@ -27,15 +27,15 @@ } -// (int* matrixAsInput, int size) +// in (int* vectorIn, int vectorInSize) -%typemap(in) (int* matrixAsInput, int size) +%typemap(in) (int* vectorIn, int vectorInSize) { - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) != SWIG_ERROR) { - $2 = nbRows * nbCols; + $2 = rowCount * colCount; } else { @@ -44,15 +44,15 @@ } -// (int size, int* matrixAsInput) +// in (int vectorInSize, int* vectorInSize) -%typemap(in) (int size, int* matrixAsInput) +%typemap(in) (int vectorInSize, int* vectorInSize) { - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) != SWIG_ERROR) { - $1 = nbRows * nbCols; + $1 = rowCount * colCount; } else { @@ -60,20 +60,20 @@ } } -// (int** matrixAsOutput, int* rows, int* cols) +// out (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) -%typemap(in, numinputs=0) (int** matrixAsOutput, int* rows, int* cols) +%typemap(in, numinputs=0) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { } -%typemap(arginit) (int** matrixAsOutput, int* rows, int* cols) +%typemap(arginit) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { $1 = (int**) malloc(sizeof(int*)); $2 = (int*) malloc(sizeof(int)); $3 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixAsOutput, int* rows, int* cols) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) { @@ -85,7 +85,7 @@ } } -%typemap(freearg) (int** matrixAsOutput, int* rows, int* cols) +%typemap(freearg) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { free(*$1); free($1); @@ -94,20 +94,20 @@ } -// (int* rows, int* cols, int** matrixAsOutput) +// out (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) -%typemap(in, numinputs=0) (int* rows, int* cols, int** matrixAsOutput) +%typemap(in, numinputs=0) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { } -%typemap(arginit) (int* rows, int* cols, int** matrixAsOutput) +%typemap(arginit) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int*) malloc(sizeof(int)); $3 = (int**) malloc(sizeof(int*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* rows, int* cols, int** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) { @@ -119,7 +119,7 @@ } } -%typemap(freearg) (int* rows, int* cols, int** matrixAsOutput) +%typemap(freearg) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { free($1); free($2); @@ -128,21 +128,20 @@ } -// (int** matrixAsOutput, int* size) +// out (int** vectorOut, int* vectorOutSize) -%typemap(in, numinputs=0) (int** matrixAsOutput, int* size) +%typemap(in, numinputs=0) (int** vectorOut, int* vectorOutSize) { } -%typemap(arginit) (int** matrixAsOutput, int* size) +%typemap(arginit) (int** vectorOut, int* vectorOutSize) { $1 = (int**) malloc(sizeof(int*)); $2 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixAsOutput, int* size) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** vectorOut, int* vectorOutSize) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -153,7 +152,7 @@ } } -%typemap(freearg) (int** matrixAsOutput, int* size) +%typemap(freearg) (int** vectorOut, int* vectorOutSize) { free(*$1); free($1); @@ -161,21 +160,20 @@ } -// (int* size, int** matrixAsOutput) +// out (int* vectorOutSize, int** vectorOut) -%typemap(in, numinputs=0) (int* size, int** matrixAsOutput) +%typemap(in, numinputs=0) (int* vectorOutSize, int** vectorOut) { } -%typemap(arginit) (int* size, int** matrixAsOutput) +%typemap(arginit) (int* vectorOutSize, int** vectorOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int**) malloc(sizeof(int*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, int** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* vectorOutSize, int** vectorOut) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -186,7 +184,7 @@ } } -%typemap(freearg) (int* size, int** matrixAsOutput) +%typemap(freearg) (int* vectorInSize, int** vectorOut) { free($1); free(*$2); From e6af8948ef25c927bd9e44414de22c16f220693b Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 19 Jun 2013 16:34:12 +0200 Subject: [PATCH 08/41] Scilab: add string matrix typemaps --- Lib/scilab/matrix.i | 2 +- Lib/scilab/scichar.swg | 74 +++++++++++++++++++++++++++++ Lib/scilab/scimatrixchar.swg | 91 ++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 Lib/scilab/scimatrixchar.swg diff --git a/Lib/scilab/matrix.i b/Lib/scilab/matrix.i index d36240cd1..0be93fa50 100644 --- a/Lib/scilab/matrix.i +++ b/Lib/scilab/matrix.i @@ -5,6 +5,6 @@ %include %include - +%include diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index 4b84c21fd..ec93d4783 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -175,3 +175,77 @@ SwigScilabStringFromCharPtr(void *_pvApiCtx, int _iVarOut, const char *_pchValue return Rhs + _iVarOut; } } + +/* + * CHAR * ARRAY +*/ +%fragment("SwigScilabStringToCharPtrArrayAndSize", "header") { +SWIGINTERN int +SwigScilabStringToCharPtrArrayAndSize(void *_pvApiCtx, int _iVar, char ***_charPtrArray, int* _charPtrArraySize, char *_fname) { + SciErr sciErr; + int i = 0; + int *piAddrVar = NULL; + int iRows = 0; + int iCols = 0; + int* piLength = NULL; + + if ((_charPtrArray == NULL) || (_charPtrArraySize == NULL)) { + return SWIG_ERROR; + } + + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, NULL, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + piLength = (int*) malloc(iRows * iCols * sizeof(int)); + + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, piLength, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + *_charPtrArray = (char**) malloc(iRows * iCols * sizeof(char*)); + for(i = 0 ; i < iRows * iCols ; i++) + { + (*_charPtrArray)[i] = (char*) malloc(sizeof(char) * (piLength[i] + 1)); + } + + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, piLength, *_charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + *_charPtrArraySize = iRows * iCols; + + free(piLength); + + return SWIG_OK; +} +} +%fragment("SwigScilabStringFromCharPtrArray", "header") { +SWIGINTERN int +SwigScilabStringFromCharPtrArray(void *_pvApiCtx, int _iVarOut, char **_charPtrArray, int _charPtrArraySize) { + SciErr sciErr; + + if (_charPtrArray == NULL) { + return SWIG_ERROR; + } + + sciErr = createMatrixOfString(_pvApiCtx, nbInputArgument(pvApiCtx) + _iVarOut, _charPtrArraySize, 1, _charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return nbInputArgument(pvApiCtx) + _iVarOut; +} +} diff --git a/Lib/scilab/scimatrixchar.swg b/Lib/scilab/scimatrixchar.swg new file mode 100644 index 000000000..0619270fe --- /dev/null +++ b/Lib/scilab/scimatrixchar.swg @@ -0,0 +1,91 @@ +/* + * C-type: char* + * Scilab type: string matrix + */ + +%include + +// in (char** vectorIn, int vectorInSize) + +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") (char** vectorIn, int vectorInSize) +{ + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &$1, &$2, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +// out (char*** vectorOut, int* vectorOutSize) + +%typemap(in, numinputs=0) (char*** vectorOut, int* vectorOutSize) +{ +} + +%typemap(arginit) (char*** vectorOut, int* vectorOutSize) +{ + $1 = (char***) malloc(sizeof(char**)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg) (char*** vectorOut, int* vectorOutSize) +{ + free(*(*$1)); + free(*$1); + free($1); + free($2); +} + +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") (char*** vectorOut, int* vectorOutSize) +{ + if (SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +// in (int vectorInSize, char** vectorIn) + +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") (int vectorInSize, char** vectorIn) +{ + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &$2, &$1, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +// out (int* vectorOutSize, char*** vectorOut) + +%typemap(in, numinputs=0) (int* vectorOutSize, char*** vectorOut) +{ +} + +%typemap(arginit) (int* vectorOutSize, char*** vectorOut) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (char***) malloc(sizeof(char**)); +} + +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") (int* vectorOutSize, char*** vectorOut) +{ + if (SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* vectorOutSize, char*** vectorOut) +{ + free($1); + free(*(*$2)); + free(*$2); + free($2); +} + From 8ca085b52863290f98216b3633efca4385d3f174 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 20 Jun 2013 10:55:05 +0200 Subject: [PATCH 09/41] Scilab: update matrix2 example (with int & string matrix conversion) --- Examples/scilab/matrix2/matrixlib.c | 82 +++++++++++++++++++++++++++-- Examples/scilab/matrix2/matrixlib.i | 27 +++++++--- Examples/scilab/matrix2/runme.sci | 45 +++++++++++++--- 3 files changed, 135 insertions(+), 19 deletions(-) diff --git a/Examples/scilab/matrix2/matrixlib.c b/Examples/scilab/matrix2/matrixlib.c index 20b516444..43006bb8b 100644 --- a/Examples/scilab/matrix2/matrixlib.c +++ b/Examples/scilab/matrix2/matrixlib.c @@ -1,6 +1,8 @@ #include -double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol) +// Double matrix functions + +double sumDoubleMatrix(double *inputMatrix, int nbRow, int nbCol) { int i; double total = 0.0; @@ -11,7 +13,7 @@ double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol) return total; } -void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double** resultMatrix, int* nbRowRes, int* nbColRes) +void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double** resultMatrix, int* nbRowRes, int* nbColRes) { int i; int size = nbRow * nbCol; @@ -24,7 +26,7 @@ void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double** re } } -void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) +void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) { int i; int size; @@ -37,3 +39,77 @@ void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) (*resultMatrix)[i] = i*2; } } + +// Integer matrix functions + +int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol) +{ + int i; + int total = 0; + for (i=0; i Date: Thu, 20 Jun 2013 11:15:13 +0200 Subject: [PATCH 10/41] Scilab: add support of STL vector --- Lib/scilab/scivectorstring.swg | 94 +++++++++++++++++++--------------- Lib/scilab/std_vector.i | 1 + 2 files changed, 54 insertions(+), 41 deletions(-) diff --git a/Lib/scilab/scivectorstring.swg b/Lib/scilab/scivectorstring.swg index 305f11424..b646db4a2 100644 --- a/Lib/scilab/scivectorstring.swg +++ b/Lib/scilab/scivectorstring.swg @@ -1,26 +1,25 @@ /* - * C++ type: std::vector - * Scilab 5 type: double matrix + * C++ type: std::vector + * Scilab 5 type: string matrix */ -%include +%include -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector(std::vector temp) +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector(std::vector 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; - } + char** charArray; + int charArraySize; + int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname); + if (ret == SWIG_OK) + { $1 = temp; - $1.reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector&)$1)); + $1.reserve(charArraySize); + std::copy(charArray, charArray + charArraySize, std::back_inserter((std::vector&)$1)); + + for (int i=0; i&(std::vector temp) +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector&(std::vector 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; - } + char** charArray; + int charArraySize; + int ret = SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &charArray, &charArraySize, fname); + if (ret == SWIG_OK) + { $1 = &temp; - $1->reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1)); + $1->reserve(charArraySize); + std::copy(charArray, charArray + charArraySize, std::back_inserter(*$1)); + + for (int i=0; i +%typemap(out, fragment="SwigScilabStringFromCharPtrArray") std::vector { - int nbCols = $1.size(); - double* dmatrix = new double[nbCols]; - std::copy($1.begin(), $1.end(), dmatrix); + int pCharArraySize = $1.size(); + char** pCharArray = new char*[pCharArraySize]; + char** p = pCharArray; + for (std::vector::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); - delete[] dmatrix; + int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize); + delete[] pCharArray; if (ret != SWIG_ERROR) { @@ -70,14 +75,21 @@ } } -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector& +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") std::vector& { - int nbCols = $1->size(); - double* dmatrix = new double[nbCols]; - std::copy($1->begin(), $1->end(), dmatrix); + int pCharArraySize = $1->size(); + char** pCharArray = new char*[pCharArraySize]; + char** p = pCharArray; + for (std::vector::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); - delete[] dmatrix; + int ret = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pCharArray, pCharArraySize); + delete[] pCharArray; if (ret != SWIG_ERROR) { diff --git a/Lib/scilab/std_vector.i b/Lib/scilab/std_vector.i index b6e8f16c6..cce68109b 100644 --- a/Lib/scilab/std_vector.i +++ b/Lib/scilab/std_vector.i @@ -27,6 +27,7 @@ %include %include +%include %include From 9bdeb673121f7c0ce90716e7f7e0d8a16054a681 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 20 Jun 2013 11:38:14 +0200 Subject: [PATCH 11/41] Scilab: update STL vector example with vector --- Examples/scilab/vector/example.cpp | 32 ++++++++++++++++++++---------- Examples/scilab/vector/example.hxx | 12 +++++------ Examples/scilab/vector/runme.sci | 11 +++++++++- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp index eb1518f96..7a1e7f044 100644 --- a/Examples/scilab/vector/example.cpp +++ b/Examples/scilab/vector/example.cpp @@ -2,17 +2,13 @@ #include "example.hxx" +// double vectors std::vector create_dvector(const int size, const double value) { return std::vector(size, value); } -std::vector create_ivector(const int size, const int value) -{ - return std::vector(size, value); -} - double sum_dvector(const std::vector dvector) { double sum = 0; @@ -23,6 +19,18 @@ double sum_dvector(const std::vector dvector) return sum; } +void concat_dvector(std::vector& dvector, const std::vector other_dvector) +{ + dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end()); +} + +// int vectors + +std::vector create_ivector(const int size, const int value) +{ + return std::vector(size, value); +} + int sum_ivector(const std::vector ivector) { int sum = 0; @@ -33,15 +41,19 @@ int sum_ivector(const std::vector ivector) return sum; } -void concat_dvector(std::vector& dvector, const std::vector other_dvector) -{ - dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end()); -} - void concat_ivector(std::vector& ivector, const std::vector other_ivector) { ivector.insert(ivector.end(), other_ivector.begin(), other_ivector.end()); } +// string vectors +std::vector create_svector(const int size, const char* value) +{ + return std::vector(size, value); +} +void concat_svector(std::vector& svector, const std::vector other_svector) +{ + svector.insert(svector.end(), other_svector.begin(), other_svector.end()); +} diff --git a/Examples/scilab/vector/example.hxx b/Examples/scilab/vector/example.hxx index 8d3fff734..f2a779f17 100644 --- a/Examples/scilab/vector/example.hxx +++ b/Examples/scilab/vector/example.hxx @@ -1,16 +1,16 @@ /* File : example.hxx */ #include +#include std::vector create_dvector(const int size, const double value); -std::vector create_ivector(const int size, const int value); - double sum_dvector(const std::vector dvector); -int sum_ivector(const std::vector ivector); - void concat_dvector(std::vector& dvector, const std::vector other_dvector); + +std::vector create_ivector(const int size, const int value); +int sum_ivector(const std::vector ivector); void concat_ivector(std::vector& ivector, const std::vector other_ivector); - - +std::vector create_svector(const int size, const char* value); +void concat_svector(std::vector& svector, const std::vector other_svector); diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci index 2dce998bc..523304201 100644 --- a/Examples/scilab/vector/runme.sci +++ b/Examples/scilab/vector/runme.sci @@ -20,9 +20,18 @@ is = sum_ivector(iv); disp("sum of this vector elements is:"); disp(is); iv2 = create_ivector(2, 1); -disp("concat this vector with the vector of int {1, 1}:"); +disp("concat this vector with the vector of ints {1, 1}:"); iv3 = concat_ivector(iv, iv2); disp(iv3); +disp("now an example with vectors of string."); +disp("create the vector of string {''aa'', ''aa''}:"); +sv = create_svector(2, "aa"); +disp(sv); +sv2 = create_svector(2, "bb"); +disp("concat this vector with the vector of string {''bb'', ''bb''}:"); +sv3 = concat_svector(sv, sv2); +disp(sv3); + From 87e0005276b41b63629020b19ce2ab264e9045c0 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 20 Jun 2013 18:17:20 +0200 Subject: [PATCH 12/41] Scilab: reference passing default mode is INPUT (here fix for vectors) --- Lib/scilab/scivectordouble.swg | 4 ++-- Lib/scilab/scivectorint.swg | 4 ++-- Lib/scilab/scivectorstring.swg | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Lib/scilab/scivectordouble.swg b/Lib/scilab/scivectordouble.swg index ee7e7b4ff..fef8921b1 100644 --- a/Lib/scilab/scivectordouble.swg +++ b/Lib/scilab/scivectordouble.swg @@ -28,7 +28,7 @@ } } -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector&(std::vector temp) +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector& (std::vector temp) { double* dmatrix; int nbRows; @@ -70,7 +70,7 @@ } } -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector& +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector &INOUT { int nbCols = $1->size(); double* dmatrix = new double[nbCols]; diff --git a/Lib/scilab/scivectorint.swg b/Lib/scilab/scivectorint.swg index 3cc9dd0d5..7dccef667 100644 --- a/Lib/scilab/scivectorint.swg +++ b/Lib/scilab/scivectorint.swg @@ -28,7 +28,7 @@ } } -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector&(std::vector temp) +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector& (std::vector temp) { int* imatrix; int nbRows; @@ -70,7 +70,7 @@ } } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector& +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector &INOUT { int nbCols = $1->size(); int* imatrix = new int[nbCols]; diff --git a/Lib/scilab/scivectorstring.swg b/Lib/scilab/scivectorstring.swg index b646db4a2..2fb32e79f 100644 --- a/Lib/scilab/scivectorstring.swg +++ b/Lib/scilab/scivectorstring.swg @@ -5,7 +5,7 @@ %include -%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector(std::vector temp) +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector (std::vector temp) { char** charArray; int charArraySize; @@ -27,7 +27,7 @@ } } -%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector&(std::vector temp) +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector& (std::vector temp) { char** charArray; int charArraySize; @@ -75,7 +75,7 @@ } } -%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") std::vector& +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") std::vector &INOUT { int pCharArraySize = $1->size(); char** pCharArray = new char*[pCharArraySize]; @@ -104,3 +104,6 @@ + + + From d1beaef1bad97763179acb50728ad226bdd30e60 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 20 Jun 2013 18:21:23 +0200 Subject: [PATCH 13/41] Scilab: improve STL vector example (test all argument passing modes) --- Examples/scilab/vector/example.cpp | 34 +++++++++++++++++++----------- Examples/scilab/vector/example.hxx | 12 ++++++----- Examples/scilab/vector/example.i | 6 +++++- Examples/scilab/vector/runme.sci | 4 ++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp index 7a1e7f044..80356eb93 100644 --- a/Examples/scilab/vector/example.cpp +++ b/Examples/scilab/vector/example.cpp @@ -2,6 +2,10 @@ #include "example.hxx" +#include +#include +#include + // double vectors std::vector create_dvector(const int size, const double value) @@ -9,19 +13,19 @@ std::vector create_dvector(const int size, const double value) return std::vector(size, value); } -double sum_dvector(const std::vector dvector) +double sum_dvector(const std::vector in_dvector) { double sum = 0; - for (int i = 0; i < dvector.size(); i++) + for (int i = 0; i < in_dvector.size(); i++) { - sum += dvector[i]; + sum += in_dvector[i]; } return sum; } -void concat_dvector(std::vector& dvector, const std::vector other_dvector) +void concat_dvector(std::vector& inout_dvector, const std::vector& in_dvector) { - dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end()); + inout_dvector.insert(inout_dvector.end(), in_dvector.begin(), in_dvector.end()); } // int vectors @@ -31,19 +35,19 @@ std::vector create_ivector(const int size, const int value) return std::vector(size, value); } -int sum_ivector(const std::vector ivector) +int sum_ivector(const std::vector in_ivector) { int sum = 0; - for (int i = 0; i < ivector.size(); i++) + for (int i = 0; i < in_ivector.size(); i++) { - sum += ivector[i]; + sum += in_ivector[i]; } return sum; } -void concat_ivector(std::vector& ivector, const std::vector other_ivector) +void concat_ivector(std::vector& inout_ivector, const std::vector& in_ivector) { - ivector.insert(ivector.end(), other_ivector.begin(), other_ivector.end()); + inout_ivector.insert(inout_ivector.end(), in_ivector.begin(), in_ivector.end()); } // string vectors @@ -53,7 +57,13 @@ std::vector create_svector(const int size, const char* value) return std::vector(size, value); } -void concat_svector(std::vector& svector, const std::vector other_svector) +void print_svector(const std::vector in_svector) { - svector.insert(svector.end(), other_svector.begin(), other_svector.end()); + std::copy(in_svector.begin(), in_svector.end(), std::ostream_iterator(std::cout, "\n")); + +} + +void concat_svector(std::vector& inout_svector, const std::vector& in_svector) +{ + inout_svector.insert(inout_svector.end(), in_svector.begin(), in_svector.end()); } diff --git a/Examples/scilab/vector/example.hxx b/Examples/scilab/vector/example.hxx index f2a779f17..4a4545917 100644 --- a/Examples/scilab/vector/example.hxx +++ b/Examples/scilab/vector/example.hxx @@ -4,13 +4,15 @@ #include std::vector create_dvector(const int size, const double value); -double sum_dvector(const std::vector dvector); -void concat_dvector(std::vector& dvector, const std::vector other_dvector); +double sum_dvector(const std::vector in_vector); +void concat_dvector(std::vector& inout_dvector, const std::vector& in_dvector); std::vector create_ivector(const int size, const int value); -int sum_ivector(const std::vector ivector); -void concat_ivector(std::vector& ivector, const std::vector other_ivector); +int sum_ivector(const std::vector in_ivector); +void concat_ivector(std::vector& inout_ivector, const std::vector& in_ivector); std::vector create_svector(const int size, const char* value); -void concat_svector(std::vector& svector, const std::vector other_svector); +void print_svector(const std::vector in_svector); +void concat_svector(std::vector& inout_svector, const std::vector& in_svector); + diff --git a/Examples/scilab/vector/example.i b/Examples/scilab/vector/example.i index 25981de3b..b04b9a6ba 100644 --- a/Examples/scilab/vector/example.i +++ b/Examples/scilab/vector/example.i @@ -8,4 +8,8 @@ %include "std_vector.i" -%include "example.hxx"; +%apply std::vector &INOUT { std::vector& inout_dvector }; +%apply std::vector &INOUT { std::vector& inout_ivector }; +%apply std::vector &INOUT { std::vector& inout_svector }; + +%include "example.hxx" diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci index 523304201..938e86670 100644 --- a/Examples/scilab/vector/runme.sci +++ b/Examples/scilab/vector/runme.sci @@ -27,11 +27,11 @@ disp(iv3); disp("now an example with vectors of string."); disp("create the vector of string {''aa'', ''aa''}:"); sv = create_svector(2, "aa"); -disp(sv); +print_svector(sv); sv2 = create_svector(2, "bb"); disp("concat this vector with the vector of string {''bb'', ''bb''}:"); sv3 = concat_svector(sv, sv2); -disp(sv3); +print_svector(sv3); From 627e4002fe8811f1bb53bd9032ea82318c1f4639 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 21 Jun 2013 11:30:11 +0200 Subject: [PATCH 14/41] Scilab: small fix on int matrix typemap --- Lib/scilab/scimatrixint.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg index fe02c30c7..11ffa9364 100644 --- a/Lib/scilab/scimatrixint.swg +++ b/Lib/scilab/scimatrixint.swg @@ -44,9 +44,9 @@ } -// in (int vectorInSize, int* vectorInSize) +// in (int vectorInSize, int* vectorIn) -%typemap(in) (int vectorInSize, int* vectorInSize) +%typemap(in) (int vectorInSize, int* vectorIn) { int rowCount; int colCount; From 3dd0ebdde9db434e79fbe17607224ea1e4b96c9e Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:31:34 +0200 Subject: [PATCH 15/41] Scilab: wrap SWIG_Init() function to initialize module SWIG types (needed for STL support) --- Lib/scilab/sciruntime.swg | 35 +++++++++++++++++++++++++++++------ Source/Modules/scilab.cxx | 8 +++++--- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index 9b9d9b3d2..67b7bb8f9 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -230,11 +230,34 @@ SwigScilabRaise(const char *type) { %} -//%insert(init) "swiginit.swg" -%init %{ -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ +%insert("init") +%{ + +#define SWIG_GetModule(clientdata) SWIG_Scilab_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Scilab_SetModule(pointer) + +SWIGRUNTIME swig_module_info* +SWIG_Scilab_GetModule(void) +{ + return NULL; +} + +SWIGRUNTIME void +SWIG_Scilab_SetModule(swig_module_info *swig_module) +{ +} -SWIGEXPORT int SWIG_init(void) { +%} + +%insert(init) "swiginit.swg" + +%init %{ +#ifdef __cplusplus +extern "C" { +int SWIG_Init(char *fname, unsigned long fname_len) { + SWIG_InitializeModule(NULL); + return 0; +} +} +#endif %} diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 6ece54dd5..7602365f3 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -22,6 +22,8 @@ Scilab Options (available with -scilab)\n\ -addcflag - Additionnal path to includes for builder.sce file (Ex: -I/usr/includes/)\n\ -addldlag - Additionnal library flag for builder.sce file (Ex: -lm)\n\n"; +const char* SWIG_INIT_FUNCTION_NAME = "SWIG_Init"; + class SCILAB : public Language { protected: /* General objects used for holding the strings */ @@ -174,6 +176,9 @@ public: Printf(builderCode, "table = ["); + /* Add initialization function to builder table */ + Printf(builderCode, "\"%s\",\"%s\";", SWIG_INIT_FUNCTION_NAME, SWIG_INIT_FUNCTION_NAME); + /* Emit code for children */ if (CPlusPlus) { Printf(wrappersSection, "extern \"C\" {\n"); @@ -201,9 +206,6 @@ public: Close(builderFile); Delete(builderFile); - /* Close the init function and quit (opened in sciruntime.swg) */ - Printf(initSection, "return 0;\n}\n"); - /* Write all to the wrapper file */ SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) Dump(runtimeSection, beginSection); From 1b26ad8b21b12974389c804396be13e48aad2d49 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:32:41 +0200 Subject: [PATCH 16/41] Scilab: added target in Examples makefile for debugging --- Examples/Makefile.in | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index a2d349268..9b14df4bf 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1147,14 +1147,14 @@ R_CFLAGS=-fPIC r: $(SRCS) $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) ifneq ($(SRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) + $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) r_cpp: $(CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) ifneq ($(CXXSRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) + $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) @@ -1217,19 +1217,26 @@ scilab_cpp: $(SRCS) env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH echo 'exit(1)' |$(SCILAB) -nwni -noatomsautoload -nb -f builder.sce; \ fi -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- # Running a Scilab example -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- scilab_run: @env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -nwni -noatomsautoload -nb -f runme.sci +# ----------------------------------------------------------------- +# Debugging a scilab example +# ----------------------------------------------------------------- + +scilab_debug: + @env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -noatomsautoload -nb -debug -f runme.sci + # ----------------------------------------------------------------- # Cleaning the scilab examples # ----------------------------------------------------------------- scilab_clean: - rm -f *.sce *.so lib*lib.c + rm -f *.sce *.so lib*lib.c *_wrap.* ################################################################## ##### Go ###### From cdb6554fba7b3ffadd3c9380583dbefa3d7ec509 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:44:23 +0200 Subject: [PATCH 17/41] Scilab: generic support for STL containers. STL containers are mapped in Scilab as: - for int, double, string: matrices (of int, or double, etc....) - for other types (like pointers on objects): list of pointers --- Lib/scilab/scicontainer.swg | 363 ++++++++++-------------------- Lib/scilab/scilist.swg | 78 +++++++ Lib/scilab/scisequence.swg | 153 +++++++++++++ Lib/scilab/scisequencedouble.swg | 103 +++++++++ Lib/scilab/scisequenceint.swg | 102 +++++++++ Lib/scilab/scisequencepointer.swg | 121 ++++++++++ Lib/scilab/scisequencestring.swg | 97 ++++++++ 7 files changed, 771 insertions(+), 246 deletions(-) create mode 100644 Lib/scilab/scilist.swg create mode 100644 Lib/scilab/scisequence.swg create mode 100644 Lib/scilab/scisequencedouble.swg create mode 100644 Lib/scilab/scisequenceint.swg create mode 100644 Lib/scilab/scisequencepointer.swg create mode 100644 Lib/scilab/scisequencestring.swg diff --git a/Lib/scilab/scicontainer.swg b/Lib/scilab/scicontainer.swg index a1e9b059f..ee740173e 100644 --- a/Lib/scilab/scicontainer.swg +++ b/Lib/scilab/scicontainer.swg @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * scicontainer.swg * - * Scilab list <-> C++ container wrapper (Based on Octave wrapper) + * Scilab list <-> C++ container wrapper * * This wrapper, and its iterator, allows a general use (and reuse) of * the mapping between C++ and Scilab, thanks to the C++ templates. @@ -15,177 +15,32 @@ #include %} - #if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS) # if !defined(SWIG_EXPORT_ITERATOR_METHODS) # define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS # endif #endif + +// #define (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS) +// if defined: sequences in return are converted from/to Scilab lists or matrices +// if not defined: sequences are passed from/to Scilab as pointers + +%{ +#define SWIG_STD_NOASSIGN_STL +%} + %include +%include -// The Scilab C++ Wrap - -%insert(header) %{ +%{ #include %} %include -%fragment(SWIG_Traits_frag(SciObject),"header",fragment="StdTraits") { -namespace swig { - template <> struct traits { - typedef value_category category; - static const char* type_name() { return "SciObject"; } - }; - - template <> struct traits_from { - typedef SciObject value_type; - static SciObject from(const value_type& val) { - return val; - } - }; - - template <> - struct traits_check { - static bool check(const SciObject&) { - return true; - } - }; - - template <> struct traits_asval { - typedef SciObject value_type; - static int asval(const SciObject& obj, value_type *val) { - if (val) *val = obj; - return SWIG_OK; - } - }; -} -} - -%fragment("SciSequence_Base","header",fragment="") -{ -%#include - -namespace std { - template <> - struct less : public binary_function - { - bool - operator()(const SciObject& v, const SciObject& w) const - { - //SciObject res = do_binary_op(SciObject::op_le,v,w); - return true;//res.is_true(); - } - }; -} - -namespace swig { - inline size_t - check_index(ptrdiff_t i, size_t size, bool insert = false) { - if ( i < 0 ) { - if ((size_t) (-i) <= size) - return (size_t) (i + size); - } else if ( (size_t) i < size ) { - return (size_t) i; - } else if (insert && ((size_t) i == size)) { - return size; - } - - throw std::out_of_range("index out of range"); - } - - inline size_t - slice_index(ptrdiff_t i, size_t size) { - if ( i < 0 ) { - if ((size_t) (-i) <= size) { - return (size_t) (i + size); - } else { - throw std::out_of_range("index out of range"); - } - } else { - return ( (size_t) i < size ) ? ((size_t) i) : size; - } - } - - template - inline typename Sequence::iterator - getpos(Sequence* self, Difference i) { - typename Sequence::iterator pos = self->begin(); - std::advance(pos, check_index(i,self->size())); - return pos; - } - - template - inline typename Sequence::const_iterator - cgetpos(const Sequence* self, Difference i) { - typename Sequence::const_iterator pos = self->begin(); - std::advance(pos, check_index(i,self->size())); - return pos; - } - - template - inline Sequence* - getslice(const Sequence* self, Difference i, Difference j) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size); - typename Sequence::size_type jj = swig::slice_index(j, size); - - if (jj > ii) { - typename Sequence::const_iterator vb = self->begin(); - typename Sequence::const_iterator ve = self->begin(); - std::advance(vb,ii); - std::advance(ve,jj); - return new Sequence(vb, ve); - } else { - return new Sequence(); - } - } - - template - inline void - setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj < ii) jj = ii; - size_t ssize = jj - ii; - if (ssize <= v.size()) { - typename Sequence::iterator sb = self->begin(); - typename InputSeq::const_iterator vmid = v.begin(); - std::advance(sb,ii); - std::advance(vmid, jj - ii); - self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end()); - } else { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb,ii); - std::advance(se,jj); - self->erase(sb,se); - self->insert(sb, v.begin(), v.end()); - } - } - - template - inline void - delslice(Sequence* self, Difference i, Difference j) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj > ii) { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb,ii); - std::advance(se,jj); - self->erase(sb,se); - } - } -} -} - -%fragment("SciSequence_Cont","header", +%fragment("SciSequence_Cont", "header", fragment="StdTraits", - fragment="SciSequence_Base", fragment="SciSwigIterator_T") { %#include @@ -193,43 +48,46 @@ namespace swig { namespace swig { template - struct SciSequence_Ref // * Scilab can't support these, because of how assignment works + struct SciSequence_Ref { SciSequence_Ref(const SciObject& seq, int index) : _seq(seq), _index(index) { + if (traits_as_sequence::get(_seq, &_piSeqAddr) != SWIG_OK) + { + throw std::invalid_argument("Cannot getl sequence data."); + } } operator T () const { - // swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, _index); - SciObject item; // * todo - try { - return swig::as(item, true); - } catch (std::exception& e) { - char msg[1024]; - sprintf(msg, "in sequence element %d ", _index); - if (!Scilab_Error_Occurred()) { - %type_error(swig::type_name()); - } - SWIG_Scilab_AddErrorMsg(msg); - SWIG_Scilab_AddErrorMsg(e.what()); - throw; + try + { + T value; + if (traits_asval_sequenceitem::asval(_seq, _piSeqAddr, _index, &value) == SWIG_OK) + { + return value; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); } } SciSequence_Ref& operator=(const T& v) { - // SciSequence_SetItem(_seq, _index, swig::from(v)); - // * todo + // TODO return *this; } - private: - SciObject _seq; - int _index; + private: + SciObject _seq; + int _index; + void *_piSeqAddr; }; + template struct SciSequence_ArrowProxy { @@ -349,14 +207,6 @@ namespace swig SciSequence_Cont(const SciObject& seq) : _seq(seq) { - // * assert that we have map type etc. - /* - if (!SciSequence_Check(seq)) { - throw std::invalid_argument("a sequence is expected"); - } - _seq = seq; - Py_INCREF(_seq); - */ } ~SciSequence_Cont() @@ -365,8 +215,15 @@ namespace swig size_type size() const { - // return static_cast(SciSequence_Size(_seq)); - return 0; // * todo + int iSeqSize; + if (traits_as_sequence::size(_seq, &iSeqSize) == SWIG_OK) + { + return iSeqSize; + } + else + { + return 0; + } } bool empty() const @@ -404,28 +261,9 @@ namespace swig return const_reference(_seq, n); } - bool check(bool set_err = true) const - { - int s = size(); - for (int i = 0; i < s; ++i) { - // swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, i); - SciObject item; // * todo - if (!swig::check(item)) { - if (set_err) { - char msg[1024]; - sprintf(msg, "in sequence element %d", i); - SWIG_Error(SWIG_RuntimeError, msg); - } - return false; - } - } - return true; - } - private: SciObject _seq; }; - } } @@ -491,30 +329,6 @@ namespace swig %swig_sequence_iterator(%arg(Sequence)) %swig_container_methods(%arg(Sequence)) - %fragment("SciSequence_Base"); - - %extend { - value_type pop() throw (std::out_of_range) { - if (self->size() == 0) - throw std::out_of_range("pop from empty container"); - Sequence::value_type x = self->back(); - self->pop_back(); - return x; - } - - value_type __paren__(difference_type i) throw (std::out_of_range) { - return *(swig::cgetpos(self, i)); - } - - void __paren_asgn__(difference_type i, value_type x) throw (std::out_of_range) { - *(swig::getpos(self,i)) = x; - } - - void append(value_type x) { - self->push_back(x); - } - } - %enddef %define %swig_sequence_methods(Sequence...) @@ -531,20 +345,21 @@ namespace swig %fragment("StdSequenceTraits","header", fragment="StdTraits", - fragment="SciSequence_Cont") + fragment="SciSequence_Cont", + fragment=SWIG_Traits_SequenceItem_frag(ptr)) { namespace swig { template inline void - assign(const SciSeq& sciseq, Seq* seq) { + assign(const SciSeq& sciSeq, Seq* seq) { %#ifdef SWIG_STD_NOASSIGN_STL typedef typename SciSeq::value_type value_type; - typename SciSeq::const_iterator it = sciseq.begin(); - for (;it != sciseq.end(); ++it) { + typename SciSeq::const_iterator it = sciSeq.begin(); + for (;it != sciSeq.end(); ++it) { seq->insert(seq->end(),(value_type)(*it)); } %#else - seq->assign(sciseq.begin(), sciseq.end()); + seq->assign(sciSeq.begin(), sciSeq.end()); %#endif } @@ -553,9 +368,41 @@ namespace swig { typedef Seq sequence; typedef T value_type; - static int asptr(const SciObject& obj, sequence **seq) { - // TODO: convert input Scilab list (or pointer) to sequence. - return SWIG_ERROR; + static int asptr(const SciObject& obj, sequence **seq) + { + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + sequence *p; + if (SWIG_ConvertPtr(obj, (void**)&p, typeInfo, 0) == SWIG_OK) + { + if (seq) + *seq = p; + return SWIG_OLDOBJ; + } + } + + if (traits_as_sequence::check(obj) == SWIG_OK) + { + try + { + SciSequence_Cont sciSeq(obj); + if (seq) + { + *seq = new sequence(); + assign(sciSeq, *seq); + return SWIG_NEWOBJ; + } + else + { + return true; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); + } + } } }; @@ -566,15 +413,39 @@ namespace swig { typedef typename Seq::size_type size_type; typedef typename sequence::const_iterator const_iterator; - static SciObject from(const sequence& seq) { -#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS - swig_type_info *desc = swig::type_info(); - if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN); + static SciObject from(const sequence& seq) + { + %#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + return SWIG_NewPointerObj(new sequence(seq), typeInfo, SWIG_POINTER_OWN); + } + %#endif + + try + { + void *data; + size_type size = seq.size(); + if (traits_from_sequence::create(size, &data) == SWIG_OK) { + const_iterator it; + int index = 0; + for (it = seq.begin(); it != seq.end(); ++it) + { + traits_from_sequenceitem::from(data, index, *it); + index++; + } + return traits_from_sequence::set(size, data); + } + else + { + return 0; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); } -#endif - // TODO: return a Scilab list from the sequence. - return (SciObject)0; } }; } diff --git a/Lib/scilab/scilist.swg b/Lib/scilab/scilist.swg new file mode 100644 index 000000000..fc73d463a --- /dev/null +++ b/Lib/scilab/scilist.swg @@ -0,0 +1,78 @@ +/* + * Scilab list related functions + * + */ + +%fragment("SWIG_ScilabList", "header") +{ +SWIGINTERN int +SWIG_GetScilabList(SciObject _obj, int **_piListAddr) +{ + SciErr sciErr; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, _piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGINTERN int +SWIG_GetScilabListSize(SciObject _obj, int *_piListSize) +{ + SciErr sciErr; + int *piListAddr; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getListItemNumber(pvApiCtx, piListAddr, _piListSize); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + + +SWIGINTERN int +SWIG_CheckScilabList(SciObject _obj) +{ + SciErr sciErr; + int *piListAddr; + int iType; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piListAddr, &iType); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if ((iType != sci_list) && (iType != sci_tlist) && (iType != sci_mlist)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A list is expected.\n"), fname, _obj); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +} + diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg new file mode 100644 index 000000000..c889f1a18 --- /dev/null +++ b/Lib/scilab/scisequence.swg @@ -0,0 +1,153 @@ +/* + * + * Scilab sequence conversions + * + */ + +#define SWIG_Traits_Sequence_frag(Type) %fragment_name(AsVal_Traits_Sequence, Type) + +#define SWIG_AsCheck_Sequence_frag(Type...) %fragment_name(AsCheck_Sequence, Type) +#define SWIG_AsCheck_Sequence_dec(Type...) %symbol_name(AsCheck_Sequence, Type) +#define SWIG_AsGet_Sequence_frag(Type...) %fragment_name(AsGet_Sequence, Type) +#define SWIG_AsGet_Sequence_dec(Type...) %symbol_name(AsGet_Sequence, Type) +#define SWIG_AsSize_Sequence_frag(Type...) %fragment_name(AsSize_Sequence, Type) +#define SWIG_AsSize_Sequence_dec(Type...) %symbol_name(AsSize_Sequence, Type) +#define SWIG_FromCreate_Sequence_frag(Type...) %fragment_name(FromCreate_Sequence, Type) +#define SWIG_FromCreate_Sequence_dec(Type...) %symbol_name(FromCreate_Sequence, Type) +#define SWIG_FromSet_Sequence_frag(Type...) %fragment_name(FromSet_Sequence, Type) +#define SWIG_FromSet_Sequence_dec(Type...) %symbol_name(FromSet_Sequence, Type) + +#define SWIG_Traits_SequenceItem_frag(Type) %fragment_name(AsVal_Traits_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_frag(Type...) %fragment_name(AsVal_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_dec(Type...) %symbol_name(AsVal_SequenceItem, Type) +#define SWIG_From_SequenceItem_frag(Type...) %fragment_name(From_SequenceItem, Type) +#define SWIG_From_SequenceItem_dec(Type...) %symbol_name(From_SequenceItem, Type) + + +%include +%include +%include +%include + +// +// Sequence conversion +// + +%fragment(SWIG_Traits_Sequence_frag(ptr), "header", + fragment=SWIG_AsCheck_Sequence_frag(ptr), + fragment=SWIG_AsGet_Sequence_frag(ptr), + fragment=SWIG_AsSize_Sequence_frag(ptr), + fragment=SWIG_FromCreate_Sequence_frag(ptr), + fragment=SWIG_FromSet_Sequence_frag(ptr)) { + +namespace swig { + template struct traits_as_sequence { + static int check(SciObject obj) { + return SWIG_AsCheck_Sequence_dec(ptr)(obj); + } + static int get(SciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(ptr)(obj, (int **)sequence); + } + static int size(SciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(ptr)(obj, size); + } + }; + template struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(ptr)(size, (int ***)sequence); + } + static SciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(ptr)(size, (int **)sequence); + } + }; +} +} + +%define %traits_sequence(CppType, ScilabType) + %fragment(SWIG_Traits_Sequence_frag(CppType), "header", + fragment=SWIG_Traits_Sequence_frag(ptr), + fragment=SWIG_AsCheck_Sequence_frag(CppType), + fragment=SWIG_AsGet_Sequence_frag(CppType), + fragment=SWIG_AsSize_Sequence_frag(CppType), + fragment=SWIG_FromCreate_Sequence_frag(CppType), + fragment=SWIG_FromSet_Sequence_frag(CppType)) { + +namespace swig { + template <> struct traits_as_sequence { + static int check(SciObject obj) { + return SWIG_AsCheck_Sequence_dec(CppType)(obj); + } + static int get(SciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(CppType)(obj, (ScilabType **)sequence); + } + static int size(SciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(CppType)(obj, size); + } + }; + template <> struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(CppType)(size, (ScilabType **)sequence); + } + static SciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(CppType)(size, (ScilabType *)sequence); + } + }; +} +} +%enddef + + +// +// Sequence item conversion +// + +%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header", + fragment=SWIG_AsVal_SequenceItem_frag(ptr), + fragment=SWIG_From_SequenceItem_frag(ptr)) { + +namespace swig { + template struct traits_asval_sequenceitem { + static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) { + return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (int **)pItemValue); + } + }; + template struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, T itemValue) { + return SWIG_From_SequenceItem_dec(ptr)((int **)pSequence, iItemIndex, (int*)itemValue); + } + }; +} +} + +%define %traits_sequenceitem(CppType, ScilabType) + %fragment(SWIG_Traits_SequenceItem_frag(CppType), "header", + fragment=SWIG_Traits_SequenceItem_frag(ptr), + fragment=SWIG_AsVal_SequenceItem_frag(CppType), + fragment=SWIG_From_SequenceItem_frag(CppType)) { + +namespace swig { + template <> struct traits_asval_sequenceitem { + static int asval(SciObject obj, void *pSequence, int iItemIndex, CppType *pItemValue) { + return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex, pItemValue); + } + }; + template <> struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, CppType itemValue) { + return SWIG_From_SequenceItem_dec(CppType)((ScilabType *)pSequence, iItemIndex, itemValue); + } + }; +} +} +%enddef + +%define %add_traits_sequence(CppType, ScilabType) + %traits_sequence(CppType, ScilabType); + %fragment(SWIG_Traits_Sequence_frag(CppType)); + %traits_sequenceitem(CppType, ScilabType); + %fragment(SWIG_Traits_SequenceItem_frag(CppType)); +%enddef + +%add_traits_sequence(int, int); +%add_traits_sequence(double, double); +%add_traits_sequence(std::string, char*); + diff --git a/Lib/scilab/scisequencedouble.swg b/Lib/scilab/scisequencedouble.swg new file mode 100644 index 000000000..cc07f6a39 --- /dev/null +++ b/Lib/scilab/scisequencedouble.swg @@ -0,0 +1,103 @@ +/* + * + * Scilab matrix of double <-> C++ double container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(double)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A double is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(double)(SciObject _obj, double **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(double)(SciObject _obj, int *_piSize) { + double *pdblMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &pdblMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: A double vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(double), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(double)(int _size, double **_sequence) { + *_sequence = new double[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_FromDoubleArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(double)(int _size, double *_sequence) { + SciObject obj = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (double *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(double), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(double)(SciObject _obj, double *_pSequence, int _iItemIndex, double *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(double), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(double)(double *_pSequence, int _iItemIndex, double _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scisequenceint.swg b/Lib/scilab/scisequenceint.swg new file mode 100644 index 000000000..f4e4427d8 --- /dev/null +++ b/Lib/scilab/scisequenceint.swg @@ -0,0 +1,102 @@ +/* + * + * Scilab matrix of int <-> C++ int container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(int)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isIntegerType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: An integer is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(int)(SciObject _obj, int **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(int)(SciObject _obj, int *_piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(int), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(int)(int _size, int **_sequence) { + *_sequence = new int[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_FromIntArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(int)(int _size, int *_sequence) { + SciObject obj = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (int *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(int)(SciObject _obj, int *_pSequence, int _iItemIndex, int *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(int)(int *_pSequence, int _iItemIndex, int _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} diff --git a/Lib/scilab/scisequencepointer.swg b/Lib/scilab/scisequencepointer.swg new file mode 100644 index 000000000..f68b2969c --- /dev/null +++ b/Lib/scilab/scisequencepointer.swg @@ -0,0 +1,121 @@ +/* + * + * Scilab list of pointer <-> C++ pointer container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(ptr)(SciObject _obj) { + return SWIG_CheckScilabList(_obj); +} +} + +%fragment(SWIG_AsGet_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(ptr)(SciObject _obj, int **_piSequence) { + return SWIG_GetScilabList(_obj, _piSequence); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(ptr)(SciObject _obj, int *_piSize) { + return SWIG_GetScilabListSize(_obj, _piSize); +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(ptr), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) { + *_sequence = new int*[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(ptr), "header") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) { + SciErr sciErr; + int *piListAddr; + + int iVarOut = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + + sciErr = createList(pvApiCtx, iVarOut, _size, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + for (int i=0; i<_size; i++) + { + sciErr = createPointerInList(pvApiCtx, iVarOut, piListAddr, i + 1, (void *)_sequence[i]); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + delete (int*)_sequence; + return iVarOut; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemIndex, int **_pItemValue) +{ + SciErr sciErr; + int *piItemAddr; + int iType; + + sciErr = getListItemAddress(pvApiCtx, _piSequence, _itemIndex + 1, &piItemAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piItemAddr, &iType); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType != sci_pointer) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A pointer is expected at list item #%d.\n"), fname, _obj, _itemIndex + 1); + return SWIG_ERROR; + } + + sciErr = getPointerInList(pvApiCtx, _piSequence, _itemIndex + 1, (void **)_pItemValue); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(ptr), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(ptr)(int **_pSequence, int _iItemIndex, int *_itemValue) { + _pSequence[_iItemIndex] = _itemValue; +} +} diff --git a/Lib/scilab/scisequencestring.swg b/Lib/scilab/scisequencestring.swg new file mode 100644 index 000000000..bde797728 --- /dev/null +++ b/Lib/scilab/scisequencestring.swg @@ -0,0 +1,97 @@ +/* + *char + * Scilab matrix of string <-> C++ std::string container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(std::string)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isStringType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A string is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(std::string)(SciObject _obj, char ***_pSequence) { + int iSize; + return (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, _pSequence, &iSize, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(std::string)(SciObject _obj, int *_piSize) { + char **pstMatrix; + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, &pstMatrix, _piSize, SWIG_Scilab_GetFname()) == SWIG_OK) { + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(std::string), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(std::string)(int _size, char ***_sequence) { + *_sequence = new char*[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(std::string), "header", + fragment="SwigScilabStringFromCharPtrArray") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(std::string)(int _size, char **_sequence) { + SciObject obj = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _sequence, _size); + delete (char **)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(std::string), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(std::string)(SciObject _obj, char **_pSequence, int _iItemIndex, std::string *_pItemValue) { + *_pItemValue = std::string(_pSequence[_iItemIndex]); + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(std::string), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(std::string)(char **_pSequence, int _iItemIndex, std::string _itemValue) { + char *pChar = new char(_itemValue.size() + 1); + strcpy(pChar, _itemValue.c_str()); + _pSequence[_iItemIndex] = pChar; + return SWIG_OK; +} +} + From 983af237b04c5e55b70057f63ca48c765fa6cddb Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:45:17 +0200 Subject: [PATCH 18/41] Scilab: generic support for STL vector --- Lib/scilab/scivectordouble.swg | 94 ---------------------------- Lib/scilab/scivectorint.swg | 91 --------------------------- Lib/scilab/scivectorstring.swg | 109 --------------------------------- Lib/scilab/std_vector.i | 13 ++-- 4 files changed, 6 insertions(+), 301 deletions(-) delete mode 100644 Lib/scilab/scivectordouble.swg delete mode 100644 Lib/scilab/scivectorint.swg delete mode 100644 Lib/scilab/scivectorstring.swg diff --git a/Lib/scilab/scivectordouble.swg b/Lib/scilab/scivectordouble.swg deleted file mode 100644 index fef8921b1..000000000 --- a/Lib/scilab/scivectordouble.swg +++ /dev/null @@ -1,94 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: double matrix - */ - -%include - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector(std::vector 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&)$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector& (std::vector 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 -{ - 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 &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; - } -} - - - - diff --git a/Lib/scilab/scivectorint.swg b/Lib/scilab/scivectorint.swg deleted file mode 100644 index 7dccef667..000000000 --- a/Lib/scilab/scivectorint.swg +++ /dev/null @@ -1,91 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: integer matrix - */ - -%include - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector(std::vector 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&)$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector& (std::vector 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 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 &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; - } -} - diff --git a/Lib/scilab/scivectorstring.swg b/Lib/scilab/scivectorstring.swg deleted file mode 100644 index 2fb32e79f..000000000 --- a/Lib/scilab/scivectorstring.swg +++ /dev/null @@ -1,109 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: string matrix - */ - -%include - -%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") std::vector (std::vector 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&)$1)); - - for (int i=0; i& (std::vector 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 -{ - int pCharArraySize = $1.size(); - char** pCharArray = new char*[pCharArraySize]; - char** p = pCharArray; - for (std::vector::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 &INOUT -{ - int pCharArraySize = $1->size(); - char** pCharArray = new char*[pCharArraySize]; - char** p = pCharArray; - for (std::vector::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; - } -} - - - - - - - diff --git a/Lib/scilab/std_vector.i b/Lib/scilab/std_vector.i index cce68109b..be7a1bde2 100644 --- a/Lib/scilab/std_vector.i +++ b/Lib/scilab/std_vector.i @@ -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") %{ namespace swig { @@ -14,7 +18,7 @@ template struct traits_from > { static SciObject from(const std::vector& vec) { - return traits_from_stdseq >::from(vec); + return traits_from_stdseq >::from(vec); } }; } @@ -24,10 +28,5 @@ #define %swig_vector_methods(Type...) %swig_sequence_methods(Type) #define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); - -%include -%include -%include - %include From 2472fe492a0adaf9364b6cedce5028ab807c4fc3 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:54:20 +0200 Subject: [PATCH 19/41] Scilab: rewrite STL vector example (vector argument passing example) Fixes: - use generic support of vectors - add vector of object example - improve example messages - simplify cpp code - move example code to "std_vector" folder --- .../std_vector_as_function_argument}/Makefile | 12 ++- .../example.cpp | 93 +++++++++++++++++++ .../example.hxx | 33 +++++++ .../std_vector_as_function_argument/example.i | 20 ++++ .../std_vector_as_function_argument/runme.sci | 57 ++++++++++++ Examples/scilab/vector/example.cpp | 69 -------------- Examples/scilab/vector/example.hxx | 18 ---- Examples/scilab/vector/example.i | 15 --- Examples/scilab/vector/runme.sci | 37 -------- 9 files changed, 211 insertions(+), 143 deletions(-) rename Examples/scilab/{vector => std_vector/std_vector_as_function_argument}/Makefile (72%) create mode 100644 Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp create mode 100644 Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx create mode 100644 Examples/scilab/std_vector/std_vector_as_function_argument/example.i create mode 100644 Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci delete mode 100644 Examples/scilab/vector/example.cpp delete mode 100644 Examples/scilab/vector/example.hxx delete mode 100644 Examples/scilab/vector/example.i delete mode 100644 Examples/scilab/vector/runme.sci diff --git a/Examples/scilab/vector/Makefile b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile similarity index 72% rename from Examples/scilab/vector/Makefile rename to Examples/scilab/std_vector/std_vector_as_function_argument/Makefile index e8ea02e15..032a0e6cc 100644 --- a/Examples/scilab/vector/Makefile +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile @@ -1,16 +1,20 @@ -TOP = ../.. +TOP = ../../.. SWIG = $(TOP)/../preinst-swig SRCS = example.cpp TARGET = example INTERFACE = example.i -all: +all: run + +loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cxx -check: all +run: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp new file mode 100644 index 000000000..779a74cbd --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp @@ -0,0 +1,93 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include + + + +template +std::vector concat_vector(const std::vector vector, const std::vector other_vector) +{ + std::vector out_vector(vector); + out_vector.insert(out_vector.end(), other_vector.begin(), other_vector.end()); + return out_vector; +} + +// double vectors + +std::vector create_double_vector(const int size, const double value) +{ + return std::vector(size, value); +} + +double sum_double_vector(const std::vector& vector) +{ + return std::accumulate(vector.begin(), vector.end(), 0); +} + +std::vector concat_double_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// int vectors + +std::vector create_integer_vector(const int size, const int value) +{ + return std::vector(size, value); +} + +int sum_integer_vector(const std::vector& vector) +{ + return std::accumulate(vector.begin(), vector.end(), 0); +} + +std::vector concat_integer_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// string vectors + +std::vector create_string_vector(const int size, const char* value) +{ + return std::vector(size, value); +} + +std::vector concat_string_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// pointer (on objects) vectors + +std::vector create_classA_vector(const int size, const int value) +{ + std::vector out_vector; + for (int i=0; i& vector) +{ + std::vector::const_iterator it; + std::cout << std::endl; + for (it = vector.begin(); it != vector.end(); ++it) + { + std::cout << "a << ">" << std::endl; + } +} + +std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx new file mode 100644 index 000000000..1db601e6f --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx @@ -0,0 +1,33 @@ +/* File : example.hxx */ + +#include +#include + + +// double vectors +std::vector create_double_vector(const int size, const double value); +double sum_double_vector(const std::vector& vector); +std::vector concat_double_vector(const std::vector vector, const std::vector other_vector); + +// integer vectors +std::vector create_integer_vector(const int size, const int value); +int sum_integer_vector(const std::vector& vector); +std::vector concat_integer_vector(const std::vector vector, const std::vector other_vector); + +// string vectors +std::vector create_string_vector(const int size, const char* value); +std::vector concat_string_vector(const std::vector vector, const std::vector other_vector); + +// pointer (on objects) vectors +class classA +{ +public: + classA() : a(0) {} + classA(int _a) : a(_a) {} + int a; +}; + +std::vector create_classA_vector(const int size, const int value); +void print_classA_vector(const std::vector& pvector); +std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector); + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i new file mode 100644 index 000000000..113b5639e --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i @@ -0,0 +1,20 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntVector) vector; + %template(DoubleVector) vector; + %template(StringVector) vector; + %template(ClassAVector) vector; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci new file mode 100644 index 000000000..1148be73d --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -0,0 +1,57 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL vectors arguments +// Here, STL vectors are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + + +// double vectors + +disp("Example of passing matrices of double as vector arguments of C++ functions."); +disp("get a vector of double {2.0, 2.0, 2.0, 2.0} from create_double_vector():"); +dv = create_double_vector(4, 2.0); +disp(dv); +disp("get the sum of this vector elements with sum_double_vector():") +ds = sum_double_vector(dv); +disp(ds); +dv2 = create_double_vector(2, 5.0); +disp("concat this vector with the vector of double {5.0, 5.0} with concat_double_vector():"); +dv3 = concat_double_vector(dv, dv2); +disp(dv3); + +// integer vectors + +disp("Example of passing matrices of int as vector arguments of C++ functions."); +disp("get a vector of int {3, 3, 3, 3} from create_integer_vector():"); +iv = create_integer_vector(3, 3); +disp(iv); +disp("get the sum of this vector elements with sum_integer_vector():") +is = sum_integer_vector(iv); +disp(is); +iv2 = create_integer_vector(2, 1); +disp("concat this vector with the vector of int {1, 1} with concat_integer_vector():"); +iv3 = concat_integer_vector(iv, iv2); +disp(iv3); + +// string vectors + +disp("Example of passing matrices of string as vector arguments of C++ functions."); +disp("get a vector of string {''aa'', ''aa''} with create_string_vector():"); +sv = create_string_vector(2, "aa"); +disp(sv); +sv2 = create_string_vector(2, "bb"); +disp("concat this vector with the vector of string {''bb'', ''bb''} with concat_string_vector():"); +sv3 = concat_string_vector(sv, sv2); +disp(sv3); + +// pointer (on object) vectors + +disp("Example of passing list of objects as vector arguments of C++ functions."); +disp("get a vector of objects {, , } with create_classA_vector():"); +pv = create_classA_vector(3, 1); +print_classA_vector(pv); +pv2 = create_classA_vector(2, 5); +disp("concat this vector with the vector of objects {, } with concat_classA_vector():"); +pv3 = concat_classA_vector(pv, pv2); +print_classA_vector(pv3); + diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp deleted file mode 100644 index 80356eb93..000000000 --- a/Examples/scilab/vector/example.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* File : example.cpp */ - -#include "example.hxx" - -#include -#include -#include - -// double vectors - -std::vector create_dvector(const int size, const double value) -{ - return std::vector(size, value); -} - -double sum_dvector(const std::vector in_dvector) -{ - double sum = 0; - for (int i = 0; i < in_dvector.size(); i++) - { - sum += in_dvector[i]; - } - return sum; -} - -void concat_dvector(std::vector& inout_dvector, const std::vector& in_dvector) -{ - inout_dvector.insert(inout_dvector.end(), in_dvector.begin(), in_dvector.end()); -} - -// int vectors - -std::vector create_ivector(const int size, const int value) -{ - return std::vector(size, value); -} - -int sum_ivector(const std::vector in_ivector) -{ - int sum = 0; - for (int i = 0; i < in_ivector.size(); i++) - { - sum += in_ivector[i]; - } - return sum; -} - -void concat_ivector(std::vector& inout_ivector, const std::vector& in_ivector) -{ - inout_ivector.insert(inout_ivector.end(), in_ivector.begin(), in_ivector.end()); -} - -// string vectors - -std::vector create_svector(const int size, const char* value) -{ - return std::vector(size, value); -} - -void print_svector(const std::vector in_svector) -{ - std::copy(in_svector.begin(), in_svector.end(), std::ostream_iterator(std::cout, "\n")); - -} - -void concat_svector(std::vector& inout_svector, const std::vector& in_svector) -{ - inout_svector.insert(inout_svector.end(), in_svector.begin(), in_svector.end()); -} diff --git a/Examples/scilab/vector/example.hxx b/Examples/scilab/vector/example.hxx deleted file mode 100644 index 4a4545917..000000000 --- a/Examples/scilab/vector/example.hxx +++ /dev/null @@ -1,18 +0,0 @@ -/* File : example.hxx */ - -#include -#include - -std::vector create_dvector(const int size, const double value); -double sum_dvector(const std::vector in_vector); -void concat_dvector(std::vector& inout_dvector, const std::vector& in_dvector); - -std::vector create_ivector(const int size, const int value); -int sum_ivector(const std::vector in_ivector); -void concat_ivector(std::vector& inout_ivector, const std::vector& in_ivector); - -std::vector create_svector(const int size, const char* value); -void print_svector(const std::vector in_svector); -void concat_svector(std::vector& inout_svector, const std::vector& in_svector); - - diff --git a/Examples/scilab/vector/example.i b/Examples/scilab/vector/example.i deleted file mode 100644 index b04b9a6ba..000000000 --- a/Examples/scilab/vector/example.i +++ /dev/null @@ -1,15 +0,0 @@ -/* File : example.i */ - -%module example - -%{ -#include "example.hxx" -%} - -%include "std_vector.i" - -%apply std::vector &INOUT { std::vector& inout_dvector }; -%apply std::vector &INOUT { std::vector& inout_ivector }; -%apply std::vector &INOUT { std::vector& inout_svector }; - -%include "example.hxx" diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci deleted file mode 100644 index 938e86670..000000000 --- a/Examples/scilab/vector/runme.sci +++ /dev/null @@ -1,37 +0,0 @@ -exec loader.sce; - -disp("this is an example with vectors of double."); -disp("create the vector of double {2.0, 2.0, 2.0, 2.0}:"); -dv = create_dvector(4, 2.0); -disp(dv); -ds = sum_dvector(dv); -disp("sum of this vector elements is:") -disp(ds); -dv2 = create_dvector(2, 5.0); -disp("concat this vector with the vector of double {5.0, 5.0}:"); -dv3 = concat_dvector(dv, dv2); -disp(dv3); - -disp("now an example with vectors of int."); -disp("create the vector of int {3, 3, 3}:"); -iv = create_ivector(3, 3); -disp(iv); -is = sum_ivector(iv); -disp("sum of this vector elements is:"); -disp(is); -iv2 = create_ivector(2, 1); -disp("concat this vector with the vector of ints {1, 1}:"); -iv3 = concat_ivector(iv, iv2); -disp(iv3); - -disp("now an example with vectors of string."); -disp("create the vector of string {''aa'', ''aa''}:"); -sv = create_svector(2, "aa"); -print_svector(sv); -sv2 = create_svector(2, "bb"); -disp("concat this vector with the vector of string {''bb'', ''bb''}:"); -sv3 = concat_svector(sv, sv2); -print_svector(sv3); - - - From 28dd6985c2a07d176a768de8cb6080e2acb21927 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:55:32 +0200 Subject: [PATCH 20/41] Scilab: add STL simple vector example (available also for Python, Ruby...) --- .../scilab/std_vector/std_vector/Makefile | 20 +++++++++++ .../scilab/std_vector/std_vector/example.h | 25 +++++++++++++ .../scilab/std_vector/std_vector/example.i | 18 ++++++++++ .../scilab/std_vector/std_vector/runme.sci | 35 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 Examples/scilab/std_vector/std_vector/Makefile create mode 100644 Examples/scilab/std_vector/std_vector/example.h create mode 100644 Examples/scilab/std_vector/std_vector/example.i create mode 100644 Examples/scilab/std_vector/std_vector/runme.sci diff --git a/Examples/scilab/std_vector/std_vector/Makefile b/Examples/scilab/std_vector/std_vector/Makefile new file mode 100644 index 000000000..2c9100c43 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +SRCS = +TARGET = example +INTERFACE = example.i + +all: run + +loader.sce: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile scilab_clean + +run: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_vector/std_vector/example.h b/Examples/scilab/std_vector/std_vector/example.h new file mode 100644 index 000000000..a5ea86d2a --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/example.h @@ -0,0 +1,25 @@ +/* File : example.h */ + +#include +#include +#include +#include + +double average(std::vector v) { + return std::accumulate(v.begin(),v.end(),0.0)/v.size(); +} + +std::vector half(const std::vector v) { + std::vector w(v); + for (unsigned int i=0; i& v) { + // would you believe this is the same as the above? + std::transform(v.begin(),v.end(),v.begin(), + std::bind2nd(std::divides(),2.0)); +} + + diff --git a/Examples/scilab/std_vector/std_vector/example.i b/Examples/scilab/std_vector/std_vector/example.i new file mode 100644 index 000000000..18f0775aa --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std { + %template(IntVector) vector; + %template(DoubleVector) vector; +} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/scilab/std_vector/std_vector/runme.sci b/Examples/scilab/std_vector/std_vector/runme.sci new file mode 100644 index 000000000..3dbe4c604 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/runme.sci @@ -0,0 +1,35 @@ +// file: runme.sci +exec loader.sce; +SWIG_Init(); + + +disp(mean([1,2,3,4])); + +// ... or a wrapped std::vector + +v = new_IntVector(); +for i = 1:4 + IntVector_push_back(v, i); +end; +disp(average(v)); + + +// half will return a Scilab matrix. +// Call it with a Scilab matrix... + +disp(half([1.0, 1.5, 2.0, 2.5, 3.0])); + + +// ... or a wrapped std::vector + +v = new_DoubleVector(); +for i = 1:4 + DoubleVector_push_back(v, i); +end; +disp(half(v)); + +// now halve a wrapped std::vector in place + +halve_in_place(v); +disp(v); + From c66952a3f0e49b2d24ccfdad68d09425550f8256 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:56:00 +0200 Subject: [PATCH 21/41] Scilab: add generic support for STL set --- Lib/scilab/std_set.i | 100 +++++++++++-------------------------------- Lib/scilab/stl.i | 7 +-- 2 files changed, 26 insertions(+), 81 deletions(-) diff --git a/Lib/scilab/std_set.i b/Lib/scilab/std_set.i index 0299e47b6..2a4b3b2cc 100644 --- a/Lib/scilab/std_set.i +++ b/Lib/scilab/std_set.i @@ -1,84 +1,32 @@ /* - * C++ type: std::set - * Scilab 5 type: integer matrix - */ + * + * C++ type : STL set + * Scilab type : matrix (for sets of primitive types) or list (for sets of all other types : pointers...) + * +*/ -%include +%fragment("StdSetTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SciObject &obj, std::set **set) { + return traits_asptr_stdseq >::asptr(obj, set); + } + }; -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set(std::set 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; - std::set& tmpset = (std::set&)$1; - std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin())); + template + struct traits_from > { + static SciObject from(const std::set& set) { + return traits_from_stdseq >::from(set); + } + }; } -} - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set& (std::set 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; - std::set& tmpset = *$1; - std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin())); - } -} +%} -%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::set -{ - int nbCols = $1.size(); - int* imatrix = new int[nbCols]; - std::copy($1.begin(), $1.end(), imatrix); +#define %swig_set_methods(Type...) %swig_sequence_methods(Type) +#define %swig_set_methods_val(Type...) %swig_sequence_methods_val(Type); - 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) std::set& -{ - 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; - } -} +%include diff --git a/Lib/scilab/stl.i b/Lib/scilab/stl.i index 9656ee6d4..27e7f262f 100644 --- a/Lib/scilab/stl.i +++ b/Lib/scilab/stl.i @@ -1,8 +1,5 @@ /* initial STL definition. extended as needed in each language */ %include std_common.i -%include std_vector.i %include std_string.i - - - - +%include std_vector.i +%include std_set.i From 1cf1e72e721b2369d5bad74a129990442cfbf52b Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:59:00 +0200 Subject: [PATCH 22/41] Scilab: update STL set example Fixes: - use generic support of STL set - add example for set of string --- Examples/scilab/set/example.cpp | 29 ----------- Examples/scilab/set/example.hxx | 13 ----- Examples/scilab/set/example.i | 14 ------ Examples/scilab/set/runme.sci | 16 ------ Examples/scilab/{set => std_set}/Makefile | 10 ++-- Examples/scilab/std_set/example.cpp | 61 +++++++++++++++++++++++ Examples/scilab/std_set/example.hxx | 14 ++++++ Examples/scilab/std_set/example.i | 18 +++++++ Examples/scilab/std_set/runme.sci | 31 ++++++++++++ 9 files changed, 131 insertions(+), 75 deletions(-) delete mode 100644 Examples/scilab/set/example.cpp delete mode 100644 Examples/scilab/set/example.hxx delete mode 100644 Examples/scilab/set/example.i delete mode 100644 Examples/scilab/set/runme.sci rename Examples/scilab/{set => std_set}/Makefile (77%) create mode 100644 Examples/scilab/std_set/example.cpp create mode 100644 Examples/scilab/std_set/example.hxx create mode 100644 Examples/scilab/std_set/example.i create mode 100644 Examples/scilab/std_set/runme.sci diff --git a/Examples/scilab/set/example.cpp b/Examples/scilab/set/example.cpp deleted file mode 100644 index 080b27416..000000000 --- a/Examples/scilab/set/example.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* File : example.cpp */ - -#include "example.hxx" - -std::set create_iset(const int size, const int* values) -{ - std::set iset; - std::copy(values, values + size, std::inserter(iset, iset.begin())); - return iset; -} - -int sum_iset(const std::set iset) -{ - int sum = 0; - std::set::iterator it; - for (it = iset.begin(); it != iset.end(); it++) - { - sum += *it; - } - return sum; -} - -void concat_iset(std::set& iset, const std::set other_iset) -{ - std::copy(other_iset.begin(), other_iset.end(), std::inserter(iset, iset.begin())); -} - - - diff --git a/Examples/scilab/set/example.hxx b/Examples/scilab/set/example.hxx deleted file mode 100644 index e00b7b24b..000000000 --- a/Examples/scilab/set/example.hxx +++ /dev/null @@ -1,13 +0,0 @@ -/* File : example.hxx */ - -#include - -std::set create_iset(const int size, const int* values); - -int sum_iset(const std::set iset); - -void concat_iset(std::set& iset, const std::set other_iset); - - - - diff --git a/Examples/scilab/set/example.i b/Examples/scilab/set/example.i deleted file mode 100644 index a4ab23972..000000000 --- a/Examples/scilab/set/example.i +++ /dev/null @@ -1,14 +0,0 @@ -/* File : example.i */ - -%module example - -%{ -#include "example.hxx" -%} - -%include "std_set.i" - -%include "matrix.i" -%apply (int size, int* matrixAsInput) { (const int size, const int* values) }; - -%include "example.hxx"; diff --git a/Examples/scilab/set/runme.sci b/Examples/scilab/set/runme.sci deleted file mode 100644 index 475d95b34..000000000 --- a/Examples/scilab/set/runme.sci +++ /dev/null @@ -1,16 +0,0 @@ -exec loader.sce; - -disp("this is an example with sets of int."); -disp("create the set from matrix [1, 2, 4, 4]:"); -iset = create_iset(int32([1, 2, 4, 4])); -disp(iset); -s = sum_iset(iset); -disp("sum of this set elements is:"); -disp(s); -iset2 = create_iset(int32([1, 10])); -disp("concat this set with the set of int {1, 10}:"); -iset3 = concat_iset(iset, iset2); -disp(iset3); - - - diff --git a/Examples/scilab/set/Makefile b/Examples/scilab/std_set/Makefile similarity index 77% rename from Examples/scilab/set/Makefile rename to Examples/scilab/std_set/Makefile index e8ea02e15..8a3ebed0c 100644 --- a/Examples/scilab/set/Makefile +++ b/Examples/scilab/std_set/Makefile @@ -4,13 +4,17 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all: +all: run + +loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cxx -check: all +run: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_set/example.cpp b/Examples/scilab/std_set/example.cpp new file mode 100644 index 000000000..1cb136d77 --- /dev/null +++ b/Examples/scilab/std_set/example.cpp @@ -0,0 +1,61 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include +#include + + +template +std::set concat_set(const std::set set, const std::set other_set) +{ + std::set out_set(set); + out_set.insert(other_set.begin(), other_set.end()); + return out_set; +} + +// int sets + +std::set create_integer_set(const int rangemin, const int rangemax) +{ + std::set out_set; + for (int i = rangemin; i <= rangemax; i++) + { + out_set.insert(i); + } + return out_set; +} + +int sum_integer_set(const std::set& set) +{ + return std::accumulate(set.begin(), set.end(), 0); +} + +std::set concat_integer_set(const std::set set, const std::set other_set) +{ + return concat_set(set, other_set); +} + +// string sets + +std::set create_string_set(const char* svalue) +{ + std::set out_set; + std::string str(svalue); + + std::istringstream iss(str); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::inserter >(out_set, out_set.begin())); + + return out_set; +} + +std::set concat_string_set(const std::set set, const std::set other_set) +{ + return concat_set(set, other_set); +} + diff --git a/Examples/scilab/std_set/example.hxx b/Examples/scilab/std_set/example.hxx new file mode 100644 index 000000000..615c8e9fa --- /dev/null +++ b/Examples/scilab/std_set/example.hxx @@ -0,0 +1,14 @@ +/* File : example.hxx */ + +#include +#include + + +// integer sets +std::set create_integer_set(const int size, const int value); +int sum_integer_set(const std::set& set); +std::set concat_integer_set(const std::set set, const std::set other_set); + +// string sets +std::set create_string_set(const char* value); +std::set concat_string_set(const std::set set, const std::set other_set); diff --git a/Examples/scilab/std_set/example.i b/Examples/scilab/std_set/example.i new file mode 100644 index 000000000..80032f677 --- /dev/null +++ b/Examples/scilab/std_set/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntSet) set; + %template(StringSet) set; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_set/runme.sci b/Examples/scilab/std_set/runme.sci new file mode 100644 index 000000000..8b479569d --- /dev/null +++ b/Examples/scilab/std_set/runme.sci @@ -0,0 +1,31 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL sets arguments +// Here, STL sets are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// integer sets + +disp("Example of passing matrices of int as set arguments of C++ functions."); +disp("get a set of int {1...4} from create_integer_set():"); +is = create_integer_set(1, 4); +disp(is); +disp("get the sum of this set elements with sum_integer_set():") +sum = sum_integer_set(is); +disp(is); +is2 = create_integer_set(3, 6); +disp("concat this set with the set of int {3...6} with concat_integer_set():"); +is3 = concat_integer_set(is, is2); +disp(is3); + +// string sets + +disp("Example of passing matrices of string as set arguments of C++ functions."); +disp("get a set of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_set():"); +ss = create_string_set("aa bb cc dd"); +disp(ss); +ss2 = create_string_set("cc dd ee ff"); +disp("concat this set with the set of string {''cc'', ''dd'', ''ee'', ''ff''} with concat_string_set():"); +ss3 = concat_string_set(ss, ss2); +disp(ss3); + From bc80012e0a790e8d0fe35609584157f8d2b60130 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 17:29:10 +0200 Subject: [PATCH 23/41] Scilab: add support for STL bool containers --- Lib/scilab/scibool.swg | 15 +++++ Lib/scilab/scisequence.swg | 2 + Lib/scilab/scisequencebool.swg | 102 +++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 Lib/scilab/scisequencebool.swg diff --git a/Lib/scilab/scibool.swg b/Lib/scilab/scibool.swg index a73c3306f..8306f3f93 100644 --- a/Lib/scilab/scibool.swg +++ b/Lib/scilab/scibool.swg @@ -82,3 +82,18 @@ SWIG_SciBoolean_AsIntArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows, int * return SWIG_OK; } } + +%fragment("SWIG_SciBoolean_FromIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_FromIntArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const int *_piData) { + SciErr sciErr; + + sciErr = createMatrixOfBoolean(_pvApiCtx, Rhs + _iVarOut, _iRows, _iCols, _piData); + if(sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return Rhs + _iVarOut; +} +} diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg index c889f1a18..2319f811c 100644 --- a/Lib/scilab/scisequence.swg +++ b/Lib/scilab/scisequence.swg @@ -28,6 +28,7 @@ %include %include %include +%include // // Sequence conversion @@ -150,4 +151,5 @@ namespace swig { %add_traits_sequence(int, int); %add_traits_sequence(double, double); %add_traits_sequence(std::string, char*); +%add_traits_sequence(bool, int); diff --git a/Lib/scilab/scisequencebool.swg b/Lib/scilab/scisequencebool.swg new file mode 100644 index 000000000..510dbb68e --- /dev/null +++ b/Lib/scilab/scisequencebool.swg @@ -0,0 +1,102 @@ +/* + * + * Scilab matrix of bool <-> C++ bool container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(bool), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(bool)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isBooleanType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A boolean is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(bool)(SciObject _obj, int **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(bool)(SciObject _obj, int *_piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(bool), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(bool)(int _size, int **_sequence) { + *_sequence = new int[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_FromIntArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(bool)(int _size, int *_sequence) { + SciObject obj = SWIG_SciBoolean_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (int *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(bool), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(bool)(SciObject _obj, int *_pSequence, int _iItemIndex, bool *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(bool), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(bool)(int *_pSequence, int _iItemIndex, bool _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} From ca282beae64348da759d490797eccd3f51e448fc Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 17:31:59 +0200 Subject: [PATCH 24/41] Scilab: add bool type in STL vector example --- .../std_vector_as_function_argument/example.cpp | 12 ++++++++++++ .../std_vector_as_function_argument/example.hxx | 4 ++++ .../std_vector_as_function_argument/example.i | 1 + .../std_vector_as_function_argument/runme.sci | 11 +++++++++++ 4 files changed, 28 insertions(+) diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp index 779a74cbd..c5d8c153a 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp @@ -63,6 +63,18 @@ std::vector concat_string_vector(const std::vector vec return concat_vector(vector, other_vector); } +// bool vectors + +std::vector create_bool_vector(const int size, const bool value) +{ + return std::vector(size, value); +} + +std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + // pointer (on objects) vectors std::vector create_classA_vector(const int size, const int value) diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx index 1db601e6f..efe6b6e4f 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx @@ -18,6 +18,10 @@ std::vector concat_integer_vector(const std::vector vector, const std: std::vector create_string_vector(const int size, const char* value); std::vector concat_string_vector(const std::vector vector, const std::vector other_vector); +// bool vectors +std::vector create_bool_vector(const int size, const bool value); +std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector); + // pointer (on objects) vectors class classA { diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i index 113b5639e..92c9a321c 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i @@ -14,6 +14,7 @@ namespace std %template(IntVector) vector; %template(DoubleVector) vector; %template(StringVector) vector; + %template(BoolVector) vector; %template(ClassAVector) vector; } diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci index 1148be73d..a463054e6 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -44,6 +44,17 @@ disp("concat this vector with the vector of string {''bb'', ''bb''} with concat_ sv3 = concat_string_vector(sv, sv2); disp(sv3); +// bool vectors + +disp("Example of passing matrices of bool as vector arguments of C++ functions."); +disp("get a vector of bool {true, true} with create_bool_vector():"); +bv = create_bool_vector(2, %T); +disp(bv); +bv2 = create_bool_vector(3, %F); +disp("concat this vector with the vector of bool {false, false, false} with concat_bool_vector():"); +bv3 = concat_bool_vector(bv, bv2); +disp(bv3); + // pointer (on object) vectors disp("Example of passing list of objects as vector arguments of C++ functions."); From f09525bcd8ac2112c75668a0f51ffac25bbd257a Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 17:59:49 +0200 Subject: [PATCH 25/41] Scilab: add generic support for STL list --- Lib/scilab/std_list.i | 27 +++++++++++++++++++++++++++ Lib/scilab/stl.i | 1 + 2 files changed, 28 insertions(+) create mode 100644 Lib/scilab/std_list.i diff --git a/Lib/scilab/std_list.i b/Lib/scilab/std_list.i new file mode 100644 index 000000000..a82349bcb --- /dev/null +++ b/Lib/scilab/std_list.i @@ -0,0 +1,27 @@ +/* + Lists +*/ + +%fragment("StdListTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(SciObject obj, std::list **lis) { + return traits_asptr_stdseq >::asptr(obj, lis); + } + }; + + template + struct traits_from > { + static SciObject from(const std::list &lis) { + return traits_from_stdseq >::from(lis); + } + }; + } +%} + +#define %swig_list_methods(Type...) %swig_sequence_methods(Type) +#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include \ No newline at end of file diff --git a/Lib/scilab/stl.i b/Lib/scilab/stl.i index 27e7f262f..76553c221 100644 --- a/Lib/scilab/stl.i +++ b/Lib/scilab/stl.i @@ -3,3 +3,4 @@ %include std_string.i %include std_vector.i %include std_set.i +%include std_list.i From ef48783589293545f32552fd6c1aeee93038ebb6 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 18:01:18 +0200 Subject: [PATCH 26/41] Scilab: add STL list example --- Examples/scilab/std_list/Makefile | 20 +++++++++ Examples/scilab/std_list/example.cpp | 61 ++++++++++++++++++++++++++++ Examples/scilab/std_list/example.hxx | 14 +++++++ Examples/scilab/std_list/example.i | 18 ++++++++ Examples/scilab/std_list/runme.sci | 31 ++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 Examples/scilab/std_list/Makefile create mode 100644 Examples/scilab/std_list/example.cpp create mode 100644 Examples/scilab/std_list/example.hxx create mode 100644 Examples/scilab/std_list/example.i create mode 100644 Examples/scilab/std_list/runme.sci diff --git a/Examples/scilab/std_list/Makefile b/Examples/scilab/std_list/Makefile new file mode 100644 index 000000000..8a3ebed0c --- /dev/null +++ b/Examples/scilab/std_list/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.cpp +TARGET = example +INTERFACE = example.i + +all: run + +loader.sce: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile scilab_clean + +run: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_list/example.cpp b/Examples/scilab/std_list/example.cpp new file mode 100644 index 000000000..416e1827a --- /dev/null +++ b/Examples/scilab/std_list/example.cpp @@ -0,0 +1,61 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include +#include + + +template +std::list concat_list(const std::list list, const std::list other_list) +{ + std::list out_list(list); + out_list.insert(out_list.end(), other_list.begin(), other_list.end()); + return out_list; +} + +// int lists + +std::list create_integer_list(const int rangemin, const int rangemax) +{ + std::list out_list; + for (int i = rangemin; i <= rangemax; i++) + { + out_list.push_back(i); + } + return out_list; +} + +int sum_integer_list(const std::list& list) +{ + return std::accumulate(list.begin(), list.end(), 0); +} + +std::list concat_integer_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + +// string lists + +std::list create_string_list(const char* svalue) +{ + std::list out_list; + std::string str(svalue); + + std::istringstream iss(str); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::inserter >(out_list, out_list.begin())); + + return out_list; +} + +std::list concat_string_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + diff --git a/Examples/scilab/std_list/example.hxx b/Examples/scilab/std_list/example.hxx new file mode 100644 index 000000000..116fcc3d4 --- /dev/null +++ b/Examples/scilab/std_list/example.hxx @@ -0,0 +1,14 @@ +/* File : example.hxx */ + +#include +#include + + +// integer lists +std::list create_integer_list(const int size, const int value); +int sum_integer_list(const std::list& list); +std::list concat_integer_list(const std::list list, const std::list other_list); + +// string lists +std::list create_string_list(const char* value); +std::list concat_string_list(const std::list list, const std::list other_list); diff --git a/Examples/scilab/std_list/example.i b/Examples/scilab/std_list/example.i new file mode 100644 index 000000000..51210e726 --- /dev/null +++ b/Examples/scilab/std_list/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntList) list; + %template(StringList) list; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_list/runme.sci b/Examples/scilab/std_list/runme.sci new file mode 100644 index 000000000..aba132f6b --- /dev/null +++ b/Examples/scilab/std_list/runme.sci @@ -0,0 +1,31 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL lists arguments +// Here, STL lists are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// integer lists + +disp("Example of passing matrices of int as list arguments of C++ functions."); +disp("get a list of int {1...4} from create_integer_list():"); +is = create_integer_list(1, 4); +disp(is); +disp("get the sum of this list elements with sum_integer_list():") +sum = sum_integer_list(is); +disp(is); +is2 = create_integer_list(3, 6); +disp("concat this list with the list of int {3...6} with concat_integer_list():"); +is3 = concat_integer_list(is, is2); +disp(is3); + +// string lists + +disp("Example of passing matrices of string as list arguments of C++ functions."); +disp("get a list of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_list():"); +ss = create_string_list("aa bb cc dd"); +disp(ss); +ss2 = create_string_list("cc dd ee ff"); +disp("concat this list with the list of string {''cc'', ''dd'', ''ee'', ''ff''} with concat_string_list():"); +ss3 = concat_string_list(ss, ss2); +disp(ss3); + From c3992df0bb8c0d4e51ae4b8ab6ba229d6b7cdf3a Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Mon, 22 Jul 2013 17:37:25 +0200 Subject: [PATCH 27/41] Scilab: support of containers of "complex type" values (like vector) --- Lib/scilab/scisequence.swg | 26 ++++++++++++++++++++++---- Lib/scilab/scisequencepointer.swg | 10 +++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg index 2319f811c..10df14a3e 100644 --- a/Lib/scilab/scisequence.swg +++ b/Lib/scilab/scisequence.swg @@ -55,10 +55,10 @@ namespace swig { }; template struct traits_from_sequence { static int create(int size, void **sequence) { - return SWIG_FromCreate_Sequence_dec(ptr)(size, (int ***)sequence); + return SWIG_FromCreate_Sequence_dec(ptr)(size, (long long **)sequence); } static SciObject set(int size, void *sequence) { - return SWIG_FromSet_Sequence_dec(ptr)(size, (int **)sequence); + return SWIG_FromSet_Sequence_dec(ptr)(size, (long long *)sequence); } }; } @@ -107,14 +107,32 @@ namespace swig { fragment=SWIG_From_SequenceItem_frag(ptr)) { namespace swig { + + // Default value container conversion of item + template struct traits_asval_sequenceitem { static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) { - return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (int **)pItemValue); + T* tmp; + int ret = SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (void **)&tmp); + *pItemValue = *tmp; } }; template struct traits_from_sequenceitem { static int from(void *pSequence, int iItemIndex, T itemValue) { - return SWIG_From_SequenceItem_dec(ptr)((int **)pSequence, iItemIndex, (int*)itemValue); + return SWIG_From_SequenceItem_dec(ptr)((long long *)pSequence, iItemIndex, (long long) &itemValue); + } + }; + + // Default pointer container conversion of item + + template struct traits_asval_sequenceitem { + static int asval(SciObject obj, void *pSequence, int iItemIndex, T **pItemValue) { + return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (void **)pItemValue); + } + }; + template struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, T *itemValue) { + return SWIG_From_SequenceItem_dec(ptr)((long long *)pSequence, iItemIndex, (long long) itemValue); } }; } diff --git a/Lib/scilab/scisequencepointer.swg b/Lib/scilab/scisequencepointer.swg index f68b2969c..332b5fb7e 100644 --- a/Lib/scilab/scisequencepointer.swg +++ b/Lib/scilab/scisequencepointer.swg @@ -36,8 +36,8 @@ SWIG_AsSize_Sequence_dec(ptr)(SciObject _obj, int *_piSize) { %fragment(SWIG_FromCreate_Sequence_frag(ptr), "header") { SWIGINTERN int -SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) { - *_sequence = new int*[_size]; +SWIG_FromCreate_Sequence_dec(ptr)(int _size, long long **_sequence) { + *_sequence = new long long[_size]; return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; } } @@ -45,7 +45,7 @@ SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) { %fragment(SWIG_FromSet_Sequence_frag(ptr), "header") { SWIGINTERN SciObject -SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) { +SWIG_FromSet_Sequence_dec(ptr)(int _size, long long *_sequence) { SciErr sciErr; int *piListAddr; @@ -75,7 +75,7 @@ SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) { %fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") { SWIGINTERN int -SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemIndex, int **_pItemValue) +SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int *_piSequence, int _itemIndex, void **_pItemValue) { SciErr sciErr; int *piItemAddr; @@ -115,7 +115,7 @@ SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemInde %fragment(SWIG_From_SequenceItem_frag(ptr), "header") { SWIGINTERN int -SWIG_From_SequenceItem_dec(ptr)(int **_pSequence, int _iItemIndex, int *_itemValue) { +SWIG_From_SequenceItem_dec(ptr)(long long *_pSequence, int _iItemIndex, long long _itemValue) { _pSequence[_iItemIndex] = _itemValue; } } From 111c1eb538fa931ee7c8c7545dfdde941dd3af82 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Mon, 22 Jul 2013 17:39:01 +0200 Subject: [PATCH 28/41] Scilab: add vector in STL vector example --- .../example.cpp | 36 ++++++++++++++++--- .../example.hxx | 16 ++++++--- .../std_vector_as_function_argument/example.i | 3 +- .../std_vector_as_function_argument/runme.sci | 15 ++++++-- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp index c5d8c153a..dcd24506e 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp @@ -75,9 +75,37 @@ std::vector concat_bool_vector(const std::vector vector, const std:: return concat_vector(vector, other_vector); } +// object vectors + +std::vector create_classA_vector(const int size, const int value) +{ + std::vector out_vector; + for (int i=0; i& vector) +{ + std::vector::const_iterator it; + std::cout << std::endl; + for (it = vector.begin(); it != vector.end(); ++it) + { + std::cout << "a << ">" << std::endl; + } +} + +std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + // pointer (on objects) vectors -std::vector create_classA_vector(const int size, const int value) +std::vector create_classAPtr_vector(const int size, const int value) { std::vector out_vector; for (int i=0; i create_classA_vector(const int size, const int value) return out_vector; } -void print_classA_vector(const std::vector& vector) +void print_classAPtr_vector(const std::vector& vector) { std::vector::const_iterator it; std::cout << std::endl; for (it = vector.begin(); it != vector.end(); ++it) { - std::cout << "a << ">" << std::endl; + std::cout << "a << ">" << std::endl; } } -std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector) +std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector) { return concat_vector(vector, other_vector); } diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx index efe6b6e4f..65391d8c6 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx @@ -22,7 +22,7 @@ std::vector concat_string_vector(const std::vector vec std::vector create_bool_vector(const int size, const bool value); std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector); -// pointer (on objects) vectors + class classA { public: @@ -31,7 +31,15 @@ public: int a; }; -std::vector create_classA_vector(const int size, const int value); -void print_classA_vector(const std::vector& pvector); -std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector); +// object vectors + +std::vector create_classA_vector(const int size, const int value); +void print_classA_vector(const std::vector& pvector); +std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector); + +// pointer (on objects) vectors + +std::vector create_classAPtr_vector(const int size, const int value); +void print_classAPtr_vector(const std::vector& pvector); +std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector); diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i index 92c9a321c..f27df893b 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i @@ -15,7 +15,8 @@ namespace std %template(DoubleVector) vector; %template(StringVector) vector; %template(BoolVector) vector; - %template(ClassAVector) vector; + %template(ClassAVector) vector; + %template(ClassAPtrVector) vector; } %include "example.hxx" diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci index a463054e6..9c6299c9a 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -55,9 +55,9 @@ disp("concat this vector with the vector of bool {false, false, false} with conc bv3 = concat_bool_vector(bv, bv2); disp(bv3); -// pointer (on object) vectors +// object vectors -disp("Example of passing list of objects as vector arguments of C++ functions."); +disp("Example of passing lists of pointer on object as vector of objects arguments of C++ functions."); disp("get a vector of objects {, , } with create_classA_vector():"); pv = create_classA_vector(3, 1); print_classA_vector(pv); @@ -66,3 +66,14 @@ disp("concat this vector with the vector of objects {, } pv3 = concat_classA_vector(pv, pv2); print_classA_vector(pv3); +// pointer (on object) vectors + +disp("Example of passing lists of pointers on object as vector of pointers on objects arguments of C++ functions."); +disp("get a vector of pointers on object {, , } with create_classAPtr_vector():"); +pv = create_classAPtr_vector(3, 1); +print_classAPtr_vector(pv); +pv2 = create_classAPtr_vector(2, 5); +disp("concat this vector with the vector of pointers on object {, } with concat_classAPtr_vector():"); +pv3 = concat_classAPtr_vector(pv, pv2); +print_classAPtr_vector(pv3); + From 2ea501d488ef78c3877c64b31d0c67bccd80418f Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Mon, 22 Jul 2013 17:39:25 +0200 Subject: [PATCH 29/41] Scilab: small typo fix --- Lib/scilab/scicontainer.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/scilab/scicontainer.swg b/Lib/scilab/scicontainer.swg index ee740173e..41458d509 100644 --- a/Lib/scilab/scicontainer.swg +++ b/Lib/scilab/scicontainer.swg @@ -55,7 +55,7 @@ namespace swig { if (traits_as_sequence::get(_seq, &_piSeqAddr) != SWIG_OK) { - throw std::invalid_argument("Cannot getl sequence data."); + throw std::invalid_argument("Cannot get sequence data."); } } From ae92e24b0cb444b6cabebde8dc3910cd92e5f581 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Mon, 22 Jul 2013 17:41:45 +0200 Subject: [PATCH 30/41] Scilab: missing delete variable in scilab program --- Source/Modules/scilab.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 7602365f3..e8c539346 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -221,6 +221,8 @@ public: Close(beginSection); Delete(beginSection); + Delete(sourceFileList); + return SWIG_OK; } From 2ce28624721b71ae20d16a0ac135043c89a1b337 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 16:37:30 +0200 Subject: [PATCH 31/41] Scilab: fix some example makefiles (restore target check) --- Examples/scilab/std_set/Makefile | 4 ++-- Examples/scilab/std_vector/std_vector/Makefile | 4 ++-- .../std_vector/std_vector_as_function_argument/Makefile | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Examples/scilab/std_set/Makefile b/Examples/scilab/std_set/Makefile index 8a3ebed0c..698e8a472 100644 --- a/Examples/scilab/std_set/Makefile +++ b/Examples/scilab/std_set/Makefile @@ -4,7 +4,7 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all: run +all: check loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ @@ -13,7 +13,7 @@ loader.sce: clean: $(MAKE) -f $(TOP)/Makefile scilab_clean -run: loader.sce +check: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run debug: loader.sce diff --git a/Examples/scilab/std_vector/std_vector/Makefile b/Examples/scilab/std_vector/std_vector/Makefile index 2c9100c43..244ca1145 100644 --- a/Examples/scilab/std_vector/std_vector/Makefile +++ b/Examples/scilab/std_vector/std_vector/Makefile @@ -4,7 +4,7 @@ SRCS = TARGET = example INTERFACE = example.i -all: run +all: check loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ @@ -13,7 +13,7 @@ loader.sce: clean: $(MAKE) -f $(TOP)/Makefile scilab_clean -run: loader.sce +check: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run debug: loader.sce diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile index 032a0e6cc..ea885ccc9 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile @@ -4,7 +4,7 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all: run +all: check loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ @@ -13,7 +13,7 @@ loader.sce: clean: $(MAKE) -f $(TOP)/Makefile scilab_clean -run: loader.sce +check: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run debug: loader.sce From f7b67980e6d6bec43936d8170449f4515e2f461c Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 16:38:52 +0200 Subject: [PATCH 32/41] Scilab: fix some example scripts (missing exit) --- Examples/scilab/matrix2/runme.sci | 2 ++ Examples/scilab/std_set/runme.sci | 2 ++ Examples/scilab/std_vector/std_vector/runme.sci | 2 ++ .../scilab/std_vector/std_vector_as_function_argument/runme.sci | 2 ++ Examples/scilab/template/runme.sci | 2 ++ 5 files changed, 10 insertions(+) diff --git a/Examples/scilab/matrix2/runme.sci b/Examples/scilab/matrix2/runme.sci index a4780edc0..e1be153b7 100644 --- a/Examples/scilab/matrix2/runme.sci +++ b/Examples/scilab/matrix2/runme.sci @@ -39,5 +39,7 @@ disp("Call lib function concatStringVector()"); stringVector2 = concatStringVector(stringVector); disp(stringVector2); +exit + diff --git a/Examples/scilab/std_set/runme.sci b/Examples/scilab/std_set/runme.sci index 8b479569d..68078a0fb 100644 --- a/Examples/scilab/std_set/runme.sci +++ b/Examples/scilab/std_set/runme.sci @@ -29,3 +29,5 @@ disp("concat this set with the set of string {''cc'', ''dd'', ''ee'', ''ff''} wi ss3 = concat_string_set(ss, ss2); disp(ss3); +exit + diff --git a/Examples/scilab/std_vector/std_vector/runme.sci b/Examples/scilab/std_vector/std_vector/runme.sci index 3dbe4c604..67f1a8eb6 100644 --- a/Examples/scilab/std_vector/std_vector/runme.sci +++ b/Examples/scilab/std_vector/std_vector/runme.sci @@ -33,3 +33,5 @@ disp(half(v)); halve_in_place(v); disp(v); +exit + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci index 9c6299c9a..1b6e11c41 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -77,3 +77,5 @@ disp("concat this vector with the vector of pointers on object {, < pv3 = concat_classAPtr_vector(pv, pv2); print_classAPtr_vector(pv3); +exit + diff --git a/Examples/scilab/template/runme.sci b/Examples/scilab/template/runme.sci index 7c084f09e..d4d21ae09 100644 --- a/Examples/scilab/template/runme.sci +++ b/Examples/scilab/template/runme.sci @@ -30,3 +30,5 @@ delete_SquareDouble(s); printf("%i shapes remain\n", ShapeDouble_getNbShapes()); +exit + From d85cc8b796c001c9dd3b0751a32a0836206d95da Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 16:40:15 +0200 Subject: [PATCH 33/41] Scilab: SWIG_Init() used in C++ mode only --- Source/Modules/scilab.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index e8c539346..a562d9dba 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -176,8 +176,10 @@ public: Printf(builderCode, "table = ["); - /* Add initialization function to builder table */ - Printf(builderCode, "\"%s\",\"%s\";", SWIG_INIT_FUNCTION_NAME, SWIG_INIT_FUNCTION_NAME); + /* In C++ mode, add initialization function to builder table */ + if (CPlusPlus) { + Printf(builderCode, "\"%s\",\"%s\";", SWIG_INIT_FUNCTION_NAME, SWIG_INIT_FUNCTION_NAME); + } /* Emit code for children */ if (CPlusPlus) { From 16d45620ba7d404ed185c4609b3d4e2ee21bb706 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 19 Jul 2013 16:43:06 +0200 Subject: [PATCH 34/41] Scilab: fix example check list --- Examples/scilab/check.list | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/scilab/check.list b/Examples/scilab/check.list index 57888c86c..038e99498 100644 --- a/Examples/scilab/check.list +++ b/Examples/scilab/check.list @@ -5,10 +5,14 @@ contract enum funcptr matrix -#matrix2 +matrix2 pointer simple +std_set +std_vector/std_vector +std_vector/std_vector_as_function_argument struct +template variables From 74243ae306c335cc695110748c68885c2f493356 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 23 Jul 2013 14:59:01 +0200 Subject: [PATCH 35/41] Scilab: fix constructor_copy test_case using vector needs T have default constructor --- Examples/test-suite/constructor_copy.i | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/constructor_copy.i b/Examples/test-suite/constructor_copy.i index 02ae5f944..4b977034d 100644 --- a/Examples/test-suite/constructor_copy.i +++ b/Examples/test-suite/constructor_copy.i @@ -5,13 +5,13 @@ %nocopyctor Bar; %inline %{ - + struct Foo1 { int x; Foo1(int _x = 2) : x(_x) { - } + } }; struct Foo2 { @@ -25,7 +25,7 @@ struct Foo3 { struct Foo4 { Foo4() { } - + protected: Foo4(const Foo4& ) { } }; @@ -33,7 +33,7 @@ protected: struct Foo4a { Foo4a() { } - + private: Foo4a(const Foo4a& ) { } }; @@ -53,7 +53,7 @@ struct Foo8 { }; template -class Bar +class Bar { public: int x; @@ -95,12 +95,14 @@ public: namespace Space { class Flow { public: + Flow() {} Flow(int i) {} }; class FlowFlow { public: + FlowFlow() {} FlowFlow(int i) {} }; @@ -124,7 +126,7 @@ public: template struct ModelUtils_T {}; - } + } } %} @@ -142,13 +144,13 @@ namespace Space1 { class TotalReturnSwap { public: TotalReturnSwap() {} - }; + }; template class TotalReturnSwap_T { public: TotalReturnSwap_T() {} - }; + }; } } From 25ffa87cab05e57ae6eec05f681eb0ce25283a95 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 23 Jul 2013 15:02:39 +0200 Subject: [PATCH 36/41] Scilab: fix dynamic_cast test case Close SWIG_Init() in Scilab executable. --- Lib/scilab/sciruntime.swg | 10 ++-------- Source/Modules/scilab.cxx | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index 67b7bb8f9..a86275e23 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -230,9 +230,7 @@ SwigScilabRaise(const char *type) { %} -%insert("init") -%{ - +%init %{ #define SWIG_GetModule(clientdata) SWIG_Scilab_GetModule() #define SWIG_SetModule(clientdata, pointer) SWIG_Scilab_SetModule(pointer) @@ -246,18 +244,14 @@ SWIGRUNTIME void SWIG_Scilab_SetModule(swig_module_info *swig_module) { } - %} %insert(init) "swiginit.swg" %init %{ #ifdef __cplusplus -extern "C" { +extern "C" int SWIG_Init(char *fname, unsigned long fname_len) { SWIG_InitializeModule(NULL); - return 0; -} -} #endif %} diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index a562d9dba..544bc1e40 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -208,6 +208,9 @@ public: Close(builderFile); Delete(builderFile); + /* Close the init function (opened in sciinit.swg) */ + Printf(initSection, "return 0;\n}\n"); + /* Write all to the wrapper file */ SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) Dump(runtimeSection, beginSection); From c5c684632a3511fec7e46c20b9165cbf2c97df5a Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Tue, 23 Jul 2013 15:03:53 +0200 Subject: [PATCH 37/41] Scilab: fix vararg test case crash --- Source/Modules/scilab.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 544bc1e40..ad4b562a9 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -359,7 +359,7 @@ public: maxOutputArguments++; } - Delete(functionReturnTypemap); + //Delete(functionReturnTypemap); // Makes SWIG crash on vararg test case. } else { Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(functionReturnType, 0), functionName); From d034386fc6980a160202a43dd18c616406059e32 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 31 Jul 2013 10:46:40 +0200 Subject: [PATCH 38/41] Scilab: fix usage of swig scilab program (-help) --- Source/Modules/scilab.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index ad4b562a9..07661be20 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -17,10 +17,10 @@ /*#define SWIG_DEBUG*/ static const char *usage = (char*) "\ -Scilab Options (available with -scilab)\n\ - -addsrc - Additionnal source file for builder.sce file (Ex: myfile.cxx)\n\ - -addcflag - Additionnal path to includes for builder.sce file (Ex: -I/usr/includes/)\n\ - -addldlag - Additionnal library flag for builder.sce file (Ex: -lm)\n\n"; +Scilab options\n\ + -addsrc additionnal source files (separated by comma) to include in build script (ex: myfile.cxx myfile2.cxx)\n\ + -addcflag -I additionnal include path to include in build script (ex: -I/usr/includes/)\n\ + -addldlag additionnal link flag to include in build script (ex: -lm)\n\n"; const char* SWIG_INIT_FUNCTION_NAME = "SWIG_Init"; From 077e69a851df5efc777769aa18762d5af897093c Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 31 Jul 2013 11:57:16 +0200 Subject: [PATCH 39/41] Scilab: fix SWIT_Init() close in C mode --- Lib/scilab/sciruntime.swg | 1 - Source/Modules/scilab.cxx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index a86275e23..ee6c9e792 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -253,5 +253,4 @@ SWIG_Scilab_SetModule(swig_module_info *swig_module) extern "C" int SWIG_Init(char *fname, unsigned long fname_len) { SWIG_InitializeModule(NULL); -#endif %} diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 07661be20..37c1cb041 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -209,7 +209,7 @@ public: Delete(builderFile); /* Close the init function (opened in sciinit.swg) */ - Printf(initSection, "return 0;\n}\n"); + Printf(initSection, "return 0;\n}\n#endif\n"); /* Write all to the wrapper file */ SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) From 255603639f918c5b4b89bbcdba8b7e55bb3af120 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 31 Jul 2013 18:28:23 +0200 Subject: [PATCH 40/41] Scilab: rollback, support of container only (not ) --- .../example.cpp | 28 ------------------- .../example.hxx | 11 ++------ .../std_vector_as_function_argument/example.i | 1 - .../std_vector_as_function_argument/runme.sci | 12 -------- Lib/scilab/scisequence.swg | 26 +++-------------- Lib/scilab/scisequencepointer.swg | 10 +++---- 6 files changed, 11 insertions(+), 77 deletions(-) diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp index dcd24506e..febe5f4e2 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp @@ -75,34 +75,6 @@ std::vector concat_bool_vector(const std::vector vector, const std:: return concat_vector(vector, other_vector); } -// object vectors - -std::vector create_classA_vector(const int size, const int value) -{ - std::vector out_vector; - for (int i=0; i& vector) -{ - std::vector::const_iterator it; - std::cout << std::endl; - for (it = vector.begin(); it != vector.end(); ++it) - { - std::cout << "a << ">" << std::endl; - } -} - -std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector) -{ - return concat_vector(vector, other_vector); -} - // pointer (on objects) vectors std::vector create_classAPtr_vector(const int size, const int value) diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx index 65391d8c6..e16ce8990 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx @@ -22,23 +22,16 @@ std::vector concat_string_vector(const std::vector vec std::vector create_bool_vector(const int size, const bool value); std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector); - +// pointer (on object) vectors class classA { public: classA() : a(0) {} classA(int _a) : a(_a) {} + classA(const classA& c) : a(c.a) {} int a; }; -// object vectors - -std::vector create_classA_vector(const int size, const int value); -void print_classA_vector(const std::vector& pvector); -std::vector concat_classA_vector(const std::vector vector, const std::vector other_vector); - -// pointer (on objects) vectors - std::vector create_classAPtr_vector(const int size, const int value); void print_classAPtr_vector(const std::vector& pvector); std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector); diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i index f27df893b..a405742f4 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i @@ -15,7 +15,6 @@ namespace std %template(DoubleVector) vector; %template(StringVector) vector; %template(BoolVector) vector; - %template(ClassAVector) vector; %template(ClassAPtrVector) vector; } diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci index 1b6e11c41..87535d617 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -4,7 +4,6 @@ SWIG_Init(); // This example shows how to use C++ fonctions with STL vectors arguments // Here, STL vectors are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) - // double vectors disp("Example of passing matrices of double as vector arguments of C++ functions."); @@ -55,17 +54,6 @@ disp("concat this vector with the vector of bool {false, false, false} with conc bv3 = concat_bool_vector(bv, bv2); disp(bv3); -// object vectors - -disp("Example of passing lists of pointer on object as vector of objects arguments of C++ functions."); -disp("get a vector of objects {, , } with create_classA_vector():"); -pv = create_classA_vector(3, 1); -print_classA_vector(pv); -pv2 = create_classA_vector(2, 5); -disp("concat this vector with the vector of objects {, } with concat_classA_vector():"); -pv3 = concat_classA_vector(pv, pv2); -print_classA_vector(pv3); - // pointer (on object) vectors disp("Example of passing lists of pointers on object as vector of pointers on objects arguments of C++ functions."); diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg index 10df14a3e..2319f811c 100644 --- a/Lib/scilab/scisequence.swg +++ b/Lib/scilab/scisequence.swg @@ -55,10 +55,10 @@ namespace swig { }; template struct traits_from_sequence { static int create(int size, void **sequence) { - return SWIG_FromCreate_Sequence_dec(ptr)(size, (long long **)sequence); + return SWIG_FromCreate_Sequence_dec(ptr)(size, (int ***)sequence); } static SciObject set(int size, void *sequence) { - return SWIG_FromSet_Sequence_dec(ptr)(size, (long long *)sequence); + return SWIG_FromSet_Sequence_dec(ptr)(size, (int **)sequence); } }; } @@ -107,32 +107,14 @@ namespace swig { fragment=SWIG_From_SequenceItem_frag(ptr)) { namespace swig { - - // Default value container conversion of item - template struct traits_asval_sequenceitem { static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) { - T* tmp; - int ret = SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (void **)&tmp); - *pItemValue = *tmp; + return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (int **)pItemValue); } }; template struct traits_from_sequenceitem { static int from(void *pSequence, int iItemIndex, T itemValue) { - return SWIG_From_SequenceItem_dec(ptr)((long long *)pSequence, iItemIndex, (long long) &itemValue); - } - }; - - // Default pointer container conversion of item - - template struct traits_asval_sequenceitem { - static int asval(SciObject obj, void *pSequence, int iItemIndex, T **pItemValue) { - return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (void **)pItemValue); - } - }; - template struct traits_from_sequenceitem { - static int from(void *pSequence, int iItemIndex, T *itemValue) { - return SWIG_From_SequenceItem_dec(ptr)((long long *)pSequence, iItemIndex, (long long) itemValue); + return SWIG_From_SequenceItem_dec(ptr)((int **)pSequence, iItemIndex, (int*)itemValue); } }; } diff --git a/Lib/scilab/scisequencepointer.swg b/Lib/scilab/scisequencepointer.swg index 332b5fb7e..36f6ca2d5 100644 --- a/Lib/scilab/scisequencepointer.swg +++ b/Lib/scilab/scisequencepointer.swg @@ -36,8 +36,8 @@ SWIG_AsSize_Sequence_dec(ptr)(SciObject _obj, int *_piSize) { %fragment(SWIG_FromCreate_Sequence_frag(ptr), "header") { SWIGINTERN int -SWIG_FromCreate_Sequence_dec(ptr)(int _size, long long **_sequence) { - *_sequence = new long long[_size]; +SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) { + *_sequence = new int*[_size]; return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; } } @@ -45,7 +45,7 @@ SWIG_FromCreate_Sequence_dec(ptr)(int _size, long long **_sequence) { %fragment(SWIG_FromSet_Sequence_frag(ptr), "header") { SWIGINTERN SciObject -SWIG_FromSet_Sequence_dec(ptr)(int _size, long long *_sequence) { +SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) { SciErr sciErr; int *piListAddr; @@ -75,7 +75,7 @@ SWIG_FromSet_Sequence_dec(ptr)(int _size, long long *_sequence) { %fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") { SWIGINTERN int -SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int *_piSequence, int _itemIndex, void **_pItemValue) +SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemIndex, int **_pItemValue) { SciErr sciErr; int *piItemAddr; @@ -115,7 +115,7 @@ SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int *_piSequence, int _itemInde %fragment(SWIG_From_SequenceItem_frag(ptr), "header") { SWIGINTERN int -SWIG_From_SequenceItem_dec(ptr)(long long *_pSequence, int _iItemIndex, long long _itemValue) { +SWIG_From_SequenceItem_dec(ptr)(int **_pSequence, int _iItemIndex, int *_itemValue) { _pSequence[_iItemIndex] = _itemValue; } } From 6735b9727f9c68e0a935fe77d331cf60145b9217 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 31 Jul 2013 18:28:45 +0200 Subject: [PATCH 41/41] Scilab: fix arrays_global test_case --- Lib/scilab/scichar.swg | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index ec93d4783..b0ca9d6f0 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -99,23 +99,27 @@ SWIGINTERN int SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLength, char *_fname) { SciErr sciErr; int *piAddrVar = NULL; + char* pcTmpValue = NULL; int iRet; + if (_pcValue == NULL) { + return SWIG_ERROR; + } + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - if (_pcValue == NULL) { - return SWIG_ERROR; - } - - iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &_pcValue); + iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &pcTmpValue); if (iRet) { return SWIG_ERROR; } + strncpy(_pcValue, pcTmpValue, _iLength); + free(pcTmpValue); + return SWIG_OK; } }