diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2004-05-31 07:14:33 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2004-05-31 07:14:33 +0000 |
commit | 240f395497e7f3f4d1458bd7fb88151d62417743 (patch) | |
tree | ac81700a16012935011455629348ff9073e57d7c /Examples/java | |
parent | e18288ecabbc70645ebe74c09c9b5f35d6d221f3 (diff) | |
download | swig-240f395497e7f3f4d1458bd7fb88151d62417743.tar.gz |
Update for new enum wrapping which uses the typesafe enum pattern
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5953 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/java')
-rw-r--r-- | Examples/java/enum/example.h | 2 | ||||
-rw-r--r-- | Examples/java/enum/index.html | 16 | ||||
-rw-r--r-- | Examples/java/enum/main.java | 25 |
3 files changed, 18 insertions, 25 deletions
diff --git a/Examples/java/enum/example.h b/Examples/java/enum/example.h index 525d62afc..9119cd9fc 100644 --- a/Examples/java/enum/example.h +++ b/Examples/java/enum/example.h @@ -5,7 +5,7 @@ enum color { RED, BLUE, GREEN }; class Foo { public: Foo() { } - enum speed { IMPULSE, WARP, LUDICROUS }; + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; void enum_test(speed s); }; diff --git a/Examples/java/enum/index.html b/Examples/java/enum/index.html index cd81244e3..6179f9f97 100644 --- a/Examples/java/enum/index.html +++ b/Examples/java/enum/index.html @@ -14,9 +14,11 @@ <tt>$Header$</tt><br> <p> -This example tests SWIG's ability to wrap enumerations. By default, SWIG -converts enumeration specifications into integer constants. Further use -of enumerated types are handled as integers. +This example tests SWIG's ability to wrap enumerations. +SWIG wraps enums in numerous different ways. The default approach is to wrap +each enum with the typesafe enum pattern. Enums are handled as integers in the JNI layer. +See the documentation for the other approaches for wrapping enums. + <ul> <li><a href="example.h">example.h</a>. Header file containing some enums. @@ -24,14 +26,6 @@ of enumerated types are handled as integers. <li><a href="main.java">main.java</a>. Sample Java program. </ul> -<h2>Notes</h2> - -<ul> -<li>SWIG allows arbitrary integers to be passed as enum values. However, -the result of passing an integer not corresponding to any of the values -specified in the <tt>enum</tt> specification is undefined. -</ul> - <hr> </body> </html> diff --git a/Examples/java/enum/main.java b/Examples/java/enum/main.java index b1098c7b1..8646e0087 100644 --- a/Examples/java/enum/main.java +++ b/Examples/java/enum/main.java @@ -13,27 +13,26 @@ public class main { { // Print out the value of some enums System.out.println("*** color ***"); - System.out.println(" RED = " + example.RED); - System.out.println(" BLUE = " + example.BLUE); - System.out.println(" GREEN = " + example.GREEN); + System.out.println(" " + color.RED + " = " + color.RED.swigValue()); + System.out.println(" " + color.BLUE + " = " + color.BLUE.swigValue()); + System.out.println(" " + color.GREEN + " = " + color.GREEN.swigValue()); System.out.println("\n*** Foo::speed ***"); - System.out.println(" Foo::IMPULSE = " + Foo.IMPULSE); - System.out.println(" Foo::WARP = " + Foo.WARP); - System.out.println(" Foo::LUDICROUS = " + Foo.LUDICROUS); + System.out.println(" Foo::" + Foo.speed.IMPULSE + " = " + Foo.speed.IMPULSE.swigValue()); + System.out.println(" Foo::" + Foo.speed.WARP + " = " + Foo.speed.WARP.swigValue()); + System.out.println(" Foo::" + Foo.speed.LUDICROUS + " = " + Foo.speed.LUDICROUS.swigValue()); System.out.println("\nTesting use of enums with functions\n"); - example.enum_test(example.RED, Foo.IMPULSE); - example.enum_test(example.BLUE, Foo.WARP); - example.enum_test(example.GREEN, Foo.LUDICROUS); - example.enum_test(1234,5678); + example.enum_test(color.RED, Foo.speed.IMPULSE); + example.enum_test(color.BLUE, Foo.speed.WARP); + example.enum_test(color.GREEN, Foo.speed.LUDICROUS); System.out.println( "\nTesting use of enum with class method" ); Foo f = new Foo(); - f.enum_test(Foo.IMPULSE); - f.enum_test(Foo.WARP); - f.enum_test(Foo.LUDICROUS); + f.enum_test(Foo.speed.IMPULSE); + f.enum_test(Foo.speed.WARP); + f.enum_test(Foo.speed.LUDICROUS); } } |