swig/Lib/scilab/sciunsignedshort.swg
2014-07-10 12:18:41 +02:00

197 lines
5.9 KiB
Text

/*
* C-type: unsigned short
* Scilab type: double or uint16 scalar
*/
%fragment(SWIG_AsVal_frag(unsigned short), "header", fragment="SWIG_SciUint16_AsUnsignedShort", fragment="<limits.h>") {
%#define SWIG_AsVal_unsigned_SS_short(scilabValue, valuePointer) SWIG_SciUint16_AsUnsignedShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname())
}
%fragment("SWIG_SciUint16_AsUnsignedShort", "header") {
SWIGINTERN int
SWIG_SciUint16_AsUnsignedShort(void *_pvApiCtx, int iVar, unsigned short *pusValue, char *fname) {
SciErr sciErr;
int iType = 0;
int iRows = 0;
int iCols = 0;
int iPrec = 0;
int *piAddrVar = NULL;
unsigned short *pusData = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, iVar, &piAddrVar);
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) {
if (pusValue) {
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT16) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), fname, iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, &iRows, &iCols, &pusData);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), fname, iVar);
return SWIG_ERROR;
}
*pusValue = *pusData;
}
}
else if (iType == sci_matrix) {
if (pusValue) {
double *pdData = NULL;
double dValue = 0.0f;
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 16-bit unsigned integer or a double expected.\n"), fname, iVar);
return SWIG_TypeError;
}
dValue = *pdData;
if (dValue != floor(dValue)) {
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 16-bit unsigned integer.\n"), fname, iVar);
return SWIG_ValueError;
}
if ((dValue < 0) || (dValue > USHRT_MAX)) {
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 16-bit unsigned integer.\n"), fname, iVar);
return SWIG_OverflowError;
}
*pusValue = (unsigned short) dValue;
}
}
else {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), fname, iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment(SWIG_From_frag(unsigned short), "header", fragment="SWIG_SciUint16_FromUnsignedShort") {
%#define SWIG_From_unsigned_SS_short(scilabValue) SWIG_SciUint16_FromUnsignedShort(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFname())
}
%fragment("SWIG_SciUint16_FromUnsignedShort", "header") {
SWIGINTERN int
SWIG_SciUint16_FromUnsignedShort(void *_pvApiCtx, int iVarOut, unsigned short usValue, char *fname) {
if (createScalarDouble(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + iVarOut, (double) usValue))
return SWIG_ERROR;
return SWIG_OK;
}
}
/*
* C-type: unsigned short[]
* Scilab type: uint16 vector
*/
%fragment("SWIG_SciUint16_AsUnsignedShortArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint16_AsUnsignedShortArrayAndSize(void *_pvApiCtx, int iVar, int *iRows, int *iCols, unsigned short **pusValue, char *fname) {
SciErr sciErr;
int iType = 0;
int iPrec = 0;
int *piAddrVar = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, iVar, &piAddrVar);
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_matrix)
{
double *pdData = NULL;
int size = 0;
int i;
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, iRows, iCols, &pdData);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
size = (*iRows) * (*iCols);
*pusValue = (unsigned short*) malloc(size * sizeof(int*));
for (i = 0; i < size; i++)
(*pusValue)[i] = (unsigned short) pdData[i];
}
else if (iType == sci_ints)
{
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT16)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double vector expected.\n"), fname, iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, iRows, iCols, pusValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double vector expected.\n"), fname, iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciUint16_FromUnsignedShortArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint16_FromUnsignedShortArrayAndSize(void *_pvApiCtx, int iVarOut, int iRows, int iCols, unsigned short *pusValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
pdValues = (double*) malloc(iRows * iCols * sizeof(double));
for (i=0; i<iRows * iCols; i++)
pdValues[i] = pusValues[i];
sciErr = createMatrixOfDouble(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + iVarOut, iRows, iCols, pdValues);
if (sciErr.iErr)
{
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}