Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / share / swig / 1.3.26 / java / enums.swg
CommitLineData
920dae64
AT
1/* -----------------------------------------------------------------------------
2 * Include this file in order for C/C++ enums to be wrapped by proper Java enums.
3 * Note that the JNI layer handles the enum as an int. The Java enum has extra
4 * code generated to store the C++ int value. This is required for C++ enums that
5 * specify a value for the enum item, as native Java enums do not support this.
6 * ----------------------------------------------------------------------------- */
7
8// const enum SWIGTYPE & typemaps
9%typemap(jni) const enum SWIGTYPE & "jint"
10%typemap(jtype) const enum SWIGTYPE & "int"
11%typemap(jstype) const enum SWIGTYPE & "$*javaclassname"
12
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
18%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const enum SWIGTYPE &
19%{ static $*1_ltype temp = ($*1_ltype)$input;
20 $1 = &temp; %}
21%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"
22%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
23%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
24
25%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
26
27%typemap(throws) const enum SWIGTYPE & %{
28 (void)$1;
29 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
30%}
31
32%typemap(javain) const enum SWIGTYPE & "$javainput.swigValue()"
33%typemap(javaout) const enum SWIGTYPE & {
34 return $*javaclassname.swigToEnum($jnicall);
35 }
36
37
38// enum SWIGTYPE typemaps
39%typemap(jni) enum SWIGTYPE "jint"
40%typemap(jtype) enum SWIGTYPE "int"
41%typemap(jstype) enum SWIGTYPE "$javaclassname"
42
43%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
44%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
45
46%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
47%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
48%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
49%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"
50
51%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
52
53%typemap(throws) enum SWIGTYPE %{
54 (void)$1;
55 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
56%}
57
58%typemap(javain) enum SWIGTYPE "$javainput.swigValue()"
59%typemap(javaout) enum SWIGTYPE {
60 return $javaclassname.swigToEnum($jnicall);
61 }
62
63%typemap(javaclassmodifiers) enum SWIGTYPE "public enum"
64%typemap(javabase) enum SWIGTYPE ""
65%typemap(javacode) enum SWIGTYPE ""
66%typemap(javaimports) enum SWIGTYPE ""
67%typemap(javainterfaces) enum SWIGTYPE ""
68%typemap(javabody) enum SWIGTYPE ""
69
70/*
71 * SwigNext static inner class used instead of a static int as static fields cannot be accessed from enum initialisers.
72 * The swigToEnum method is used to find the Java enum from a C++ enum integer value. The default one here takes
73 * advantage of the fact that most enums do not have initial values specified, so the lookup is fast. If initial
74 * values are specified then a lengthy linear search through all possible enums might occur. Specific typemaps could be
75 * written to possibly optimise this lookup by taking advantage of characteristics peculiar to the targeted enum.
76 */
77%typemap(javabody) enum SWIGTYPE %{
78 public final int swigValue() {
79 return swigValue;
80 }
81
82 public static $javaclassname swigToEnum(int swigValue) {
83 $javaclassname[] swigValues = $javaclassname.class.getEnumConstants();
84 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
85 return swigValues[swigValue];
86 for ($javaclassname swigEnum : swigValues)
87 if (swigEnum.swigValue == swigValue)
88 return swigEnum;
89 throw new IllegalArgumentException("No enum " + $javaclassname.class + " with value " + swigValue);
90 }
91
92 private $javaclassname() {
93 this.swigValue = SwigNext.next++;
94 }
95
96 private $javaclassname(int swigValue) {
97 this.swigValue = swigValue;
98 SwigNext.next = swigValue+1;
99 }
100
101 private final int swigValue;
102
103 private static class SwigNext {
104 private static int next = 0;
105 }
106%}
107
108%javaenum(proper);
109