scilab: optimize typemap AsInt
This commit is contained in:
parent
a8d020f171
commit
7f14aa583a
1 changed files with 46 additions and 45 deletions
|
|
@ -11,66 +11,67 @@ SWIGINTERN int
|
||||||
SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue, char *_fname)
|
SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue, char *_fname)
|
||||||
{
|
{
|
||||||
SciErr sciErr;
|
SciErr sciErr;
|
||||||
int iRet = 0;
|
int iType = 0;
|
||||||
|
int iRows = 0;
|
||||||
|
int iCols = 0;
|
||||||
int *piAddrVar = NULL;
|
int *piAddrVar = NULL;
|
||||||
int iPrecision = 0;
|
|
||||||
int iValue;
|
|
||||||
|
|
||||||
sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar);
|
sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar);
|
||||||
if (sciErr.iErr)
|
if (sciErr.iErr) {
|
||||||
{
|
|
||||||
printError(&sciErr, 0);
|
printError(&sciErr, 0);
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isScalar(_pvApiCtx, piAddrVar))
|
sciErr = getVarType(_pvApiCtx, piAddrVar, &iType);
|
||||||
{
|
if (sciErr.iErr) {
|
||||||
Scierror(999, _("%s: Wrong size for argument %d: a scalar expected.\n"),
|
printError(&sciErr, 0);
|
||||||
SWIG_Scilab_GetFname(),_iVar);
|
return SWIG_ERROR;
|
||||||
return 999;
|
|
||||||
}
|
}
|
||||||
|
if (iType == sci_ints) {
|
||||||
|
int iPrec = 0;
|
||||||
|
int *piData = NULL;
|
||||||
|
|
||||||
// Accepts double or 32-bit signed integer
|
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
|
||||||
if (isDoubleType(_pvApiCtx, piAddrVar) && !isVarComplex(_pvApiCtx, piAddrVar))
|
if (sciErr.iErr) {
|
||||||
{
|
printError(&sciErr, 0);
|
||||||
double dValue = 0.0;
|
return SWIG_ERROR;
|
||||||
iRet = getScalarDouble(_pvApiCtx, piAddrVar, &dValue);
|
}
|
||||||
if (iRet)
|
if (iPrec != SCI_INT32) {
|
||||||
{
|
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar);
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
iValue = (int)dValue;
|
sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &piData);
|
||||||
}
|
if (sciErr.iErr) {
|
||||||
else if (isIntegerType(pvApiCtx, piAddrVar))
|
|
||||||
{
|
|
||||||
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrecision);
|
|
||||||
if (sciErr.iErr)
|
|
||||||
{
|
|
||||||
printError(&sciErr, 0);
|
printError(&sciErr, 0);
|
||||||
return sciErr.iErr;
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
if (iRows * iCols != 1) {
|
||||||
|
Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
*_piValue = *piData;
|
||||||
|
}
|
||||||
|
else if (iType == sci_matrix) {
|
||||||
|
double *pdData = NULL;
|
||||||
|
|
||||||
|
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
|
||||||
|
if (sciErr.iErr) {
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
if (iRows * iCols != 1) {
|
||||||
|
Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
*_piValue = (int) *pdData;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar);
|
||||||
|
return SWIG_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iPrecision == SCI_INT32)
|
|
||||||
{
|
|
||||||
iRet = getScalarInteger32(_pvApiCtx, piAddrVar, &iValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iRet == 0)
|
|
||||||
{
|
|
||||||
if (_piValue)
|
|
||||||
{
|
|
||||||
*_piValue = iValue;
|
|
||||||
}
|
|
||||||
return SWIG_OK;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue