New default C/C++ enum wrapping approach which uses the type safe enum pattern for Java and C#

Also tests for Java and C# simple enums (enum items mapped to integers)
Also proper Java (J2SDK1.5) enums


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5919 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-05-24 20:05:40 +00:00
commit b84a6d58b4
6 changed files with 41 additions and 5 deletions

View file

@ -52,7 +52,7 @@ const enum colour colourTest4(const enum colour e) { return e; }
colour myColour;
struct SpeedClass {
enum speed { slow=10, medium=20, fast=30 };
enum speed { slow=10, medium=20, fast=30, lightning };
typedef enum speed speedtd1;
speed speedTest1(speed s) { return s; }
@ -64,7 +64,7 @@ struct SpeedClass {
const colour myColour2;
speedtd1 mySpeedtd1;
SpeedClass() : myColour2(red) { }
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
};
SpeedClass::speed speedTest1(SpeedClass::speed s) { return s; }
@ -223,6 +223,7 @@ TClass<int>::scientiststd3 scientistsNameSpaceTestL(TClass<int>
%rename(doublenamerenamed) doublename;
%rename(simplerenamed) simple;
%rename(singlenamerenamed) singlename;
%rename(bang) OldNameStruct::kerboom;
%inline %{
enum oldname { argh };
@ -231,7 +232,7 @@ oldname renameTest1(oldname e) { return e; }
oldnametd renameTest2(oldnametd e) { return e; }
struct OldNameStruct {
enum enumeration {whizz, bang, pop};
enum enumeration {whizz, kerboom, pop};
enumeration renameTest1(enumeration e) { return e; }
OldNameStruct::enumeration renameTest2(OldNameStruct::enumeration e) { return e; }
@ -451,5 +452,13 @@ struct Obscure {
typedef enum {,} AlsoEmptyTrail;
};
// Unnamed enum instance
enum { globalinstance1, globalinstance2 } GlobalInstance;
struct Instances {
enum { memberinstance1, memberinstance2, memberinstance3 } MemberInstance;
Instances() : MemberInstance(memberinstance3) {}
};
%}

View file

@ -0,0 +1,7 @@
%module "enum_thorough_simple"
// Test enum wrapping using simple constants (SWIG-1.3.21 and earlier default enum wrapping for C# and Java)
%include "enumsimple.swg"
%include "enum_thorough.i"

View file

@ -0,0 +1,7 @@
%module "enum_thorough_typesafe"
// Test enum wrapping using the typesafe enum pattern in the target language
%include "enumtypesafe.swg"
%include "enum_thorough.i"

View file

@ -0,0 +1,7 @@
%module "enum_thorough_typeunsafe"
// Test enum wrapping using a type unsafe enum pattern (constant integers in a class for the enum type)
%include "enumtypeunsafe.swg"
%include "enum_thorough.i"

View file

@ -3,7 +3,9 @@
%module java_enums
// Some pragmas to add in an interface to the module class - checks that the java_enumsConstants interface class is also 'implemented'
%include "enumtypeunsafe.swg"
// Some pragmas to add in an interface to the module class
%pragma(java) moduleinterfaces="Serializable"
%pragma(java) moduleimports=%{
import java.io.*; // For Serializable
@ -12,6 +14,9 @@ import java.io.*; // For Serializable
// Set default Java const code generation
%javaconst(1);
// Change the default generation so that these enums are generated into an interface instead of a class
%typemap(javaclassmodifiers) enum stuff "public interface"
%inline %{
enum stuff { FIDDLE = 2*100, STICKS = 5+8, BONGO, DRUMS };
%}
@ -28,7 +33,6 @@ enum stuff { FIDDLE = 2*100, STICKS = 5+8, BONGO, DRUMS };
return $jnicall;
}
%inline %{
enum nonsense { POPPYCOCK, JUNK };
nonsense test1(nonsense n) { return n; }

View file

@ -1,6 +1,8 @@
/* Testcase for the Java array typemaps which are not used by default. */
%module java_lib_arrays
%include "enumtypeunsafe.swg"
/* Use the Java library typemaps */
%include "arrays_java.i"