/tags/rel-1-3-25/SWIG/Lib/python/pyenum.swg

# · Unknown · 52 lines · 41 code · 11 blank · 0 comment · 0 complexity · 031e5d6a762fa907da081d906179fed2 MD5 · raw file

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