mirror of https://github.com/swig/swig
csharp examples
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4433 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
25b125e1e0
commit
719959886d
|
@ -0,0 +1,3 @@
|
|||
# see top-level Makefile.in
|
||||
enum
|
||||
simple
|
|
@ -0,0 +1,14 @@
|
|||
runme
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.iltmp
|
||||
*.cs
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
|
@ -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
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
@ -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"
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
runme
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.iltmp
|
||||
*.cs
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue