| 1 | /* ------------------------------------------------------------ |
| 2 | * Enums |
| 3 | * ------------------------------------------------------------ */ |
| 4 | %apply int { enum SWIGTYPE }; |
| 5 | %apply const int& { const enum SWIGTYPE& }; |
| 6 | |
| 7 | %typemap(in,fragment=SWIG_As_frag(int)) const enum SWIGTYPE& ($basetype temp) { |
| 8 | temp = SWIG_static_cast(SWIG_As(int)($input),$basetype); |
| 9 | if (SWIG_arg_fail($argnum)) SWIG_fail; |
| 10 | $1 = &temp; |
| 11 | } |
| 12 | |
| 13 | |
| 14 | %typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE |
| 15 | { |
| 16 | if (sizeof(int) != sizeof($1)) { |
| 17 | PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set"); |
| 18 | return 1; |
| 19 | } |
| 20 | if (!SWIG_AsVal(int)($input, (int*)(void*)(&$1))) { |
| 21 | return 1; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | typemaps needed due to unnamed enums |
| 27 | */ |
| 28 | %define PY_ENUM_OUT_TYPEMAPS(from_meth,pyfrag) |
| 29 | %typemap(out,fragment=pyfrag) enum SWIGTYPE |
| 30 | "$result = from_meth(($1));"; |
| 31 | %typemap(out,fragment=pyfrag) const enum SWIGTYPE& |
| 32 | "$result = from_meth((*$1));"; |
| 33 | %typemap(varout,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE& |
| 34 | "$result = from_meth($1);"; |
| 35 | %typemap(constcode,fragment=pyfrag) enum SWIGTYPE |
| 36 | "PyDict_SetItemString(d,\"$symname\", from_meth($value));"; |
| 37 | %typemap(directorin,fragment=pyfrag) enum SWIGTYPE *DIRECTORIN |
| 38 | "$input = from_meth(*$1_name);"; |
| 39 | %typemap(directorin,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE& |
| 40 | "$input = from_meth($1_name);"; |
| 41 | %typemap(throws,fragment=pyfrag) enum SWIGTYPE |
| 42 | "PyErr_SetObject(PyExc_RuntimeError, from_meth($1)); |
| 43 | SWIG_fail;"; |
| 44 | %enddef |
| 45 | |
| 46 | PY_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int)); |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |