The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
13
SWIG/Examples/python/import/.cvsignore
Normal file
13
SWIG/Examples/python/import/.cvsignore
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
bar.py
|
||||
base.py
|
||||
foo.py
|
||||
spam.py
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
22
SWIG/Examples/python/import/Makefile
Normal file
22
SWIG/Examples/python/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' python_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='foo' INTERFACE='foo.i' python_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='bar' INTERFACE='bar.i' python_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='spam' INTERFACE='spam.i' python_multi_cpp
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
@rm -f foo.py bar.py spam.py base.py
|
||||
|
||||
check: all
|
||||
28
SWIG/Examples/python/import/README
Normal file
28
SWIG/Examples/python/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 'python runme.py' 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
SWIG/Examples/python/import/bar.h
Normal file
22
SWIG/Examples/python/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
SWIG/Examples/python/import/bar.i
Normal file
9
SWIG/Examples/python/import/bar.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module bar
|
||||
%{
|
||||
#include "bar.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "bar.h"
|
||||
|
||||
|
||||
18
SWIG/Examples/python/import/base.h
Normal file
18
SWIG/Examples/python/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
SWIG/Examples/python/import/base.i
Normal file
6
SWIG/Examples/python/import/base.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module base
|
||||
%{
|
||||
#include "base.h"
|
||||
%}
|
||||
|
||||
%include base.h
|
||||
21
SWIG/Examples/python/import/foo.h
Normal file
21
SWIG/Examples/python/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
SWIG/Examples/python/import/foo.i
Normal file
8
SWIG/Examples/python/import/foo.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%module foo
|
||||
%{
|
||||
#include "foo.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "foo.h"
|
||||
|
||||
111
SWIG/Examples/python/import/runme.py
Normal file
111
SWIG/Examples/python/import/runme.py
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
# file: runme.py
|
||||
# Test various properties of classes defined in separate modules
|
||||
|
||||
print "Testing the %import directive"
|
||||
import base
|
||||
import foo
|
||||
import bar
|
||||
import spam
|
||||
|
||||
# Create some objects
|
||||
|
||||
print "Creating some objects"
|
||||
|
||||
a = base.Base()
|
||||
b = foo.Foo()
|
||||
c = bar.Bar()
|
||||
d = spam.Spam()
|
||||
|
||||
# Try calling some methods
|
||||
print "Testing some methods"
|
||||
print "",
|
||||
print "Should see 'Base::A' ---> ",
|
||||
a.A()
|
||||
print "Should see 'Base::B' ---> ",
|
||||
a.B()
|
||||
|
||||
print "Should see 'Foo::A' ---> ",
|
||||
b.A()
|
||||
print "Should see 'Foo::B' ---> ",
|
||||
b.B()
|
||||
|
||||
print "Should see 'Bar::A' ---> ",
|
||||
c.A()
|
||||
print "Should see 'Bar::B' ---> ",
|
||||
c.B()
|
||||
|
||||
print "Should see 'Spam::A' ---> ",
|
||||
d.A()
|
||||
print "Should see 'Spam::B' ---> ",
|
||||
d.B()
|
||||
|
||||
# Try some casts
|
||||
|
||||
print "\nTesting some casts\n"
|
||||
print "",
|
||||
|
||||
x = a.toBase()
|
||||
print "Should see 'Base::A' ---> ",
|
||||
x.A()
|
||||
print "Should see 'Base::B' ---> ",
|
||||
x.B()
|
||||
|
||||
x = b.toBase()
|
||||
print "Should see 'Foo::A' ---> ",
|
||||
x.A()
|
||||
|
||||
print "Should see 'Base::B' ---> ",
|
||||
x.B()
|
||||
|
||||
x = c.toBase()
|
||||
print "Should see 'Bar::A' ---> ",
|
||||
x.A()
|
||||
|
||||
print "Should see 'Base::B' ---> ",
|
||||
x.B()
|
||||
|
||||
x = d.toBase()
|
||||
print "Should see 'Spam::A' ---> ",
|
||||
x.A()
|
||||
|
||||
print "Should see 'Base::B' ---> ",
|
||||
x.B()
|
||||
|
||||
x = d.toBar()
|
||||
print "Should see 'Bar::B' ---> ",
|
||||
x.B()
|
||||
|
||||
print "\nTesting some dynamic casts\n"
|
||||
x = d.toBase()
|
||||
|
||||
print " Spam -> Base -> Foo : ",
|
||||
y = foo.Foo_fromBase(x)
|
||||
if y:
|
||||
print "bad swig"
|
||||
else:
|
||||
print "good swig"
|
||||
|
||||
print " Spam -> Base -> Bar : ",
|
||||
y = bar.Bar_fromBase(x)
|
||||
if y:
|
||||
print "good swig"
|
||||
else:
|
||||
print "bad swig"
|
||||
|
||||
print " Spam -> Base -> Spam : ",
|
||||
y = spam.Spam_fromBase(x)
|
||||
if y:
|
||||
print "good swig"
|
||||
else:
|
||||
print "bad swig"
|
||||
|
||||
print " Foo -> Spam : ",
|
||||
y = spam.Spam_fromBase(b)
|
||||
if y:
|
||||
print "bad swig"
|
||||
else:
|
||||
print "good swig"
|
||||
|
||||
|
||||
|
||||
|
||||
24
SWIG/Examples/python/import/spam.h
Normal file
24
SWIG/Examples/python/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
SWIG/Examples/python/import/spam.i
Normal file
9
SWIG/Examples/python/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