From 092a7d9f097d9278122b587d2abfc5747e55e4bf Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Fri, 8 Oct 2004 09:11:09 +0000 Subject: [PATCH] add cast to work with SwigValueWrapper and write the out enum types appart, as needed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6375 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyenum.swg | 26 ++++++++++++++++++++++++-- Lib/python/pyvaltypes.swg | 19 +++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Lib/python/pyenum.swg b/Lib/python/pyenum.swg index b7cf109a6..a9d002e8b 100644 --- a/Lib/python/pyenum.swg +++ b/Lib/python/pyenum.swg @@ -2,6 +2,8 @@ * Enums * ------------------------------------------------------------ */ %apply int { enum SWIGTYPE }; +/* this doesn't work now, you need to redefined it for each enum. */ +%apply const int& { const enum SWIGTYPE& }; %typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE { @@ -14,8 +16,28 @@ } } +%define ENUM_OUT_TYPEMAP(from_meth,pyfrag) + %typemap(out,fragment=pyfrag) enum SWIGTYPE + "$result = from_meth(($1));"; + %typemap(out,fragment=pyfrag) const enum SWIGTYPE& + "$result = from_meth((*$1));"; + %typemap(varout,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE& + "$result = from_meth($1);"; + %typemap(constcode,fragment=pyfrag) enum SWIGTYPE + "PyDict_SetItemString(d,\"$symname\", from_meth($value));"; + %typemap(directorin,fragment=pyfrag) enum SWIGTYPE *DIRECTORIN + "$input = from_meth(*$1_name);"; + %typemap(directorin,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE& + "$input = from_meth($1_name);"; + %typemap(throws,fragment=pyfrag) enum SWIGTYPE + "PyErr_SetObject(PyExc_RuntimeError, from_meth($1)); + SWIG_fail;"; +%enddef + +ENUM_OUT_TYPEMAP(SWIG_From(int),SWIG_From_frag(int)); + + + -/* this doesn't work now, you need to redefined it for each enum. */ -%apply const int& { const enum SWIGTYPE& }; diff --git a/Lib/python/pyvaltypes.swg b/Lib/python/pyvaltypes.swg index 4cac41978..42b3a25a9 100644 --- a/Lib/python/pyvaltypes.swg +++ b/Lib/python/pyvaltypes.swg @@ -20,9 +20,9 @@ %define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,...) %typemap(out,fragment=pyfrag) __VA_ARGS__ - "$result = from_meth((__VA_ARGS__)$1);"; + "$result = from_meth((__VA_ARGS__)($basetype)($1));"; %typemap(out,fragment=pyfrag) const __VA_ARGS__& - "$result = from_meth((__VA_ARGS__)*($1));"; + "$result = from_meth((__VA_ARGS__)($basetype)(*$1));"; %enddef /* varin */ @@ -42,13 +42,13 @@ %define PYVAL_VAROUT_TYPEMAP(from_meth,pyfrag,...) %typemap(varout,fragment=pyfrag) __VA_ARGS__, const __VA_ARGS__& - "$result = from_meth((__VA_ARGS__)$1);"; + "$result = from_meth((__VA_ARGS__)($basetype)$1);"; %enddef /* constant installation code */ %define PYVAL_CONSTCODE_TYPEMAP(from_meth,pyfrag,...) %typemap(constcode,fragment=pyfrag) __VA_ARGS__ - "PyDict_SetItemString(d,\"$symname\", from_meth((__VA_ARGS__)$value));"; + "PyDict_SetItemString(d,\"$symname\", from_meth((__VA_ARGS__)($basetype)$value));"; %enddef @@ -56,9 +56,9 @@ %define PYVAL_DIRECTORIN_TYPEMAP(from_meth,pyfrag,...) %typemap(directorin,fragment=pyfrag) __VA_ARGS__ *DIRECTORIN - "$input = from_meth((__VA_ARGS__)*$1_name);"; + "$input = from_meth((__VA_ARGS__)($basetype)*$1_name);"; %typemap(directorin,fragment=pyfrag) __VA_ARGS__, const __VA_ARGS__& - "$input = from_meth((__VA_ARGS__)$1_name);"; + "$input = from_meth((__VA_ARGS__)($basetype)$1_name);"; %enddef /* directorout */ @@ -80,10 +80,9 @@ /* throws */ %define PYVAL_THROWS_TYPEMAP(from_meth,pyfrag,...) - %typemap(throws,fragment=pyfrag) __VA_ARGS__ { - PyErr_SetObject(PyExc_RuntimeError, from_meth((__VA_ARGS__)$1)); - SWIG_fail; - } + %typemap(throws,fragment=pyfrag) __VA_ARGS__ + "PyErr_SetObject(PyExc_RuntimeError, from_meth((__VA_ARGS__)($basetype)$1)); + SWIG_fail;"; %enddef /* typecheck */