Fix int scalar typemap (do not base on double typemap)
This commit is contained in:
parent
e667d59ed9
commit
46a234ed8f
1 changed files with 83 additions and 30 deletions
|
|
@ -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,22 +106,12 @@ 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);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue