Merge pull request #57 from smarchetto/gsoc2012-scilab

Improvement of the swig-scilab support: brings typemaps, examples, and build fixes
This commit is contained in:
Sylvestre Ledru 2013-06-06 00:35:04 -07:00
commit 318572471c
35 changed files with 1319 additions and 539 deletions

View file

@ -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

View file

@ -1,32 +1,39 @@
#include <stdlib.h>
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<nbRow*nbCol; i++)
{
total += inputMatrix[i];
}
return total;
}
void sumitems_argoutput(double *first, int nbRow, int nbCol,double** result,int* nbrowres,int* nbcolsres) {
void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double** resultMatrix, int* nbRowRes, int* nbColRes)
{
int i;
*nbrowres=nbRow;
*nbcolsres=nbCol;
*result=malloc(nbRow*nbCol*sizeof(double));
for (i=0; i<(nbRow*nbCol); i++) {
(*result)[i]=first[i]+first[i];
int size = nbRow * nbCol;
*nbRowRes = nbRow;
*nbColRes = nbCol;
*resultMatrix = (double*) malloc(size * sizeof(double));
for (i=0; i<size; i++)
{
(*resultMatrix)[i] = inputMatrix[i] * inputMatrix[i];
}
return;
}
double* getValues(int *numberOfRow, int *numberOfCol) {
double *tempMatrix ;
void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes)
{
int i;
*numberOfRow=23; *numberOfCol=3;
tempMatrix= (double*)malloc(sizeof(double )* *numberOfRow * *numberOfCol);
for (i=0; i<((*numberOfRow)*(*numberOfCol)); i++) {
tempMatrix[i]=i*2;
int size;
*nbRowRes = 5;
*nbColRes = 3;
size = (*nbRowRes) * (*nbColRes);
*resultMatrix = (double*) malloc(size * sizeof(double));
for (i=0; i<size; i++)
{
(*resultMatrix)[i] = i*2;
}
return tempMatrix;
}

View file

@ -1,42 +1,15 @@
%module matrixlib
%include matrix.i
%apply (double *matrixAsInput, int rows, int cols) { (double *inputMatrix, int nbRow, int nbCol) }
%apply (double **matrixAsOutput, int *rows, int *cols) { (double **resultMatrix, int *nbRowRes, int *nbColRes) }
%apply (double* matrixAsInput,int rows,int cols){(double *first, int nbRow, int nbCol)}
%apply (double** matrixAsArgOutput,int* rows,int* cols){(double **result,int* nbRowOut,int* nbColOut)}
%typemap(out) (double*)(int *nRow, int *nCol)
%inline
{
SciErr sciErr;
sciErr = createMatrixOfDouble(pvApiCtx, Rhs+$result, *nRow, *nCol, (double *)$1);
if (sciErr.iErr) {
printError(&sciErr, 0);
return 0;
}
AssignOutputVariable(pvApiCtx, outputPosition) = Rhs+$result;
free($1);
}
%typemap (in,numinputs=0) (int *numberOfRow, int *numberOfCol)
{
}
%typemap(arginit) (int *numberOfRow, int *numberOfCol)
{
$1 =(int*)malloc(sizeof(int));
$2 =(int*)malloc(sizeof(int));
nRow =$1;
nCol =$2;
}
%typemap(freearg) (int *numberOfRow, int *numberOfCol)
{
free($1);
free($2);
}
%inline {
extern void sumitems_argoutput(double *first, int nbRow, int nbCol,double **result,int* nbRowOut,int* nbColOut);
extern double* getValues(int *numberOfRow, int *numberOfCol);
extern double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol);
extern void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes);
extern void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes);
}

View file

