Update for new enum wrapping which uses the typesafe enum pattern
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5953 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4192a5025c
commit
a1c7dc1051
3 changed files with 18 additions and 25 deletions
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue