From 8626d96aff7c9810d4cbf1d72dd5e690f8efea5e Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 27 Sep 2013 10:30:12 +0200 Subject: [PATCH] Scilab: refactor enum typemap --- Lib/scilab/scienum.swg | 29 +++++++++++++++++++++++++++++ Lib/scilab/sciprimtypes.swg | 30 ------------------------------ Lib/scilab/scitypemaps.swg | 13 ++++++------- 3 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 Lib/scilab/scienum.swg diff --git a/Lib/scilab/scienum.swg b/Lib/scilab/scienum.swg new file mode 100644 index 000000000..5db52be35 --- /dev/null +++ b/Lib/scilab/scienum.swg @@ -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); +} +} diff --git a/Lib/scilab/sciprimtypes.swg b/Lib/scilab/sciprimtypes.swg index 55c5808b0..e1b6309aa 100644 --- a/Lib/scilab/sciprimtypes.swg +++ b/Lib/scilab/sciprimtypes.swg @@ -19,33 +19,3 @@ %include %include -%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; -} -} diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index 33cf288a6..36f3518b3 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -1,6 +1,8 @@ // Scilab fragments for primitive types %include +%include + // Include fundamental fragments definitions %include // 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; } }