Scilab: refactor enum typemap

This commit is contained in:
Simon Marchetto 2013-09-27 10:30:12 +02:00
commit 8626d96aff
3 changed files with 35 additions and 37 deletions

29
Lib/scilab/scienum.swg Normal file
View file

@ -0,0 +1,29 @@
/*
* C-type: enum
* Scilab type: int32
*/
%fragment("SWIG_SciInt32_AsEnum", "header", fragment="SWIG_SciInt32_AsInt") {
SWIGINTERN int
SWIG_SciInt32_AsEnum(void *_pvApiCtx, int _iVar, int *_enumValue, char *_fname)
{
int iValue = 0;
if (SWIG_SciInt32_AsInt(_pvApiCtx, _iVar, &iValue, _fname) != SWIG_OK)
{
return SWIG_ERROR;
}
if (_enumValue)
{
*_enumValue = iValue;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciInt32_FromEnum", "header", fragment="SWIG_SciInt32_FromInt") {
SWIGINTERN int
SWIG_SciInt32_FromEnum(void *_pvApiCtx, int _iVarOut, int _enumValue, char *_fname)
{
return SWIG_SciInt32_FromInt(_pvApiCtx, _iVarOut, _enumValue, _fname);
}
}

View file

@ -19,33 +19,3 @@
%include <scipointer.swg>
%include <scibool.swg>
%fragment("SwigScilabInt32ToEnum", "header", fragment=SWIG_AsVal_frag(int)) {
SWIGINTERN int
SwigScilabInt32ToEnum(void *_pvApiCtx, int _iVar, int *_enumValue, char* _fname)
{
int iValue = 0;
if (SWIG_AsVal_dec(int)(_iVar, &iValue) != SWIG_OK)
{
return SWIG_ERROR;
}
if (_enumValue)
{
*_enumValue = iValue;
}
return SWIG_OK;
}
}
%fragment("SwigScilabInt32FromEnum", "header") {
SWIGINTERN int
SwigScilabInt32FromEnum(void *_pvApiCtx, int _iVarOut, int _enumValue)
{
int iRet;
iRet = createScalarInteger32(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + _iVarOut, _enumValue);
if (iRet)
{
return SWIG_ERROR;
}
SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + _iVarOut);
return SWIG_OK;
}
}

View file

@ -1,6 +1,8 @@
// Scilab fragments for primitive types
%include <sciprimtypes.swg>
%include <scienum.swg>
// Include fundamental fragments definitions
%include <typemaps/fragments.swg>
// Scilab types
@ -260,23 +262,20 @@
/* -----------------------------------------------------------------------------
* --- Use enum from Scilab ---
* ----------------------------------------------------------------------------- */
%typemap(in, noblock=1, fragment="SwigScilabInt32ToEnum") enum SWIGTYPE (int val) {
if (SwigScilabInt32ToEnum(pvApiCtx, $input, &val, fname) != SWIG_OK) {
%typemap(in, noblock=1, fragment="SWIG_SciInt32_AsEnum") enum SWIGTYPE (int val) {
if (SWIG_SciInt32_AsEnum(pvApiCtx, $input, &val, SWIG_Scilab_GetFname()) != SWIG_OK) {
return 0;
}
$1 = %reinterpret_cast(val, $ltype);
}
//%scilab_in_typemap(in, SwigScilabInt32ToEnum, enum SWIGTYPE);
/* -----------------------------------------------------------------------------
* --- Return enum to Scilab ---
* ----------------------------------------------------------------------------- */
%scilab_varout_typemap(constcode, SwigScilabInt32FromEnum, enum SWIGTYPE);
%typemap(out, fragment="SwigScilabInt32FromEnum") enum SWIGTYPE {
if (SwigScilabInt32FromEnum(pvApiCtx, $result, $1) != SWIG_OK)
{
%typemap(out, fragment="SWIG_SciInt32_FromEnum") enum SWIGTYPE {
if (SWIG_SciInt32_FromEnum(pvApiCtx, $result, $1, SWIG_Scilab_GetFname()) != SWIG_OK) {
return SWIG_ERROR;
}
}