moving more enum typemaps here

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6419 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-10-18 00:27:06 +00:00
commit 1fc46dfc1f

View file

@ -2,21 +2,24 @@
* Enums * Enums
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%apply int { enum SWIGTYPE }; %apply int { enum SWIGTYPE };
/* this doesn't work now, you need to redefined it for each enum. */
%apply const int& { const enum SWIGTYPE& }; %apply const int& { const enum SWIGTYPE& };
%typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE %typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE
{ {
if (sizeof(int) != sizeof($1)) { if (sizeof(int) != sizeof($1)) {
PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set"); PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set");
return 1; return 1;
} }
if (!SWIG_AsVal(int)($input, (int*)(void*)&($1))) { if (!SWIG_AsVal(int)($input, (int*)(void*)(&$1))) {
return 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 %typemap(out,fragment=pyfrag) enum SWIGTYPE
"$result = from_meth(($1));"; "$result = from_meth(($1));";
%typemap(out,fragment=pyfrag) const enum SWIGTYPE& %typemap(out,fragment=pyfrag) const enum SWIGTYPE&
@ -34,7 +37,7 @@
SWIG_fail;"; SWIG_fail;";
%enddef %enddef
ENUM_OUT_TYPEMAP(SWIG_From(int),SWIG_From_frag(int)); PY_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int));