From 1fc46dfc1f3ef75cfcf460fa4da1a341c6979f27 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Mon, 18 Oct 2004 00:27:06 +0000 Subject: [PATCH] moving more enum typemaps here git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6419 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyenum.swg | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/python/pyenum.swg b/Lib/python/pyenum.swg index a9d002e8b..b08e26249 100644 --- a/Lib/python/pyenum.swg +++ b/Lib/python/pyenum.swg @@ -2,21 +2,24 @@ * 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 { if (sizeof(int) != sizeof($1)) { PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set"); return 1; } - if (!SWIG_AsVal(int)($input, (int*)(void*)&($1))) { + if (!SWIG_AsVal(int)($input, (int*)(void*)(&$1))) { return 1; } } -%define ENUM_OUT_TYPEMAP(from_meth,pyfrag) +/* + typemaps needed due to unnamed enums +*/ +%define PY_ENUM_OUT_TYPEMAPS(from_meth,pyfrag) %typemap(out,fragment=pyfrag) enum SWIGTYPE "$result = from_meth(($1));"; %typemap(out,fragment=pyfrag) const enum SWIGTYPE& @@ -34,7 +37,7 @@ SWIG_fail;"; %enddef -ENUM_OUT_TYPEMAP(SWIG_From(int),SWIG_From_frag(int)); +PY_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int));