%javaconst(1) feature for enums so that using enum values do not have to make a JNI call.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4361 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1b26188b33
commit
c75bcef396
3 changed files with 41 additions and 1 deletions
|
|
@ -533,7 +533,7 @@ Enumerations are wrapped as final static integers in Java and are also initialis
|
|||
|
||||
<blockquote>
|
||||
<pre>
|
||||
enum Beverage { ALE, LAGER, STOUT, PILSNER };
|
||||
enum Beverage { ALE, LAGER=10, STOUT, PILSNER };
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
|
|
@ -549,6 +549,33 @@ public class example {
|
|||
}
|
||||
</pre></blockquote>
|
||||
|
||||
The <tt>%javaconst(flag)</tt> directive introduced in the previous section on constants can also be used with enums,
|
||||
thereby also allowing enum values to be used in Java switch statements.
|
||||
As is the case for constants, the default is <tt>%javaconst(0)</tt> as not all C values will compile as Java code.
|
||||
However, it is recommended to add in a <tt>%javaconst(1)</tt> directive into your
|
||||
interface file as it is only on very rare occasions that this will produce code that won't compile under Java.
|
||||
Example usage:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
%javaconst(1);
|
||||
%javaconst(0) PILSNER;
|
||||
enum Beverage { ALE, LAGER=10, STOUT, PILSNER };
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
generates:
|
||||
|
||||
<blockquote><pre>
|
||||
public class example {
|
||||
// enums and constants
|
||||
public final static int ALE = 0;
|
||||
public final static int LAGER = 10;
|
||||
public final static int STOUT = LAGER+1;
|
||||
public final static int PILSNER = exampleJNI.get_PILSNER();
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
For enums, make sure that the definition of the enumeration actually appears in a header
|
||||
file or in the wrapper file somehow---if you just have an enum in a SWIG interface without
|
||||
also telling the C compiler about it, the wrapper code won't compile.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue