From 2824b0cbb66e715490e1ef13250bd675d87b32d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:53:17 +0000 Subject: rel-2.0.0 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/tags/rel-2.0.0@12089 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- trunk/Examples/csharp/enum/Makefile | 20 ++++ trunk/Examples/csharp/enum/example-cs.csproj | 99 +++++++++++++++++ trunk/Examples/csharp/enum/example-vc.vcproj | 158 +++++++++++++++++++++++++++ trunk/Examples/csharp/enum/example.cxx | 37 +++++++ trunk/Examples/csharp/enum/example.h | 13 +++ trunk/Examples/csharp/enum/example.i | 11 ++ trunk/Examples/csharp/enum/example.sln | 30 +++++ trunk/Examples/csharp/enum/runme.cs | 31 ++++++ 8 files changed, 399 insertions(+) create mode 100644 trunk/Examples/csharp/enum/Makefile create mode 100644 trunk/Examples/csharp/enum/example-cs.csproj create mode 100644 trunk/Examples/csharp/enum/example-vc.vcproj create mode 100644 trunk/Examples/csharp/enum/example.cxx create mode 100644 trunk/Examples/csharp/enum/example.h create mode 100644 trunk/Examples/csharp/enum/example.i create mode 100644 trunk/Examples/csharp/enum/example.sln create mode 100644 trunk/Examples/csharp/enum/runme.cs (limited to 'trunk/Examples/csharp/enum') diff --git a/trunk/Examples/csharp/enum/Makefile b/trunk/Examples/csharp/enum/Makefile new file mode 100644 index 000000000..20f0dd5bb --- /dev/null +++ b/trunk/Examples/csharp/enum/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -nologo -out:runme.exe + +all:: csharp + +csharp:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp + $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + +clean:: + $(MAKE) -f $(TOP)/Makefile csharp_clean + +check: all diff --git a/trunk/Examples/csharp/enum/example-cs.csproj b/trunk/Examples/csharp/enum/example-cs.csproj new file mode 100644 index 000000000..9d37ce2b4 --- /dev/null +++ b/trunk/Examples/csharp/enum/example-cs.csproj @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/enum/example-vc.vcproj b/trunk/Examples/csharp/enum/example-vc.vcproj new file mode 100644 index 000000000..7c0b8ef13 --- /dev/null +++ b/trunk/Examples/csharp/enum/example-vc.vcproj @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/enum/example.cxx b/trunk/Examples/csharp/enum/example.cxx new file mode 100644 index 000000000..df7bb6328 --- /dev/null +++ b/trunk/Examples/csharp/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.cxx */ + +#include "example.h" +#include + +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"); + } +} diff --git a/trunk/Examples/csharp/enum/example.h b/trunk/Examples/csharp/enum/example.h new file mode 100644 index 000000000..9119cd9fc --- /dev/null +++ b/trunk/Examples/csharp/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/trunk/Examples/csharp/enum/example.i b/trunk/Examples/csharp/enum/example.i new file mode 100644 index 000000000..23ee8a822 --- /dev/null +++ b/trunk/Examples/csharp/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/trunk/Examples/csharp/enum/example.sln b/trunk/Examples/csharp/enum/example.sln new file mode 100644 index 000000000..28b9851b0 --- /dev/null +++ b/trunk/Examples/csharp/enum/example.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/trunk/Examples/csharp/enum/runme.cs b/trunk/Examples/csharp/enum/runme.cs new file mode 100644 index 000000000..42ba896a2 --- /dev/null +++ b/trunk/Examples/csharp/enum/runme.cs @@ -0,0 +1,31 @@ +using System; + +public class runme +{ + static void Main() + { + // Print out the value of some enums + Console.WriteLine("*** color ***"); + Console.WriteLine(" " + color.RED + " = " + (int)color.RED); + Console.WriteLine(" " + color.BLUE + " = " + (int)color.BLUE); + Console.WriteLine(" " + color.GREEN + " = " + (int)color.GREEN); + + Console.WriteLine("\n*** Foo::speed ***"); + Console.WriteLine(" Foo::" + Foo.speed.IMPULSE + " = " + (int)Foo.speed.IMPULSE); + Console.WriteLine(" Foo::" + Foo.speed.WARP + " = " + (int)Foo.speed.WARP); + Console.WriteLine(" Foo::" + Foo.speed.LUDICROUS + " = " + (int)Foo.speed.LUDICROUS); + + Console.WriteLine("\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); + + Console.WriteLine( "\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); + } +} -- cgit v1.2.1