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
This commit is contained in:
Marcelo Matus 2004-10-08 09:11:09 +00:00
commit 092a7d9f09
2 changed files with 33 additions and 12 deletions

View file

@ -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& };

View file

@ -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 */