PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/rel-1-3-25/SWIG/Examples/test-suite/java_enums.i

#
Swig | 56 lines | 44 code | 12 blank | 0 comment | 0 complexity | 9682f54ed383bbe0e2cf64721a115958 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1
 2// This testcase uses the %javaconst directive to control how enums are initialised
 3
 4%module java_enums
 5
 6%include "enumtypeunsafe.swg"
 7
 8// Some pragmas to add in an interface to the module class
 9%pragma(java) moduleinterfaces="Serializable"
10%pragma(java) moduleimports=%{
11import java.io.*; // For Serializable
12%}
13
14// Set default Java const code generation
15%javaconst(1);
16
17// Change the default generation so that these enums are generated into an interface instead of a class
18%typemap(javaclassmodifiers) enum stuff "public interface"
19
20%inline %{
21enum stuff { FIDDLE = 2*100,  STICKS = 5+8, BONGO, DRUMS };
22%}
23
24// Check that the enum typemaps are working by using a short for the enums instead of int
25%javaconst(0); // will create compile errors in runme file if short typemaps not used 
26
27namespace Space {
28%typemap(jtype) enum nonsense "short"
29%typemap(jstype) enum nonsense "short"
30%typemap(javain) enum nonsense "$javainput"
31%typemap(in) enum nonsense %{ $1 = (enum Space::nonsense)$input; %}
32%typemap(out) enum nonsense %{ $result = (jshort)$1; %}
33%typemap(jni) enum nonsense "jshort"
34%typemap(javaout) enum nonsense {
35    return $jnicall;
36  }
37}
38
39%inline %{
40namespace Space {
41enum nonsense { POPPYCOCK, JUNK };
42nonsense test1(nonsense n) { return n; }
43enum nonsense test2(enum nonsense n) { return n; }
44}
45%}
46
47// Test the %javaconstvalue directive for enums
48%{
49static const int FOUR = 4;
50%}
51
52%javaconst(1);
53%javaconstvalue(4) Quattro;
54%inline %{
55enum Numero { Quattro = FOUR };
56%}