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/callback/Makefile | 20 +++ trunk/Examples/csharp/callback/example-cs.csproj | 99 ++++++++++++++ trunk/Examples/csharp/callback/example-vc.vcproj | 158 +++++++++++++++++++++++ trunk/Examples/csharp/callback/example.cxx | 4 + trunk/Examples/csharp/callback/example.h | 24 ++++ trunk/Examples/csharp/callback/example.i | 13 ++ trunk/Examples/csharp/callback/example.sln | 30 +++++ trunk/Examples/csharp/callback/runme.cs | 46 +++++++ 8 files changed, 394 insertions(+) create mode 100644 trunk/Examples/csharp/callback/Makefile create mode 100644 trunk/Examples/csharp/callback/example-cs.csproj create mode 100644 trunk/Examples/csharp/callback/example-vc.vcproj create mode 100644 trunk/Examples/csharp/callback/example.cxx create mode 100644 trunk/Examples/csharp/callback/example.h create mode 100644 trunk/Examples/csharp/callback/example.i create mode 100644 trunk/Examples/csharp/callback/example.sln create mode 100644 trunk/Examples/csharp/callback/runme.cs (limited to 'trunk/Examples/csharp/callback') diff --git a/trunk/Examples/csharp/callback/Makefile b/trunk/Examples/csharp/callback/Makefile new file mode 100644 index 000000000..51b163b85 --- /dev/null +++ b/trunk/Examples/csharp/callback/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -debug -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/callback/example-cs.csproj b/trunk/Examples/csharp/callback/example-cs.csproj new file mode 100644 index 000000000..5fc34527f --- /dev/null +++ b/trunk/Examples/csharp/callback/example-cs.csproj @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/callback/example-vc.vcproj b/trunk/Examples/csharp/callback/example-vc.vcproj new file mode 100644 index 000000000..7c0b8ef13 --- /dev/null +++ b/trunk/Examples/csharp/callback/example-vc.vcproj @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/callback/example.cxx b/trunk/Examples/csharp/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/trunk/Examples/csharp/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/trunk/Examples/csharp/callback/example.h b/trunk/Examples/csharp/callback/example.h new file mode 100644 index 000000000..38d25a043 --- /dev/null +++ b/trunk/Examples/csharp/callback/example.h @@ -0,0 +1,24 @@ +/* File : example.h */ + +#include +#include + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void resetCallback() { _callback = 0; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/trunk/Examples/csharp/callback/example.i b/trunk/Examples/csharp/callback/example.i new file mode 100644 index 000000000..90beda01a --- /dev/null +++ b/trunk/Examples/csharp/callback/example.i @@ -0,0 +1,13 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +%include "example.h" + diff --git a/trunk/Examples/csharp/callback/example.sln b/trunk/Examples/csharp/callback/example.sln new file mode 100644 index 000000000..28b9851b0 --- /dev/null +++ b/trunk/Examples/csharp/callback/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/callback/runme.cs b/trunk/Examples/csharp/callback/runme.cs new file mode 100644 index 000000000..a104b1a3e --- /dev/null +++ b/trunk/Examples/csharp/callback/runme.cs @@ -0,0 +1,46 @@ +using System; + +public class runme +{ + static void Main() + { + Console.WriteLine("Adding and calling a normal C++ callback"); + Console.WriteLine("----------------------------------------"); + + Caller caller = new Caller(); + using (Callback callback = new Callback()) + { + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Console.WriteLine(); + Console.WriteLine("Adding and calling a C# callback"); + Console.WriteLine("------------------------------------"); + + using (Callback callback = new CSharpCallback()) + { + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Console.WriteLine(); + Console.WriteLine("C# exit"); + } +} + +public class CSharpCallback : Callback +{ + public CSharpCallback() + : base() + { + } + + public override void run() + { + Console.WriteLine("CSharpCallback.run()"); + } +} + -- cgit v1.2.1