diff --git a/SWIG/Examples/csharp/check.list b/SWIG/Examples/csharp/check.list new file mode 100644 index 000000000..ea5678645 --- /dev/null +++ b/SWIG/Examples/csharp/check.list @@ -0,0 +1,3 @@ +# see top-level Makefile.in +enum +simple diff --git a/SWIG/Examples/csharp/enum/.cvsignore b/SWIG/Examples/csharp/enum/.cvsignore new file mode 100644 index 000000000..fccb2721d --- /dev/null +++ b/SWIG/Examples/csharp/enum/.cvsignore @@ -0,0 +1,14 @@ +runme +*_wrap.c +*_wrap.cxx +*.iltmp +*.cs +*.dll +*.dsw +*.exp +*.lib +*.ncb +*.opt +*.plg +Release +Debug diff --git a/SWIG/Examples/csharp/enum/Makefile b/SWIG/Examples/csharp/enum/Makefile new file mode 100644 index 000000000..953d5cc96 --- /dev/null +++ b/SWIG/Examples/csharp/enum/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -o runme + +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/SWIG/Examples/csharp/enum/example.cxx b/SWIG/Examples/csharp/enum/example.cxx new file mode 100644 index 000000000..df7bb6328 --- /dev/null +++ b/SWIG/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/SWIG/Examples/csharp/enum/example.h b/SWIG/Examples/csharp/enum/example.h new file mode 100644 index 000000000..525d62afc --- /dev/null +++ b/SWIG/Examples/csharp/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE, WARP, LUDICROUS }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/SWIG/Examples/csharp/enum/example.i b/SWIG/Examples/csharp/enum/example.i new file mode 100644 index 000000000..4c873824c --- /dev/null +++ b/SWIG/Examples/csharp/enum/example.i @@ -0,0 +1,13 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%pragma make_default + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/SWIG/Examples/csharp/enum/runme.cs b/SWIG/Examples/csharp/enum/runme.cs new file mode 100644 index 000000000..dbecf6b56 --- /dev/null +++ b/SWIG/Examples/csharp/enum/runme.cs @@ -0,0 +1,30 @@ +public class runme +{ + static void Main() + { + // Print out the value of some enums + Console.WriteLine("*** color ***"); + Console.WriteLine(" RED = " + example.RED); + Console.WriteLine(" BLUE = " + example.BLUE); + Console.WriteLine(" GREEN = " + example.GREEN); + + Console.WriteLine("\n*** Foo::speed ***"); + Console.WriteLine(" Foo::IMPULSE = " + Foo.IMPULSE); + Console.WriteLine(" Foo::WARP = " + Foo.WARP); + Console.WriteLine(" Foo::LUDICROUS = " + Foo.LUDICROUS); + + Console.WriteLine("\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); + + Console.WriteLine( "\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); + } +} diff --git a/SWIG/Examples/csharp/simple/.cvsignore b/SWIG/Examples/csharp/simple/.cvsignore new file mode 100644 index 000000000..fccb2721d --- /dev/null +++ b/SWIG/Examples/csharp/simple/.cvsignore @@ -0,0 +1,14 @@ +runme +*_wrap.c +*_wrap.cxx +*.iltmp +*.cs +*.dll +*.dsw +*.exp +*.lib +*.ncb +*.opt +*.plg +Release +Debug diff --git a/SWIG/Examples/csharp/simple/Makefile b/SWIG/Examples/csharp/simple/Makefile new file mode 100644 index 000000000..08ce054a0 --- /dev/null +++ b/SWIG/Examples/csharp/simple/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -o runme + +all:: csharp + +csharp:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp + $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + +clean:: + $(MAKE) -f $(TOP)/Makefile csharp_clean + +check: all diff --git a/SWIG/Examples/csharp/simple/example.c b/SWIG/Examples/csharp/simple/example.c new file mode 100644 index 000000000..1c2af789c --- /dev/null +++ b/SWIG/Examples/csharp/simple/example.c @@ -0,0 +1,18 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/SWIG/Examples/csharp/simple/example.i b/SWIG/Examples/csharp/simple/example.i new file mode 100644 index 000000000..6702abb1e --- /dev/null +++ b/SWIG/Examples/csharp/simple/example.i @@ -0,0 +1,5 @@ +/* File : example.i */ +%module example + +extern int gcd(int x, int y); +extern double Foo; diff --git a/SWIG/Examples/csharp/simple/runme.cs b/SWIG/Examples/csharp/simple/runme.cs new file mode 100644 index 000000000..05dff9e0b --- /dev/null +++ b/SWIG/Examples/csharp/simple/runme.cs @@ -0,0 +1,23 @@ +public class runme +{ + static void Main() + { + // Call our gcd() function + + int x = 42; + int y = 105; + int g = example.gcd(x,y); + Console.WriteLine("The gcd of " + x + " and " + y + " is " + g); + + // Manipulate the Foo global variable + + // Output its current value + Console.WriteLine("Foo = " + example.getFoo()); + + // Change its value + example.setFoo(3.1415926); + + // See if the change took effect + Console.WriteLine("Foo = " + example.getFoo()); + } +}