The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5fcae5eb66
commit
12a43edc2d
1508 changed files with 125983 additions and 44037 deletions
4
Examples/tcl/import/.cvsignore
Normal file
4
Examples/tcl/import/.cvsignore
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
bar_wrap.cxx
|
||||
base_wrap.cxx
|
||||
foo_wrap.cxx
|
||||
spam_wrap.cxx
|
||||
22
Examples/tcl/import/Makefile
Normal file
22
Examples/tcl/import/Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -c
|
||||
#If your system requires linking with the runtime libraries then set the directory location here
|
||||
RUNTIMEDIR =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='base' INTERFACE='base.i' tcl_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='foo' INTERFACE='foo.i' tcl_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='bar' INTERFACE='bar.i' tcl_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='spam' INTERFACE='spam.i' tcl_multi_cpp
|
||||
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile tcl_clean
|
||||
|
||||
check: all
|
||||
28
Examples/tcl/import/README
Normal file
28
Examples/tcl/import/README
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
This example tests the SWIG run-time libraries and use of the
|
||||
%import directive to work with multiple modules.
|
||||
|
||||
Use 'tclsh runme.tcl' to run a test.
|
||||
|
||||
Overview:
|
||||
---------
|
||||
|
||||
The example defines 4 different extension modules--each wrapping
|
||||
a separate C++ class.
|
||||
|
||||
base.i - Base class
|
||||
foo.i - Foo class derived from Base
|
||||
bar.i - Bar class derived from Base
|
||||
spam.i - Spam class derived from Bar
|
||||
|
||||
Each module used %import to refer to another module. For
|
||||
example, the 'foo.i' module uses '%import base.i' to get
|
||||
definitions for its base class.
|
||||
|
||||
If everything is working correctly, all of the modules will load
|
||||
correctly and type checking will work correctly. The
|
||||
example requires the use of the SWIG run-time libraries
|
||||
which must be built and properly installed.
|
||||
|
||||
|
||||
|
||||
|
||||
22
Examples/tcl/import/bar.h
Normal file
22
Examples/tcl/import/bar.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "base.h"
|
||||
|
||||
class Bar : public Base {
|
||||
public:
|
||||
Bar() { }
|
||||
~Bar() { }
|
||||
virtual void A() {
|
||||
printf("I'm Bar::A\n");
|
||||
}
|
||||
void B() {
|
||||
printf("I'm Bar::B\n");
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
static Bar *fromBase(Base *b) {
|
||||
return dynamic_cast<Bar *>(b);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
9
Examples/tcl/import/bar.i
Normal file
9
Examples/tcl/import/bar.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module bar
|
||||
%{
|
||||
#include "bar.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "bar.h"
|
||||
|
||||
|
||||
18
Examples/tcl/import/base.h
Normal file
18
Examples/tcl/import/base.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base() { };
|
||||
~Base() { };
|
||||
virtual void A() {
|
||||
printf("I'm Base::A\n");
|
||||
}
|
||||
void B() {
|
||||
printf("I'm Base::B\n");
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
6
Examples/tcl/import/base.i
Normal file
6
Examples/tcl/import/base.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module base
|
||||
%{
|
||||
#include "base.h"
|
||||
%}
|
||||
|
||||
%include base.h
|
||||
21
Examples/tcl/import/foo.h
Normal file
21
Examples/tcl/import/foo.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "base.h"
|
||||
|
||||
class Foo : public Base {
|
||||
public:
|
||||
Foo() { }
|
||||
~Foo() { }
|
||||
virtual void A() {
|
||||
printf("I'm Foo::A\n");
|
||||
}
|
||||
void B() {
|
||||
printf("I'm Foo::B\n");
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
static Foo *fromBase(Base *b) {
|
||||
return dynamic_cast<Foo *>(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
8
Examples/tcl/import/foo.i
Normal file
8
Examples/tcl/import/foo.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%module foo
|
||||
%{
|
||||
#include "foo.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "foo.h"
|
||||
|
||||
121
Examples/tcl/import/runme.tcl
Normal file
121
Examples/tcl/import/runme.tcl
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
# file: runme.py
|
||||
# Test various properties of classes defined in separate modules
|
||||
|
||||
puts "Testing the %import directive"
|
||||
catch { load ./base.so base}
|
||||
catch { load ./base.dll base} ;# Windows
|
||||
|
||||
catch { load ./foo.so foo}
|
||||
catch { load ./foo.dll foo} ;# Windows
|
||||
|
||||
catch { load ./bar.so bar}
|
||||
catch { load ./bar.dll bar} ;# Windows
|
||||
|
||||
catch { load ./spam.so spam}
|
||||
catch { load ./spam.dll spam} ;# Windows
|
||||
|
||||
# Create some objects
|
||||
|
||||
puts "Creating some objects"
|
||||
|
||||
set a [Base]
|
||||
set b [Foo]
|
||||
set c [Bar]
|
||||
set d [Spam]
|
||||
|
||||
# Try calling some methods
|
||||
puts "Testing some methods"
|
||||
puts "Should see 'Base::A' ---> "
|
||||
$a A
|
||||
puts "Should see 'Base::B' ---> "
|
||||
$a B
|
||||
|
||||
puts "Should see 'Foo::A' ---> "
|
||||
$b A
|
||||
puts "Should see 'Foo::B' ---> "
|
||||
$b B
|
||||
|
||||
puts "Should see 'Bar::A' ---> "
|
||||
$c A
|
||||
puts "Should see 'Bar::B' ---> "
|
||||
$c B
|
||||
|
||||
puts "Should see 'Spam::A' ---> "
|
||||
$d A
|
||||
puts "Should see 'Spam::B' ---> "
|
||||
$d B
|
||||
|
||||
# Try some casts
|
||||
|
||||
puts "\nTesting some casts\n"
|
||||
|
||||
Base x -this [$a toBase]
|
||||
puts "Should see 'Base::A' ---> "
|
||||
x A
|
||||
puts "Should see 'Base::B' ---> "
|
||||
x B
|
||||
rename x ""
|
||||
|
||||
Base x -this [$b toBase]
|
||||
puts "Should see 'Foo::A' ---> "
|
||||
x A
|
||||
puts "Should see 'Base::B' ---> "
|
||||
x B
|
||||
rename x ""
|
||||
|
||||
Base x -this [$c toBase]
|
||||
puts "Should see 'Bar::A' ---> "
|
||||
x A
|
||||
puts "Should see 'Base::B' ---> "
|
||||
x B
|
||||
rename x ""
|
||||
|
||||
Base x -this [$d toBase]
|
||||
puts "Should see 'Spam::A' ---> "
|
||||
x A
|
||||
puts "Should see 'Base::B' ---> "
|
||||
x B
|
||||
rename x ""
|
||||
|
||||
Bar x -this [$d toBar]
|
||||
puts "Should see 'Bar::B' ---> "
|
||||
x B
|
||||
rename x ""
|
||||
|
||||
puts "\nTesting some dynamic casts\n"
|
||||
Base x -this [$d toBase]
|
||||
|
||||
puts "Spam -> Base -> Foo : "
|
||||
set y [Foo_fromBase [x cget -this]]
|
||||
if {$y != "NULL"} {
|
||||
puts "bad swig"
|
||||
} {
|
||||
puts "good swig"
|
||||
}
|
||||
|
||||
puts "Spam -> Base -> Bar : "
|
||||
set y [Bar_fromBase [x cget -this]]
|
||||
if {$y != "NULL"} {
|
||||
puts "good swig"
|
||||
} {
|
||||
puts "bad swig"
|
||||
}
|
||||
|
||||
puts "Spam -> Base -> Spam : "
|
||||
set y [Spam_fromBase [x cget -this]]
|
||||
if {$y != "NULL"} {
|
||||
puts "good swig"
|
||||
} {
|
||||
puts "bad swig"
|
||||
}
|
||||
|
||||
puts "Foo -> Spam : "
|
||||
set y [Spam_fromBase $b]
|
||||
if {$y != "NULL"} {
|
||||
puts "bad swig"
|
||||
} {
|
||||
puts "good swig"
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
Examples/tcl/import/spam.h
Normal file
24
Examples/tcl/import/spam.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "bar.h"
|
||||
|
||||
class Spam : public Bar {
|
||||
public:
|
||||
Spam() { }
|
||||
~Spam() { }
|
||||
virtual void A() {
|
||||
printf("I'm Spam::A\n");
|
||||
}
|
||||
void B() {
|
||||
printf("I'm Spam::B\n");
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
virtual Bar *toBar() {
|
||||
return static_cast<Bar *>(this);
|
||||
}
|
||||
static Spam *fromBase(Base *b) {
|
||||
return dynamic_cast<Spam *>(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
9
Examples/tcl/import/spam.i
Normal file
9
Examples/tcl/import/spam.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module spam
|
||||
%{
|
||||
#include "spam.h"
|
||||
%}
|
||||
|
||||
%import bar.i
|
||||
%include "spam.h"
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue