Added a new Examples folder with modified Examples/java files

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10763 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Cheryl Foil 2008-08-15 23:54:53 +00:00
commit 311ddbc2bf
78 changed files with 3668 additions and 0 deletions

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
SWIGOPT =
all:: java
java::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
javac *.java
clean::
$(MAKE) -f $(TOP)/Makefile java_clean
check: all

View file

@ -0,0 +1,37 @@
/* File : example.cxx */
#include "example.h"
#include <stdio.h>
void Foo::enum_test(speed s) {
if (s == IMPULSE) {
printf("IMPULSE speed\n");
} else if (s == WARP) {
printf("WARP speed\n");
} else if (s == LUDICROUS) {
printf("LUDICROUS speed\n");
} else {
printf("Unknown speed\n");
}
}
void enum_test(color c, Foo::speed s) {
if (c == RED) {
printf("color = RED, ");
} else if (c == BLUE) {
printf("color = BLUE, ");
} else if (c == GREEN) {
printf("color = GREEN, ");
} else {
printf("color = Unknown color!, ");
}
if (s == Foo::IMPULSE) {
printf("speed = IMPULSE speed\n");
} else if (s == Foo::WARP) {
printf("speed = WARP speed\n");
} else if (s == Foo::LUDICROUS) {
printf("speed = LUDICROUS speed\n");
} else {
printf("speed = Unknown speed!\n");
}
}

View file

@ -0,0 +1,23 @@
/** This is a block describing enum
*/
enum color { RED, BLUE, GREEN };
/*! This is describing class foo
*/
class Foo {
public:
Foo() { }
enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
void enum_test(speed s);
};
/*! This is describing enum test
//! \param c the color c
//! \param s the speed
*/
void enum_test(color c, Foo::speed s);

View file

@ -0,0 +1,14 @@
/** File : example.i */
%module example
%{
#include "example.h"
%}
/** Force the generated Java code to use the C enum values rather than making a JNI call */
%javaconst(1);
/** Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,29 @@
<html>
<head>
<title>SWIG:Examples:java:enum</title>
</head>
<body bgcolor="#ffffff">
<tt>SWIG/Examples/java/enum/</tt>
<hr>
<H2>Wrapping enumerations</H2>
<p>
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.
<li><a href="example.i">example.i</a>. Interface file.
<li><a href="main.java">main.java</a>. Sample Java program.
</ul>
<hr>
</body>
</html>

View file

@ -0,0 +1,38 @@
public class main {
static {
try {
System.loadLibrary("example");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// Print out the value of some enums
System.out.println("*** color ***");
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::" + 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(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.speed.IMPULSE);
f.enum_test(Foo.speed.WARP);
f.enum_test(Foo.speed.LUDICROUS);
}
}