PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/java/enums.swg

#
Unknown | 117 lines | 94 code | 23 blank | 0 comment | 0 complexity | 49990e251195081fdd9976dc589f808e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * enums.swg
  3. *
  4. * Include this file in order for C/C++ enums to be wrapped by proper Java enums.
  5. * Note that the JNI layer handles the enum as an int. The Java enum has extra
  6. * code generated to store the C++ int value. This is required for C++ enums that
  7. * specify a value for the enum item, as native Java enums do not support this.
  8. * ----------------------------------------------------------------------------- */
  9. // const enum SWIGTYPE & typemaps
  10. %typemap(jni) const enum SWIGTYPE & "jint"
  11. %typemap(jtype) const enum SWIGTYPE & "int"
  12. %typemap(jstype) const enum SWIGTYPE & "$*javaclassname"
  13. %typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
  14. %{ temp = ($*1_ltype)$input;
  15. $1 = &temp; %}
  16. %typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}
  17. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
  18. %{ static $*1_ltype temp = ($*1_ltype)$input;
  19. $result = &temp; %}
  20. %typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1;"
  21. %typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
  22. %typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
  23. %typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
  24. %typemap(throws) const enum SWIGTYPE &
  25. %{ (void)$1;
  26. SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); %}
  27. %typemap(javain) const enum SWIGTYPE & "$javainput.swigValue()"
  28. %typemap(javaout) const enum SWIGTYPE & {
  29. return $*javaclassname.swigToEnum($jnicall);
  30. }
  31. // enum SWIGTYPE typemaps
  32. %typemap(jni) enum SWIGTYPE "jint"
  33. %typemap(jtype) enum SWIGTYPE "int"
  34. %typemap(jstype) enum SWIGTYPE "$javaclassname"
  35. %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
  36. %typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
  37. %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
  38. %typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
  39. %typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
  40. %typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"
  41. %typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
  42. %typemap(throws) enum SWIGTYPE
  43. %{ (void)$1;
  44. SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); %}
  45. %typemap(javain) enum SWIGTYPE "$javainput.swigValue()"
  46. %typemap(javaout) enum SWIGTYPE {
  47. return $javaclassname.swigToEnum($jnicall);
  48. }
  49. %typemap(javaclassmodifiers) enum SWIGTYPE "public enum"
  50. %typemap(javabase) enum SWIGTYPE ""
  51. %typemap(javacode) enum SWIGTYPE ""
  52. %typemap(javaimports) enum SWIGTYPE ""
  53. %typemap(javainterfaces) enum SWIGTYPE ""
  54. %typemap(javabody) enum SWIGTYPE ""
  55. /*
  56. * SwigNext static inner class used instead of a static int as static fields cannot be accessed from enum initialisers.
  57. * The swigToEnum method is used to find the Java enum from a C++ enum integer value. The default one here takes
  58. * advantage of the fact that most enums do not have initial values specified, so the lookup is fast. If initial
  59. * values are specified then a lengthy linear search through all possible enums might occur. Specific typemaps could be
  60. * written to possibly optimise this lookup by taking advantage of characteristics peculiar to the targeted enum.
  61. */
  62. %typemap(javabody) enum SWIGTYPE %{
  63. public final int swigValue() {
  64. return swigValue;
  65. }
  66. public static $javaclassname swigToEnum(int swigValue) {
  67. $javaclassname[] swigValues = $javaclassname.class.getEnumConstants();
  68. if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
  69. return swigValues[swigValue];
  70. for ($javaclassname swigEnum : swigValues)
  71. if (swigEnum.swigValue == swigValue)
  72. return swigEnum;
  73. throw new IllegalArgumentException("No enum " + $javaclassname.class + " with value " + swigValue);
  74. }
  75. @SuppressWarnings("unused")
  76. private $javaclassname() {
  77. this.swigValue = SwigNext.next++;
  78. }
  79. @SuppressWarnings("unused")
  80. private $javaclassname(int swigValue) {
  81. this.swigValue = swigValue;
  82. SwigNext.next = swigValue+1;
  83. }
  84. @SuppressWarnings("unused")
  85. private $javaclassname($javaclassname swigEnum) {
  86. this.swigValue = swigEnum.swigValue;
  87. SwigNext.next = this.swigValue+1;
  88. }
  89. private final int swigValue;
  90. private static class SwigNext {
  91. private static int next = 0;
  92. }
  93. %}
  94. %javaenum(proper);