@ -1,9 +1,14 @@
// loader the *.so
exec loader.sce
myMatrix=[ 103 3 1 12;0 0 2043 1];
m=sumitems_argoutput(myMatrix)
myOtherMatrix=getValues();
size(myOtherMatrix)
disp(myOtherMatrix);
exit
disp("Call lib function getMatrix()");
matrix1 = getMatrix();
disp(matrix1);
disp("Call lib function sumMatrixElements()");
s = sumMatrixElements(matrix1);
disp(s);
disp("Call lib function squareMatrixElements()");
squareMatrix = squareMatrixElements(matrix1);
disp(squareMatrix);

View file

@ -1,81 +0,0 @@
#include "api_scilab.h"
double sumitems(double *first, int nbRow, int nbCol);
double* getValues(int *numberOfRow, int *numberOfCol);
int sci_sumitems(char *fname,unsigned long fname_len)
{
int iRows = 0;
int iCols = 0;
int *piAddr = NULL;
double* pdblReal = NULL;
CheckInputArgument(pvApiCtx, 1, 1);
CheckOutputArgument(pvApiCtx, 1, 1);
SciErr sciErr;
//get variable address of the first input argument
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
double plop = sumitems(pdblReal, iRows, iCols);
/*
* Here, it is a scalar but it could be also a matrix... don't assume it
* it will be always 1x1
*/
int iRowsReturn=1;
int iColReturn=1;
sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, iRowsReturn, iColReturn, &plop);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
return 0;
}
int sci_getValues(char *fname,unsigned long fname_len)
{
int iRows = 0;
int iCols = 0;
int *piAddr = NULL;
double* pdblReal = NULL;
CheckInputArgument(pvApiCtx, 0, 0);
CheckOutputArgument(pvApiCtx, 1, 1);
SciErr sciErr;
int numberRow, numberCol, i;
double * matrix = getValues(&numberRow, &numberCol);
sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, numberRow, numberCol, matrix);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
return 0;
}

View file

@ -0,0 +1,16 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.cpp
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.cxx
check: all
$(MAKE) -f $(TOP)/Makefile scilab_run

View file

@ -0,0 +1,29 @@
/* File : example.cpp */
#include "example.hxx"
std::set<int> create_iset(const int size, const int* values)
{
std::set<int> iset;
std::copy(values, values + size, std::inserter(iset, iset.begin()));
return iset;
}
int sum_iset(const std::set<int> iset)
{
int sum = 0;
std::set<int>::iterator it;
for (it = iset.begin(); it != iset.end(); it++)
{
sum += *it;
}
return sum;
}
void concat_iset(std::set<int>& iset, const std::set<int> other_iset)
{
std::copy(other_iset.begin(), other_iset.end(), std::inserter(iset, iset.begin()));
}

View file

@ -0,0 +1,13 @@
/* File : example.hxx */
#include <set>
std::set<int> create_iset(const int size, const int* values);
int sum_iset(const std::set<int> iset);
void concat_iset(std::set<int>& iset, const std::set<int> other_iset);

View file

@ -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";

View file

@ -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);

View file

@ -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

View file

@ -0,0 +1,43 @@
/* File : example.c */
#include "example.h"
#define M_PI 3.14159265358979323846
template<typename T>
void Shape<T>::move(T dx, T dy) {
x += dx;
y += dy;
}
template<typename T>
int Shape<T>::nbshapes = 0;
template<typename T>
int Shape<T>::getNbShapes() {
return Shape<T>::nbshapes;
}
template<typename T>
T Circle<T>::area() {
return M_PI*radius*radius;
}
template<typename T>
T Circle<T>::perimeter() {
return 2*M_PI*radius;
}
template<typename T>
T Square<T>::area() {
return width*width;
}
template<typename T>
T Square<T>::perimeter() {
return 4*width;
}
template class Shape<double>;
template class Square<double>;
template class Circle<double>;

View file

@ -0,0 +1,36 @@
/* File : example.h */
template<typename T>
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<typename T>
class Circle : public Shape<T> {
private:
T radius;
public:
Circle(T r) : Shape<T>() { radius = r; };
virtual T area();
virtual T perimeter();
};
template<typename T>
class Square : public Shape<T> {
private:
T width;
public:
Square(T w) : Shape<T>() { width = w; };
virtual T area();
virtual T perimeter();
};

