diff --git a/Examples/scilab/matrix2/Makefile b/Examples/scilab/matrix2/Makefile index 4950a70ea..374a46bbb 100644 --- a/Examples/scilab/matrix2/Makefile +++ b/Examples/scilab/matrix2/Makefile @@ -4,12 +4,12 @@ SRCS = matrixlib.c TARGET = matrixlib INTERFACE = matrixlib.i -all:: +all: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab - -clean:: + +clean: $(MAKE) -f $(TOP)/Makefile scilab_clean rm -f *.sce *.so lib*lib.c *_wrap.c diff --git a/Examples/scilab/matrix2/matrixlib.c b/Examples/scilab/matrix2/matrixlib.c index 5d6af7178..20b516444 100644 --- a/Examples/scilab/matrix2/matrixlib.c +++ b/Examples/scilab/matrix2/matrixlib.c @@ -1,32 +1,39 @@ #include -double sumitems(double *first, int nbRow, int nbCol) { + +double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol) +{ int i; - double total; - for (i=0; i<(nbRow*nbCol); i++) { - total+=first[i]; + double total = 0.0; + for (i=0; i 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 new file mode 100644 index 000000000..e00b7b24b --- /dev/null +++ b/Examples/scilab/set/example.hxx @@ -0,0 +1,13 @@ +/* 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 new file mode 100644 index 000000000..a4ab23972 --- /dev/null +++ b/Examples/scilab/set/example.i @@ -0,0 +1,14 @@ +/* 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 new file mode 100644 index 000000000..475d95b34 --- /dev/null +++ b/Examples/scilab/set/runme.sci @@ -0,0 +1,16 @@ +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/template/Makefile b/Examples/scilab/template/Makefile new file mode 100644 index 000000000..6c0980aca --- /dev/null +++ b/Examples/scilab/template/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.cxx +TARGET = example +INTERFACE = example.i + +all: + $(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.c *_wrap.cxx + +check: all + $(MAKE) -f $(TOP)/Makefile scilab_run diff --git a/Examples/scilab/template/example.cxx b/Examples/scilab/template/example.cxx new file mode 100644 index 000000000..72410315d --- /dev/null +++ b/Examples/scilab/template/example.cxx @@ -0,0 +1,43 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +template +void Shape::move(T dx, T dy) { + x += dx; + y += dy; +} + +template +int Shape::nbshapes = 0; + +template +int Shape::getNbShapes() { + return Shape::nbshapes; +} + +template +T Circle::area() { + return M_PI*radius*radius; +} + +template +T Circle::perimeter() { + return 2*M_PI*radius; +} + +template +T Square::area() { + return width*width; +} + +template +T Square::perimeter() { + return 4*width; +} + +template class Shape; +template class Square; +template class Circle; + diff --git a/Examples/scilab/template/example.h b/Examples/scilab/template/example.h new file mode 100644 index 000000000..a825631b3 --- /dev/null +++ b/Examples/scilab/template/example.h @@ -0,0 +1,36 @@ +/* File : example.h */ + +template +class Shape { +private: + static int nbshapes; +public: + Shape() { x = 0; y = 0; nbshapes++; } + virtual ~Shape() { nbshapes--; }; + T x, y; + void move(T dx, T dy); + virtual T area() = 0; + virtual T perimeter() = 0; + static int getNbShapes(); +}; + +template +class Circle : public Shape { +private: + T radius; +public: + Circle(T r) : Shape() { radius = r; }; + virtual T area(); + virtual T perimeter(); +}; + +template +class Square : public Shape { +private: + T width; +public: + Square(T w) : Shape() { width = w; }; + virtual T area(); + virtual T perimeter(); +}; + diff --git a/Examples/scilab/template/example.i b/Examples/scilab/template/example.i new file mode 100644 index 000000000..9732ebe2b --- /dev/null +++ b/Examples/scilab/template/example.i @@ -0,0 +1,14 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + +%template(ShapeDouble) Shape; +%template(CircleDouble) Circle; +%template(SquareDouble) Square; + diff --git a/Examples/scilab/template/runme.sci b/Examples/scilab/template/runme.sci new file mode 100644 index 000000000..7c084f09e --- /dev/null +++ b/Examples/scilab/template/runme.sci @@ -0,0 +1,32 @@ +function printShape(shape, name) + printf("\nShape %s position:\n", name); + printf(" (x, y) = (%f, %f)\n", ShapeDouble_x_get(shape), ShapeDouble_y_get(shape)) + + printf("\nShape %s properties:\n", name); + printf(" area = %f\n", ShapeDouble_area(shape)); + printf(" perimeter = %f\n", ShapeDouble_perimeter(shape)); + + printf("\n"); +endfunction + +exec loader.sce; + +printf("Creating some objects:\n"); +c = new_CircleDouble(10); +s = new_SquareDouble(10); + +printf("\nA total of %i shapes were created\n", ShapeDouble_getNbShapes()); + +ShapeDouble_move(c, 20, 30); +ShapeDouble_move(s, -10, 0); + +printShape(c, "circle"); +printShape(s, "square"); + +printf("\nGuess I will clean up now\n"); + +delete_CircleDouble(c); +delete_SquareDouble(s); + +printf("%i shapes remain\n", ShapeDouble_getNbShapes()); + diff --git a/Examples/scilab/vector/Makefile b/Examples/scilab/vector/Makefile index 168d5a5dc..e8ea02e15 100644 --- a/Examples/scilab/vector/Makefile +++ b/Examples/scilab/vector/Makefile @@ -4,13 +4,13 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all:: +all: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cpp + rm -f *.sce *.so lib*lib.c *_wrap.cxx check: all $(MAKE) -f $(TOP)/Makefile scilab_run diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp index 3afe6b12a..eb1518f96 100644 --- a/Examples/scilab/vector/example.cpp +++ b/Examples/scilab/vector/example.cpp @@ -1,19 +1,47 @@ /* File : example.cpp */ -#include -#include +#include "example.hxx" -class opt { -public: - void set_lower_bound(const std::vector &v) { - double sum = 0; - std::cout << "coucou" << std::endl; - for (int i = 0; i < v.size(); i++) { - sum += v[i]; - std::cout << v[i] << std::endl; - } - //return sum; + +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; + for (int i = 0; i < dvector.size(); i++) + { + sum += dvector[i]; } -}; + return sum; +} + +int sum_ivector(const std::vector ivector) +{ + int sum = 0; + for (int i = 0; i < ivector.size(); i++) + { + sum += ivector[i]; + } + 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()); +} + diff --git a/Examples/scilab/vector/example.hxx b/Examples/scilab/vector/example.hxx index b272099e9..8d3fff734 100644 --- a/Examples/scilab/vector/example.hxx +++ b/Examples/scilab/vector/example.hxx @@ -1,18 +1,16 @@ -/* File : example.cpp */ +/* File : example.hxx */ #include -namespace nlopt { - class opt { - public: - void set_lower_bound(const std::vector &v) { - double sum = 0; - for (int i = 0; i < v.size(); i++) { - sum += v[i]; - } - //return sum; - } - }; -} +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); +void concat_ivector(std::vector& ivector, const std::vector other_ivector); + + diff --git a/Examples/scilab/vector/example.i b/Examples/scilab/vector/example.i index 75d700cbd..25981de3b 100644 --- a/Examples/scilab/vector/example.i +++ b/Examples/scilab/vector/example.i @@ -1,4 +1,5 @@ /* File : example.i */ + %module example %{ @@ -6,8 +7,5 @@ %} %include "std_vector.i" -namespace std { - %template(nlopt_doublevector) vector; - }; %include "example.hxx"; diff --git a/Examples/scilab/vector/loader.sce b/Examples/scilab/vector/loader.sce deleted file mode 100644 index 4cb5545b0..000000000 --- a/Examples/scilab/vector/loader.sce +++ /dev/null @@ -1,58 +0,0 @@ -// This file is released under the 3-clause BSD license. See COPYING-BSD. -// Generated by builder.sce : Please, do not edit this file -// ---------------------------------------------------------------------------- -// -libexamplelib_path = get_absolute_file_path('loader.sce'); -// -// ulink previous function with same name -[bOK, ilib] = c_link('libexamplelib'); -if bOK then - ulink(ilib); -end -// -list_functions = [ 'delete_SciSwigIterator'; - 'SciSwigIterator_value'; - 'SciSwigIterator_incr'; - 'SciSwigIterator_decr'; - 'SciSwigIterator_distance'; - 'SciSwigIterator_equal'; - 'SciSwigIterator_copy'; - 'SciSwigIterator_next'; - 'SciSwigIterator_previous'; - 'SciSwigIterator_advance'; - 'nlopt_doublevector_pop'; - 'nlopt_doublevector___paren__'; - 'nlopt_doublevector___paren_asgn__'; - 'nlopt_doublevector_append'; - 'nlopt_doublevector_empty'; - 'nlopt_doublevector_size'; - 'nlopt_doublevector_clear'; - 'nlopt_doublevector_swap'; - 'nlopt_doublevector_get_allocator'; - 'nlopt_doublevector_begin'; - 'nlopt_doublevector_end'; - 'nlopt_doublevector_rbegin'; - 'nlopt_doublevector_rend'; - 'nlopt_doublevector_pop_back'; - 'nlopt_doublevector_erase'; - 'new_nlopt_doublevector'; - 'nlopt_doublevector_push_back'; - 'nlopt_doublevector_front'; - 'nlopt_doublevector_back'; - 'nlopt_doublevector_assign'; - 'nlopt_doublevector_resize'; - 'nlopt_doublevector_insert'; - 'nlopt_doublevector_reserve'; - 'nlopt_doublevector_capacity'; - 'delete_nlopt_doublevector'; - 'opt_set_lower_bound'; - 'new_opt'; - 'delete_opt'; -]; -addinter(libexamplelib_path + filesep() + 'libexamplelib' + getdynlibext(), 'libexamplelib', list_functions); -// remove temp. variables on stack -clear libexamplelib_path; -clear bOK; -clear ilib; -clear list_functions; -// ---------------------------------------------------------------------------- diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci new file mode 100644 index 000000000..2dce998bc --- /dev/null +++ b/Examples/scilab/vector/runme.sci @@ -0,0 +1,28 @@ +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 int {1, 1}:"); +iv3 = concat_ivector(iv, iv2); +disp(iv3); + + + diff --git a/Lib/scilab/matrix.i b/Lib/scilab/matrix.i index ef04e067f..d36240cd1 100644 --- a/Lib/scilab/matrix.i +++ b/Lib/scilab/matrix.i @@ -1,48 +1,10 @@ -%typemap(in) (double* matrixAsInput, int rows, int cols) { - int *piAddr = NULL; - SciErr sciErr; - sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddr); - if (sciErr.iErr) { - printError(&sciErr, 0); - return 0; - } - sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &$2, &$3, &$1); - if (sciErr.iErr) { - printError(&sciErr, 0); - return 0; - } -} +/* + * Matrix typemaps + * + */ + +%include +%include -%typemap(in,numinputs=0) (double** matrixAsArgOutput,int* rows, int* cols) -{ -} - -%typemap(arginit) (double** matrixAsArgOutput,int* rows, int* cols) -{ - $1=(double**)malloc(16*sizeof(double*)); - $2=(int*)malloc(sizeof(int)); - $3=(int*)malloc(sizeof(int)); -} - -%typemap(freearg) (double** matrixAsArgOutput,int* rows, int* cols) -{ - free(*$1); - free($1); - free($2); - free($3); -} - -%typemap(argout) (double** matrixAsArgOutput,int* rows, int* cols) -{ - SciErr sciErr; - sciErr = createMatrixOfDouble(pvApiCtx, Rhs +$result, *$2, *$3, (double *)*$1); - if (sciErr.iErr) { - printError(&sciErr, 0); - return 0; - } - AssignOutputVariable(pvApiCtx, outputPosition) = Rhs +$result; - -} - diff --git a/Lib/scilab/sciint.swg b/Lib/scilab/sciint.swg index 425e88676..843659dd7 100644 --- a/Lib/scilab/sciint.swg +++ b/Lib/scilab/sciint.swg @@ -1,41 +1,104 @@ /* * C-type: int - * Scilab type: double scalar + * Scilab type: 32-bit signed integer or double scalar */ -%fragment(SWIG_AsVal_frag(int), "header", fragment=SWIG_AsVal_frag(double)) { +%fragment(SWIG_AsVal_frag(int), "header") { SWIGINTERN int -SWIG_AsVal_dec(int)(SciObject _iVar, int *_piValue) { - double dblValue = 0.0; - if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) { +SWIG_AsVal_dec(int)(SciObject _iVar, int *_piValue) +{ + SciErr sciErr; + int iRet = 0; + int *piAddrVar = NULL; + int iPrecision = 0; + int iValue; + + sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); + if (sciErr.iErr) + { + printError(&sciErr, 0); return SWIG_ERROR; } - *_piValue = (int) dblValue; - return SWIG_OK; + + if (!isScalar(pvApiCtx, piAddrVar)) + { + Scierror(999, _("%s: Wrong size for argument %d: a scalar expected.\n"), + SWIG_Scilab_GetFname(),_iVar); + return 999; + } + + // Accepts double or 32-bit signed integer + if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) + { + double dValue = 0.0; + iRet = getScalarDouble(pvApiCtx, piAddrVar, &dValue); + if (iRet) + { + return SWIG_ERROR; + } + + iValue = (int)dValue; + } + else if (isIntegerType(pvApiCtx, piAddrVar)) + { + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrecision); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return sciErr.iErr; + } + + if (iPrecision == SCI_INT32) + { + iRet = getScalarInteger32(pvApiCtx, piAddrVar, &iValue); + } + } + + if (iRet == 0) + { + if (_piValue) + { + *_piValue = iValue; + } + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for argument %d: A 32-bit signed integer or a real expected.\n"), + SWIG_Scilab_GetFname(), _iVar); + return 999; + } } } -%fragment(SWIG_AsVal_frag(size_t), "header", fragment=SWIG_AsVal_frag(double)) { +%fragment(SWIG_AsVal_frag(size_t), "header", fragment=SWIG_AsVal_frag(int)) { SWIGINTERN int -SWIG_AsVal_dec(size_t)(SciObject _iVar, size_t *_piValue) { - double dblValue = 0.0; - if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) { +SWIG_AsVal_dec(size_t)(SciObject _iVar, size_t *_piValue) +{ + int iValue = 0; + if (SWIG_AsVal_dec(int)(_iVar, &iValue) != SWIG_OK) + { return SWIG_ERROR; } - *_piValue = (int) dblValue; + if (_piValue) + { + *_piValue = (size_t) iValue; + } return SWIG_OK; } } %fragment(SWIG_From_frag(int), "header") { SWIGINTERN int -SWIG_From_dec(int)(int _iValue) { +SWIG_From_dec(int)(int _iValue) +{ SciErr sciErr; double dblDoubleValue = (double) _iValue; int iRowsOut = 1; int iColsOut = 1; - int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition(); + int iVarOut = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue); - if (sciErr.iErr) { + if (sciErr.iErr) + { printError(&sciErr, 0); return SWIG_ERROR; } @@ -43,27 +106,17 @@ SWIG_From_dec(int)(int _iValue) { return iVarOut; } } -%fragment(SWIG_From_frag(size_t), "header") { +%fragment(SWIG_From_frag(size_t), "header", fragment=SWIG_From_frag(int)) +{ SWIGINTERN int -SWIG_From_dec(size_t)(size_t _iValue) { - SciErr sciErr; - double dblDoubleValue = (double) _iValue; - int iRowsOut = 1; - int iColsOut = 1; - int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition(); - - sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - return iVarOut; +SWIG_From_dec(size_t)(size_t _iValue) +{ + return SWIG_From_dec(int)((int)_iValue); } } /* - * C-type: int[ANY] - * Scilab type: int32 vector + * C-type: int + * Scilab type: 32-bit signed integer matrix */ %fragment("SWIG_SciInt32_AsIntArrayAndSize", "header") { SWIGINTERN int @@ -74,37 +127,58 @@ SWIG_SciInt32_AsIntArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows, int *_i int *piAddrVar = NULL; sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); - if (sciErr.iErr) { + 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_ints) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer vector expected.\n"), _fname, _iVar); - return SWIG_ERROR; + // Accepts 32-bit signed integer matrix for input + if (isIntegerType(_pvApiCtx, piAddrVar)) + { + sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT32) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer matrix expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _piValue); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + return SWIG_OK; } + else if (isDoubleType(_pvApiCtx, piAddrVar)) + { + double **dblValue; - sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); - if (sciErr.iErr) { - printError(&sciErr, 0); + // Check if input matrix is not empty (empty matrix type is double) + sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, _iRows, _iCols, dblValue); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if ((*_iRows > 0) || (*_iCols > 0)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer matrix expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_piValue = (int*) malloc(sizeof(int*)); + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer matrix expected.\n"), _fname, _iVar); return SWIG_ERROR; } - if (iPrec != SCI_INT32) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer vector expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - - sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _piValue); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - return SWIG_OK; } } diff --git a/Lib/scilab/sciiterators.swg b/Lib/scilab/sciiterators.swg index b5c66b2c2..2a0fcb945 100644 --- a/Lib/scilab/sciiterators.swg +++ b/Lib/scilab/sciiterators.swg @@ -9,7 +9,7 @@ %include -%fragment("SciSwigIterator","header",fragment="") { +%fragment("SciSwigIterator","header",fragment="") { namespace swig { struct stop_iteration { }; @@ -22,7 +22,7 @@ namespace swig { SciSwigIterator(SciObject seq) : _seq(seq) { } - + public: virtual ~SciSwigIterator() {} @@ -44,7 +44,7 @@ namespace swig { { throw std::invalid_argument("operation not supported"); } - + virtual SciSwigIterator *copy() const = 0; SciObject next() @@ -64,12 +64,12 @@ namespace swig { { return (n > 0) ? incr(n) : decr(-n); } - + bool operator == (const SciSwigIterator& x) const { return equal(x); } - + bool operator != (const SciSwigIterator& x) const { return ! operator==(x); @@ -84,7 +84,7 @@ namespace swig { decr(); return this; } - + SciSwigIterator* operator + (ptrdiff_t n) const { return copy()->advance(n); @@ -94,21 +94,21 @@ namespace swig { { return copy()->advance(-n); } - + ptrdiff_t operator - (const SciSwigIterator& x) const { return x.distance(*this); } - + static swig_type_info* descriptor() { static int init = 0; static swig_type_info* desc = 0; if (!init) { desc = SWIG_TypeQuery("swig::SciSwigIterator *"); init = 1; - } + } return desc; - } + } }; } } @@ -120,7 +120,7 @@ namespace swig { { public: typedef OutIterator out_iterator; - typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::value_type value_type; typedef SciSwigIterator_T self_type; SciSwigIterator_T(out_iterator curr, SciObject seq) @@ -133,7 +133,7 @@ namespace swig { return current; } - + bool equal (const SciSwigIterator &iter) const { const self_type *iters = dynamic_cast(&iter); @@ -143,7 +143,7 @@ namespace swig { throw std::invalid_argument("bad iterator type"); } } - + ptrdiff_t distance(const SciSwigIterator &iter) const { const self_type *iters = dynamic_cast(&iter); @@ -152,14 +152,14 @@ namespace swig { } else { throw std::invalid_argument("bad iterator type"); } - } - + } + protected: out_iterator current; }; - + template - struct from_oper + struct from_oper { typedef const ValueType& argument_type; typedef SciObject result_type; @@ -169,7 +169,7 @@ namespace swig { } }; - template::value_type, typename FromOper = from_oper > class SciSwigIteratorOpen_T : public SciSwigIterator_T @@ -180,16 +180,16 @@ namespace swig { typedef ValueType value_type; typedef SciSwigIterator_T base; typedef SciSwigIteratorOpen_T self_type; - + SciSwigIteratorOpen_T(out_iterator curr, SciObject seq) : SciSwigIterator_T(curr, seq) { } - + SciObject value() const { return from(static_cast(*(base::current))); } - + SciSwigIterator *copy() const { return new self_type(*this); @@ -212,7 +212,7 @@ namespace swig { } }; - template::value_type, typename FromOper = from_oper > class SciSwigIteratorClosed_T : public SciSwigIterator_T @@ -221,14 +221,14 @@ namespace swig { FromOper from; typedef OutIterator out_iterator; typedef ValueType value_type; - typedef SciSwigIterator_T base; + typedef SciSwigIterator_T base; typedef SciSwigIteratorClosed_T self_type; - + SciSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, SciObject seq) : SciSwigIterator_T(curr, seq), begin(first), end(last) { } - + SciObject value() const { if (base::current == end) { throw stop_iteration(); @@ -236,7 +236,7 @@ namespace swig { return from(static_cast(*(base::current))); } } - + SciSwigIterator *copy() const { return new self_type(*this); @@ -289,14 +289,15 @@ namespace swig { %fragment("SciSwigIterator"); -namespace swig +namespace swig { // Throw a StopIteration exception %ignore stop_iteration; struct stop_iteration {}; - - %typemap(throws) stop_iteration { - error("stop_iteration exception"); + + %typemap(throws) stop_iteration + { + Scierror(999, "%s: stop_iteration exception", SWIG_Scilab_GetFname()); SWIG_fail; } @@ -332,13 +333,13 @@ namespace swig virtual SciObject value() const = 0; virtual SciSwigIterator *incr(size_t n = 1) = 0; - + virtual SciSwigIterator *decr(size_t n = 1); virtual ptrdiff_t distance(const SciSwigIterator &x) const; virtual bool equal (const SciSwigIterator &x) const; - + virtual SciSwigIterator *copy() const = 0; SciObject next(); diff --git a/Lib/scilab/scimatrixdouble.swg b/Lib/scilab/scimatrixdouble.swg new file mode 100644 index 000000000..52823bf50 --- /dev/null +++ b/Lib/scilab/scimatrixdouble.swg @@ -0,0 +1,180 @@ +/* + * C-type: double array + * Scilab type: double matrix + */ + +%include + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixAsInput, int rows, int cols) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int rows, int cols, double* matrixAsInput) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +%typemap(in) (double* matrixAsInput, int size) +{ + int nbRows; + int nbCols; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + { + $2 = nbRows * nbCols; + } + else + { + return SWIG_ERROR; + } +} + +%typemap(in) (int size, double* matrixAsInput) +{ + int nbRows; + int nbCols; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + { + $1 = nbRows * nbCols; + } + else + { + return SWIG_ERROR; + } +} + +%typemap(in, numinputs=0) (double** matrixAsOutput, int* rows, int* cols) +{ +} + +%typemap(arginit) (double** matrixAsOutput, int* rows, int* cols) +{ + $1 = (double**) malloc(sizeof(double*)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg) (double** matrixAsOutput, int* rows, int* cols) +{ + free(*$1); + free($1); + free($2); + free($3); +} + +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixAsOutput, int* rows, int* cols) +{ + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +// (int* rows, int* cols, double** matrixAsOutput) + +%typemap(in, numinputs=0) (int* rows, int* cols, double** matrixAsOutput) +{ +} + +%typemap(arginit) (int* rows, int* cols, double** matrixAsOutput) +{ + $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) +{ + if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* rows, int* cols, double** matrixAsOutput) +{ + free($1); + free($2); + free(*$3); + free($3); +} + + +// (double** matrixAsOutput, int* size) + +%typemap(in, numinputs=0) (double** matrixAsOutput, int* size) +{ +} + +%typemap(arginit) (double** matrixAsOutput, int* size) +{ + $1 = (double**) malloc(sizeof(double*)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (double** matrixAsOutput, int* size) +{ + + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (double** matrixAsOutput, int* size) +{ + free(*$1); + free($1); + free($2); +} + + +// (int* size, double** matrixAsOutput) + +%typemap(in, numinputs=0) (int* size, double** matrixAsOutput) +{ +} + +%typemap(arginit) (int* size, double** matrixAsOutput) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (double**) malloc(sizeof(double*)); +} + +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, double** matrixAsOutput) +{ + + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* size, double** matrixAsOutput) +{ + free($1); + free(*$2); + free($2); +} diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg new file mode 100644 index 000000000..435f40875 --- /dev/null +++ b/Lib/scilab/scimatrixint.swg @@ -0,0 +1,195 @@ +/* + * C-type: int array + * Scilab type: 32-bit integer matrix + */ + +%include + +// (int* matrixAsInput, int rows, int cols) + +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int* matrixAsInput, int rows, int cols) +{ + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + + +// (int rows, int cols, int* matrixAsInput) + +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int rows, int cols, int* matrixAsInput) +{ + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + + +// (int* matrixAsInput, int size) + +%typemap(in) (int* matrixAsInput, int size) +{ + int nbRows; + int nbCols; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + { + $2 = nbRows * nbCols; + } + else + { + return SWIG_ERROR; + } +} + + +// (int size, int* matrixAsInput) + +%typemap(in) (int size, int* matrixAsInput) +{ + int nbRows; + int nbCols; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + { + $1 = nbRows * nbCols; + } + else + { + return SWIG_ERROR; + } +} + +// (int** matrixAsOutput, int* rows, int* cols) + +%typemap(in, numinputs=0) (int** matrixAsOutput, int* rows, int* cols) +{ +} + +%typemap(arginit) (int** matrixAsOutput, int* rows, int* cols) +{ + $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) +{ + if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int** matrixAsOutput, int* rows, int* cols) +{ + free(*$1); + free($1); + free($2); + free($3); +} + + +// (int* rows, int* cols, int** matrixAsOutput) + +%typemap(in, numinputs=0) (int* rows, int* cols, int** matrixAsOutput) +{ +} + +%typemap(arginit) (int* rows, int* cols, int** matrixAsOutput) +{ + $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) +{ + if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* rows, int* cols, int** matrixAsOutput) +{ + free($1); + free($2); + free(*$3); + free($3); +} + + +// (int** matrixAsOutput, int* size) + +%typemap(in, numinputs=0) (int** matrixAsOutput, int* size) +{ +} + +%typemap(arginit) (int** matrixAsOutput, int* size) +{ + $1 = (int**) malloc(sizeof(int*)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixAsOutput, int* size) +{ + + if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int** matrixAsOutput, int* size) +{ + free(*$1); + free($1); + free($2); +} + + +// (int* size, int** matrixAsOutput) + +%typemap(in, numinputs=0) (int* size, int** matrixAsOutput) +{ +} + +%typemap(arginit) (int* size, int** matrixAsOutput) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (int**) malloc(sizeof(int*)); +} + +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, int** matrixAsOutput) +{ + + if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* size, int** matrixAsOutput) +{ + free($1); + free(*$2); + free($2); +} + diff --git a/Lib/scilab/sciprimtypes.swg b/Lib/scilab/sciprimtypes.swg index c02e2bf16..1d3dce136 100644 --- a/Lib/scilab/sciprimtypes.swg +++ b/Lib/scilab/sciprimtypes.swg @@ -17,59 +17,33 @@ %include %include -%fragment("SwigScilabInt32ToEnum", "header") { +%fragment("SwigScilabInt32ToEnum", "header", fragment=SWIG_AsVal_frag(int)) { SWIGINTERN int -SwigScilabInt32ToEnum(void *_pvApiCtx, int _iVar, int *_enumValue, char* _fname) { - SciErr sciErr; - int iPrec = 0; - int iRows = 1; - int iCols = 1; - int *piAddrVar = NULL; - int *piData = NULL; - - sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); - if (sciErr.iErr) { - printError(&sciErr, 0); +SwigScilabInt32ToEnum(void *_pvApiCtx, int _iVar, int *_enumValue, char* _fname) +{ + int iValue = 0; + if (SWIG_AsVal_dec(int)(_iVar, &iValue) != SWIG_OK) + { return SWIG_ERROR; } - - sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; + if (_enumValue) + { + *_enumValue = iValue; } - if (iPrec != SCI_INT32) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit integer expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - - sciErr = getMatrixOfInteger32(pvApiCtx, piAddrVar, &iRows, &iCols, &piData); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - *_enumValue = (int)piData[0]; - return SWIG_OK; } } %fragment("SwigScilabInt32FromEnum", "header") { SWIGINTERN int -SwigScilabInt32FromEnum(void *_pvApiCtx, int _iVarOut, int _enumValue) { - SciErr sciErr; - int iRowsOut = 1; - int iColsOut = 1; - - sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + _iVarOut, iRowsOut, iColsOut, &_enumValue); - if (sciErr.iErr) { - printError(&sciErr, 0); +SwigScilabInt32FromEnum(void *_pvApiCtx, int _iVarOut, int _enumValue) +{ + int iRet; + iRet = createScalarInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + _iVarOut, _enumValue); + if (iRet) + { return SWIG_ERROR; } - AssignOutputVariable(pvApiCtx, _iVarOut) = nbInputArgument(pvApiCtx) + _iVarOut; - return SWIG_OK; - } } diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index e581e6073..537bb43d5 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -274,6 +274,13 @@ * ----------------------------------------------------------------------------- */ %scilab_varout_typemap(constcode, SwigScilabInt32FromEnum, enum SWIGTYPE); +%typemap(out, fragment="SwigScilabInt32FromEnum") enum SWIGTYPE { + if (SwigScilabInt32FromEnum(pvApiCtx, $result, $1) != SWIG_OK) + { + return SWIG_ERROR; + } +} + /* -----------------------------------------------------------------------------*/ /* Typecheck typemaps */ /* -----------------------------------------------------------------------------*/ diff --git a/Lib/scilab/scivector.i b/Lib/scilab/scivector.i deleted file mode 100644 index 42abfe1e5..000000000 --- a/Lib/scilab/scivector.i +++ /dev/null @@ -1,64 +0,0 @@ -/* - Vectors typemaps -*/ - -// Typemap for input arguments of type const std::vector & -%typecheck(SWIG_TYPECHECK_POINTER) - const std::vector & -{ - // TODO -} -%typemap(in) - const std::vector & -(int is_new_object=0, std::vector arrayv) -{ - { - SciErr sciErr; - int iRows = 0; - int iCols = 0; - int *piAddrVar = NULL; - double *pdblTmp = NULL; - - /* Scilab value must be a double vector */ - sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) { - sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - } else { - Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - if ((iRows!=1) && (iCols!=1)) { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - /* Copy vector contents into new allocated std::vector */ - arrayv = std::vector(iRows*iCols); - $1 = &arrayv; - { - int arr_i = 0; - for (arr_i = 0; arr_i < iRows*iCols; ++arr_i) - arrayv[arr_i] = pdblTmp[arr_i]; - } - } -} -%typemap(freearg) - const std::vector & -{ - // TODO -} - -// Typemap for return values of type std::vector -%typemap(out) std::vector -{ - // TODO -} diff --git a/Lib/scilab/scivectordouble.swg b/Lib/scilab/scivectordouble.swg new file mode 100644 index 000000000..ee7e7b4ff --- /dev/null +++ b/Lib/scilab/scivectordouble.swg @@ -0,0 +1,94 @@ +/* + * 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& +{ + 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 new file mode 100644 index 000000000..3cc9dd0d5 --- /dev/null +++ b/Lib/scilab/scivectorint.swg @@ -0,0 +1,91 @@ +/* + * 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& +{ + 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 new file mode 100644 index 000000000..305f11424 --- /dev/null +++ b/Lib/scilab/scivectorstring.swg @@ -0,0 +1,94 @@ +/* + * 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& +{ + 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/std_set.i b/Lib/scilab/std_set.i new file mode 100644 index 000000000..0299e47b6 --- /dev/null +++ b/Lib/scilab/std_set.i @@ -0,0 +1,84 @@ +/* + * C++ type: std::set + * Scilab 5 type: integer matrix + */ + +%include + +%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())); + } +} + +%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); + + 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; + } +} + diff --git a/Lib/scilab/std_vector.i b/Lib/scilab/std_vector.i index f1dcd812e..cc44831d0 100644 --- a/Lib/scilab/std_vector.i +++ b/Lib/scilab/std_vector.i @@ -10,7 +10,7 @@ return traits_asptr_stdseq >::asptr(obj, vec); } }; - + template struct traits_from > { static SciObject *from(const std::vector& vec) { @@ -23,66 +23,9 @@ #define %swig_vector_methods(Type...) %swig_sequence_methods(Type) #define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); -// Typemap for input arguments of type const std::vector & -%typecheck(SWIG_TYPECHECK_POINTER) - const std::vector & -{ - // TODO -} -%typemap(in) - const std::vector & -(int is_new_object=0, std::vector arrayv) -{ - { - SciErr sciErr; - int iRows = 0; - int iCols = 0; - int *piAddrVar = NULL; - double *pdblTmp = NULL; - /* Scilab value must be a double vector */ - sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) { - sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - } else { - Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - if ((iRows!=1) && (iCols!=1)) { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - /* Copy vector contents into new allocated std::vector */ - arrayv = std::vector(iRows*iCols); - $1 = &arrayv; - { - int arr_i = 0; - for (arr_i = 0; arr_i < iRows*iCols; ++arr_i) - arrayv[arr_i] = pdblTmp[arr_i]; - } - } -} -%typemap(freearg) - const std::vector & -{ - // TODO -} - -// Typemap for return values of type std::vector -%typemap(out) std::vector -{ - // TODO -} +%include +%include %include diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 4d848b6cd..841d63191 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -35,7 +35,7 @@ protected: String *builderCode; int builderFunctionCount; - String *sourceFile; + List *sourceFileList; String *cflag; String *ldflag; @@ -45,7 +45,7 @@ public: * ----------------------------------------------------------------------*/ virtual void main(int argc, char* argv[]) { - sourceFile = NULL; + sourceFileList = NewList(); ldflag = NULL; cflag = NULL; @@ -58,9 +58,14 @@ public: /* Indicate arg as valid */ Swig_mark_arg(argIndex); } else if (strcmp(argv[argIndex], "-addsrc") == 0) { - Swig_mark_arg(argIndex); if (argv[argIndex+1] != NULL) { - sourceFile = NewString(argv[argIndex+1]); + Swig_mark_arg(argIndex); + char *sourceFile = strtok(argv[argIndex+1], " "); + while (sourceFile != NULL) + { + DohInsertitem(sourceFileList, Len(sourceFileList), sourceFile); + sourceFile = strtok(NULL, " "); + } Swig_mark_arg(argIndex+1); } } else if (strcmp(argv[argIndex], "-addcflag") == 0) { @@ -138,10 +143,6 @@ public: Printf(builderCode, "ilib_verbose(0);\n"); #endif Printf(builderCode, "ilib_name = \"%slib\";\n", moduleName); - Printf(builderCode, "files = \"%s\";\n", outputFilename); - if (sourceFile != NULL) { - Printf(builderCode, "files($+1) = \"%s\";\n", sourceFile); - } Printf(builderCode, "libs = [];\n"); if (ldflag != NULL) { @@ -149,12 +150,28 @@ public: } else { Printf(builderCode, "ldflags = \"\";\n"); } + Printf(builderCode, "cflags = [\"-g -I\" + get_absolute_file_path(\"builder.sce\")];\n"); if (cflag != NULL) { Printf(builderCode, "includepath = \"%s\";\n", cflag); Printf(builderCode, "includepath = fullpath(part(includepath, 3:length(includepath)));\n"); Printf(builderCode, "cflags = cflags + \" -I\" + includepath;\n"); } + + DohInsertitem(sourceFileList, 0, outputFilename); + for (int i=0; i