Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / share / swig / 1.3.26 / java / enumtypesafe.swg
CommitLineData
920dae64
AT
1/* -----------------------------------------------------------------------------\r
2 * Include this file in order for C/C++ enums to be wrapped by the so called\r
3 * typesafe enum pattern. Each enum has an equivalent Java class named after the\r
4 * enum and each enum item is a static instance of this class.\r
5 * ----------------------------------------------------------------------------- */\r
6\r
7// const enum SWIGTYPE & typemaps\r
8%typemap(jni) const enum SWIGTYPE & "jint"\r
9%typemap(jtype) const enum SWIGTYPE & "int"\r
10%typemap(jstype) const enum SWIGTYPE & "$*javaclassname"\r
11\r
12%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)\r
13%{ temp = ($*1_ltype)$input; \r
14 $1 = &temp; %}\r
15%typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}\r
16\r
17%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const enum SWIGTYPE &\r
18%{ static $*1_ltype temp = ($*1_ltype)$input; \r
19 $1 = &temp; %}\r
20%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"\r
21%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"\r
22%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"\r
23\r
24%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""\r
25\r
26%typemap(throws) const enum SWIGTYPE & %{\r
27 (void)$1;\r
28 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");\r
29%}\r
30\r
31%typemap(javain) const enum SWIGTYPE & "$javainput.swigValue()"\r
32%typemap(javaout) const enum SWIGTYPE & {\r
33 return $*javaclassname.swigToEnum($jnicall);\r
34 }\r
35\r
36// enum SWIGTYPE typemaps\r
37%typemap(jni) enum SWIGTYPE "jint"\r
38%typemap(jtype) enum SWIGTYPE "int"\r
39%typemap(jstype) enum SWIGTYPE "$javaclassname"\r
40\r
41%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}\r
42%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}\r
43\r
44%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}\r
45%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"\r
46%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"\r
47%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"\r
48\r
49%typecheck(SWIG_TYPECHECK_INT32) enum SWIGTYPE ""\r
50\r
51%typemap(throws) enum SWIGTYPE %{\r
52 (void)$1;\r
53 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");\r
54%}\r
55\r
56%typemap(javain) enum SWIGTYPE "$javainput.swigValue()"\r
57%typemap(javaout) enum SWIGTYPE {\r
58 return $javaclassname.swigToEnum($jnicall);\r
59 }\r
60\r
61// '$static' will be replaced with either 'static' or nothing depending on whether the enum is an inner Java class or not\r
62%typemap(javaclassmodifiers) enum SWIGTYPE "public final $static class"\r
63%typemap(javabase) enum SWIGTYPE ""\r
64%typemap(javacode) enum SWIGTYPE ""\r
65%typemap(javaimports) enum SWIGTYPE ""\r
66%typemap(javainterfaces) enum SWIGTYPE ""\r
67%typemap(javabody) enum SWIGTYPE ""\r
68\r
69/*\r
70 * The swigToEnum method is used to find the Java enum from a C++ enum integer value. The default one here takes \r
71 * advantage of the fact that most enums do not have initial values specified, so the lookup is fast. If initial\r
72 * values are specified then a lengthy linear search through all possible enums might occur. Specific typemaps could be\r
73 * written to possibly optimise this lookup by taking advantage of characteristics peculiar to the targeted enum.\r
74 * The special variable, $enumvalues, is replaced with a comma separated list of all the enum values.\r
75 */\r
76%typemap(javabody) enum SWIGTYPE %{\r
77 public final int swigValue() {\r
78 return swigValue;\r
79 }\r
80\r
81 public String toString() {\r
82 return swigName;\r
83 }\r
84\r
85 public static $javaclassname swigToEnum(int swigValue) {\r
86 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)\r
87 return swigValues[swigValue];\r
88 for (int i = 0; i < swigValues.length; i++)\r
89 if (swigValues[i].swigValue == swigValue)\r
90 return swigValues[i];\r
91 throw new IllegalArgumentException("No enum " + $javaclassname.class + " with value " + swigValue);\r
92 }\r
93\r
94 private $javaclassname(String swigName) {\r
95 this.swigName = swigName;\r
96 this.swigValue = swigNext++;\r
97 }\r
98\r
99 private $javaclassname(String swigName, int swigValue) {\r
100 this.swigName = swigName;\r
101 this.swigValue = swigValue;\r
102 swigNext = swigValue+1;\r
103 }\r
104\r
105 private static $javaclassname[] swigValues = { $enumvalues };\r
106 private static int swigNext = 0;\r
107 private final int swigValue;\r
108 private final String swigName;\r
109%}\r
110\r
111%javaenum(typesafe);\r
112\r