Vectors ...

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12708 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2011-05-23 12:48:02 +00:00
commit f7107bfea8

View file

@ -1,10 +1,84 @@
%fragment("StdVectorTraits","header")
%{
#include <vector>
%}
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
namespace std {
template<class T> class vector {
%define SCILAB_STD_VECTOR_IN(T, TYPECHECKINGFUNCTION, TEMPTYPE, READFUNCTIONNAME)
%typemap(in) vector<T> {
SciErr sciErr;
int *piAddrVar = NULL;
int *piChild = NULL;
int iType = 0;
int iNumberOfItem = 0;
TEMPTYPE *tempValue = NULL;
int iRows = 0;
int iCols = 0;
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
/* Check input type */
sciErr = getVarType(pvApiCtx, piAddrVar, &iType);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_list) {
Scierror(999, _("%s: Wrong type for input argument #%d: A list expected.\n"), fname, $argnum);
return 0;
}
/* Get list size */
sciErr = getListItemNumber(pvApiCtx, piAddrVar, &iNumberOfItem);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
$1 = std::vector<T>(iNumberOfItem);
for (unsigned int i=0; i<iNumberOfItem; i++) {
sciErr = getListItemAddress(pvApiCtx, piAddrVar, i + 1, &piChild);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (!TYPECHECKINGFUNCTION(pvApiCtx, piChild)) {
Scierror(999, _("%s: Wrong type for item #%d: A real scalar expected.\n"), fname, i + 1);
return 0;
}
sciErr = READFUNCTIONNAME(pvApiCtx, piAddrVar, i + 1, &iRows, &iCols, &tempValue);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for item #%d: A real scalar expected.\n"), fname, i + 1);
return 0;
}
(($1_type &)$1)[i] = (T)*tempValue;
}
}
%enddef
%typemap(out) vector<T>* {
/* %typemap(out) vector<T>* */
SciErr sciErr;
int *piAddrVar = NULL;
sciErr = createList(pvApiCtx, Rhs + $result, 0, &piAddrVar);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
SwigScilabSetOutput(1, Rhs + $result);
}
SCILAB_STD_VECTOR_IN(double, isDoubleType, double, getMatrixOfDoubleInList);
SCILAB_STD_VECTOR_IN(int, isDoubleType, double, getMatrixOfDoubleInList);
};
}
%include <std/std_vector.i>