View file

@ -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<double>;
%template(CircleDouble) Circle<double>;
%template(SquareDouble) Square<double>;

View file

@ -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());

View file

@ -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

View file

@ -1,19 +1,47 @@
/* File : example.cpp */
#include <iostream>
#include <vector>
#include "example.hxx"
class opt {
public:
void set_lower_bound(const std::vector<double> &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<double> create_dvector(const int size, const double value)
{
return std::vector<double>(size, value);
}
std::vector<int> create_ivector(const int size, const int value)
{
return std::vector<int>(size, value);
}
double sum_dvector(const std::vector<double> dvector)
{
double sum = 0;
for (int i = 0; i < dvector.size(); i++)
{
sum += dvector[i];
}
};
return sum;
}
int sum_ivector(const std::vector<int> ivector)
{
int sum = 0;
for (int i = 0; i < ivector.size(); i++)
{
sum += ivector[i];
}
return sum;
}
void concat_dvector(std::vector<double>& dvector, const std::vector<double> other_dvector)
{
dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end());
}
void concat_ivector(std::vector<int>& ivector, const std::vector<int> other_ivector)
{
ivector.insert(ivector.end(), other_ivector.begin(), other_ivector.end());
}

View file

@ -1,18 +1,16 @@
/* File : example.cpp */
/* File : example.hxx */
#include <vector>
namespace nlopt {
class opt {
public:
void set_lower_bound(const std::vector<double> &v) {
double sum = 0;
for (int i = 0; i < v.size(); i++) {
sum += v[i];
}
//return sum;
}
};
}
std::vector<double> create_dvector(const int size, const double value);
std::vector<int> create_ivector(const int size, const int value);
double sum_dvector(const std::vector<double> dvector);
int sum_ivector(const std::vector<int> ivector);
void concat_dvector(std::vector<double>& dvector, const std::vector<double> other_dvector);
void concat_ivector(std::vector<int>& ivector, const std::vector<int> other_ivector);

View file

@ -1,4 +1,5 @@
/* File : example.i */
%module example
%{
@ -6,8 +7,5 @@
%}
%include "std_vector.i"
namespace std {
%template(nlopt_doublevector) vector<double>;
};
%include "example.hxx";

View file

@ -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;
// ----------------------------------------------------------------------------

View file

@ -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);

View file

@ -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 <scimatrixdouble.swg>
%include <scimatrixint.swg>
%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;
}

View file

@ -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;
}
}

View file

@ -9,7 +9,7 @@
%include <std_common.i>
%fragment("SciSwigIterator","header",fragment="<stddef.h>") {
%fragment("SciSwigIterator","header",fragment="<stddef.h>") {
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<out_iterator>::value_type value_type;
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
typedef SciSwigIterator_T<out_iterator> 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<const self_type *>(&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<const self_type *>(&iter);
@ -152,14 +152,14 @@ namespace swig {
} else {
throw std::invalid_argument("bad iterator type");
}
}
}
protected:
out_iterator current;
};
template <class ValueType>
struct from_oper
struct from_oper
{
typedef const ValueType& argument_type;
typedef SciObject result_type;
@ -169,7 +169,7 @@ namespace swig {
}
};
template<typename OutIterator,
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SciSwigIteratorOpen_T : public SciSwigIterator_T<OutIterator>
@ -180,16 +180,16 @@ namespace swig {
typedef ValueType value_type;
typedef SciSwigIterator_T<out_iterator> base;
typedef SciSwigIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
SciSwigIteratorOpen_T(out_iterator curr, SciObject seq)
: SciSwigIterator_T<OutIterator>(curr, seq)
{
}
SciObject value() const {
return from(static_cast<const value_type&>(*(base::current)));
}
SciSwigIterator *copy() const
{
return new self_type(*this);
@ -212,7 +212,7 @@ namespace swig {
}
};
template<typename OutIterator,
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SciSwigIteratorClosed_T : public SciSwigIterator_T<OutIterator>
@ -221,14 +221,14 @@ namespace swig {
FromOper from;
typedef OutIterator out_iterator;
typedef ValueType value_type;
typedef SciSwigIterator_T<out_iterator> base;
typedef SciSwigIterator_T<out_iterator> base;
typedef SciSwigIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
SciSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, SciObject seq)
: SciSwigIterator_T<OutIterator>(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<const value_type&>(*(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();

View file

@ -0,0 +1,180 @@
/*
* C-type: double array
* Scilab type: double matrix
*/
%include <scidouble.swg>
%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);
}

195
Lib/scilab/scimatrixint.swg Normal file
View file

@ -0,0 +1,195 @@
/*
* C-type: int array
* Scilab type: 32-bit integer matrix
*/
%include <sciint.swg>
// (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);
}

View file

@ -17,59 +17,33 @@
%include <scipointer.swg>
%include <scibool.swg>
%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;
}
}

View file

@ -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 */
/* -----------------------------------------------------------------------------*/

View file

@ -1,64 +0,0 @@
/*
Vectors typemaps
*/
// Typemap for input arguments of type const std::vector<double> &
%typecheck(SWIG_TYPECHECK_POINTER)
const std::vector<double> &
{
// TODO
}
%typemap(in)
const std::vector<double> &
(int is_new_object=0, std::vector<double> arrayv)
{
{
SciErr sciErr;
int iRows = 0;
int iCols = 0;
int *piAddrVar = NULL;
double *pdblTmp = NULL;
/* Scilab value must be a double vector */
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) {
sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
} else {
Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
if ((iRows!=1) && (iCols!=1)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
/* Copy vector contents into new allocated std::vector<double> */
arrayv = std::vector<double>(iRows*iCols);
$1 = &arrayv;
{
int arr_i = 0;
for (arr_i = 0; arr_i < iRows*iCols; ++arr_i)
arrayv[arr_i] = pdblTmp[arr_i];
}
}
}
%typemap(freearg)
const std::vector<double> &
{
// TODO
}
// Typemap for return values of type std::vector<double>
%typemap(out) std::vector<double>
{
// TODO
}

View file

@ -0,0 +1,94 @@
/*
* C++ type: std::vector<double>
* Scilab 5 type: double matrix
*/
%include <scidouble.swg>
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<double>(std::vector<double> temp)
{
double* dmatrix;
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = temp;
$1.reserve(nbRows * nbCols);
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector<double>&)$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<double>&(std::vector<double> temp)
{
double* dmatrix;
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = &temp;
$1->reserve(nbRows * nbCols);
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<double>
{
int nbCols = $1.size();
double* dmatrix = new double[nbCols];
std::copy($1.begin(), $1.end(), dmatrix);
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
delete[] dmatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}
%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<double>&
{
int nbCols = $1->size();
double* dmatrix = new double[nbCols];
std::copy($1->begin(), $1->end(), dmatrix);
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
delete[] dmatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

View file

@ -0,0 +1,91 @@
/*
* C++ type: std::vector<int>
* Scilab 5 type: integer matrix
*/
%include <sciint.swg>
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector<int>(std::vector<int> temp)
{
int* imatrix;
int nbRows;
int nbCols;
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = temp;
$1.reserve(nbRows * nbCols);
std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter((std::vector<int>&)$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector<int>&(std::vector<int> temp)
{
int* imatrix;
int nbRows;
int nbCols;
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = &temp;
$1->reserve(nbRows * nbCols);
std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter(*$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector<int>
{
int nbCols = $1.size();
int* imatrix = new int[nbCols];
std::copy($1.begin(), $1.end(), imatrix);
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
delete[] imatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}
%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector<int>&
{
int nbCols = $1->size();
int* imatrix = new int[nbCols];
std::copy($1->begin(), $1->end(), imatrix);
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
delete[] imatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

View file

@ -0,0 +1,94 @@
/*
* C++ type: std::vector<string>
* Scilab 5 type: double matrix
*/
%include <scidouble.swg>
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>(std::vector<string> temp)
{
double* dmatrix;
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = temp;
$1.reserve(nbRows * nbCols);
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector<string>&)$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector<string>&(std::vector<string> temp)
{
double* dmatrix;
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = &temp;
$1->reserve(nbRows * nbCols);
std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1));
}
else
{
return SWIG_ERROR;
}
}
%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>
{
int nbCols = $1.size();
double* dmatrix = new double[nbCols];
std::copy($1.begin(), $1.end(), dmatrix);
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
delete[] dmatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}
%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector<string>&
{
int nbCols = $1->size();
double* dmatrix = new double[nbCols];
std::copy($1->begin(), $1->end(), dmatrix);
int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix);
delete[] dmatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

84
Lib/scilab/std_set.i Normal file
View file

@ -0,0 +1,84 @@
/*
* C++ type: std::set<int>
* Scilab 5 type: integer matrix
*/
%include <sciint.swg>
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set<int>(std::set<int> temp)
{
int* imatrix;
int nbRows;
int nbCols;
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = temp;
std::set<int>& tmpset = (std::set<int>&)$1;
std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin()));
}
}
%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set<int>& (std::set<int> temp)
{
int* imatrix;
int nbRows;
int nbCols;
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR)
{
if ((nbRows > 1) && (nbCols > 1))
{
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
$1 = &temp;
std::set<int>& tmpset = *$1;
std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin()));
}
}
%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::set<int>
{
int nbCols = $1.size();
int* imatrix = new int[nbCols];
std::copy($1.begin(), $1.end(), imatrix);
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
delete[] imatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}
%typemap(argout) std::set<int>&
{
int nbCols = $1->size();
int* imatrix = new int[nbCols];
std::copy($1->begin(), $1->end(), imatrix);
int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix);
delete[] imatrix;
if (ret != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

View file

@ -10,7 +10,7 @@
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
}
};
template <class T>
struct traits_from<std::vector<T> > {
static SciObject *from(const std::vector<T>& vec) {
@ -23,66 +23,9 @@
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
// Typemap for input arguments of type const std::vector<double> &
%typecheck(SWIG_TYPECHECK_POINTER)
const std::vector<double> &
{
// TODO
}
%typemap(in)
const std::vector<double> &
(int is_new_object=0, std::vector<double> arrayv)
{
{
SciErr sciErr;
int iRows = 0;
int iCols = 0;
int *piAddrVar = NULL;
double *pdblTmp = NULL;
/* Scilab value must be a double vector */
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) {
sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdblTmp);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
} else {
Scierror(999, _("%s: Wrong type for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
if ((iRows!=1) && (iCols!=1)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input);
return SWIG_ERROR;
}
/* Copy vector contents into new allocated std::vector<double> */
arrayv = std::vector<double>(iRows*iCols);
$1 = &arrayv;
{
int arr_i = 0;
for (arr_i = 0; arr_i < iRows*iCols; ++arr_i)
arrayv[arr_i] = pdblTmp[arr_i];
}
}
}
%typemap(freearg)
const std::vector<double> &
{
// TODO
}
// Typemap for return values of type std::vector<double>
%typemap(out) std::vector<double>
{
// TODO
}
%include <scivectordouble.swg>
%include <scivectorint.swg>
%include <std/std_vector.i>

View file

@ -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<Len(sourceFileList); i++)
{
String* sourceFile = Getitem(sourceFileList, i);
if (i==0)
{
Printf(builderCode, "files = \"%s\";\n", sourceFile);
}
else
{
Printf(builderCode, "files($ + 1) = \"%s\";\n", sourceFile);
}
}
Printf(builderCode, "table = [");
/* Emit code for children */