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
This commit is contained in:
parent
e18288ecab
commit
240f395497
3 changed files with 18 additions and 25 deletions
|
|
@ -5,7 +5,7 @@ enum color { RED, BLUE, GREEN };
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
Foo() { }
|
Foo() { }
|
||||||
enum speed { IMPULSE, WARP, LUDICROUS };
|
enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
|
||||||
void enum_test(speed s);
|
void enum_test(speed s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,11 @@
|
||||||
<tt>$Header$</tt><br>
|
<tt>$Header$</tt><br>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This example tests SWIG's ability to wrap enumerations. By default, SWIG
|
This example tests SWIG's ability to wrap enumerations.
|
||||||
converts enumeration specifications into integer constants. Further use
|
SWIG wraps enums in numerous different ways. The default approach is to wrap
|
||||||
of enumerated types are handled as integers.
|
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>
|
<ul>
|
||||||
<li><a href="example.h">example.h</a>. Header file containing some enums.
|
<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.
|
<li><a href="main.java">main.java</a>. Sample Java program.
|
||||||
</ul>
|
</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>
|
<hr>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -13,27 +13,26 @@ public class main {
|
||||||
{
|
{
|
||||||
// Print out the value of some enums
|
// Print out the value of some enums
|
||||||
System.out.println("*** color ***");
|
System.out.println("*** color ***");
|
||||||
System.out.println(" RED = " + example.RED);
|
System.out.println(" " + color.RED + " = " + color.RED.swigValue());
|
||||||
System.out.println(" BLUE = " + example.BLUE);
|
System.out.println(" " + color.BLUE + " = " + color.BLUE.swigValue());
|
||||||
System.out.println(" GREEN = " + example.GREEN);
|
System.out.println(" " + color.GREEN + " = " + color.GREEN.swigValue());
|
||||||
|
|
||||||
System.out.println("\n*** Foo::speed ***");
|
System.out.println("\n*** Foo::speed ***");
|
||||||
System.out.println(" Foo::IMPULSE = " + Foo.IMPULSE);
|
System.out.println(" Foo::" + Foo.speed.IMPULSE + " = " + Foo.speed.IMPULSE.swigValue());
|
||||||
System.out.println(" Foo::WARP = " + Foo.WARP);
|
System.out.println(" Foo::" + Foo.speed.WARP + " = " + Foo.speed.WARP.swigValue());
|
||||||
System.out.println(" Foo::LUDICROUS = " + Foo.LUDICROUS);
|
System.out.println(" Foo::" + Foo.speed.LUDICROUS + " = " + Foo.speed.LUDICROUS.swigValue());
|
||||||
|
|
||||||
System.out.println("\nTesting use of enums with functions\n");
|
System.out.println("\nTesting use of enums with functions\n");
|
||||||
|
|
||||||
example.enum_test(example.RED, Foo.IMPULSE);
|
example.enum_test(color.RED, Foo.speed.IMPULSE);
|
||||||
example.enum_test(example.BLUE, Foo.WARP);
|
example.enum_test(color.BLUE, Foo.speed.WARP);
|
||||||
example.enum_test(example.GREEN, Foo.LUDICROUS);
|
example.enum_test(color.GREEN, Foo.speed.LUDICROUS);
|
||||||
example.enum_test(1234,5678);
|
|
||||||
|
|
||||||
System.out.println( "\nTesting use of enum with class method" );
|
System.out.println( "\nTesting use of enum with class method" );
|
||||||
Foo f = new Foo();
|
Foo f = new Foo();
|
||||||
|
|
||||||
f.enum_test(Foo.IMPULSE);
|
f.enum_test(Foo.speed.IMPULSE);
|
||||||
f.enum_test(Foo.WARP);
|
f.enum_test(Foo.speed.WARP);
|
||||||
f.enum_test(Foo.LUDICROUS);
|
f.enum_test(Foo.speed.LUDICROUS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue