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
14
Examples/perl5/import/.cvsignore
Normal file
14
Examples/perl5/import/.cvsignore
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
baseclass.pm
|
||||
example.pm
|
||||
foo.pm
|
||||
bar.pm
|
||||
spam.pm
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
example.dll
|
||||
example.dsw
|
||||
example.ncb
|
||||
example.opt
|
||||
example.plg
|
||||
Release
|
||||
Debug
|
||||
21
Examples/perl5/import/Makefile
Normal file
21
Examples/perl5/import/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -c -shadow
|
||||
#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='baseclass' INTERFACE='base.i' perl5_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='foo' INTERFACE='foo.i' perl5_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='bar' INTERFACE='bar.i' perl5_multi_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='spam' INTERFACE='spam.i' perl5_multi_cpp
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile perl5_clean
|
||||
|
||||
check: all
|
||||
28
Examples/perl5/import/README
Normal file
28
Examples/perl5/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 'perl runme.pl' 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/perl5/import/bar.h
Normal file
22
Examples/perl5/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/perl5/import/bar.i
Normal file
9
Examples/perl5/import/bar.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module bar
|
||||
%{
|
||||
#include "bar.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "bar.h"
|
||||
|
||||
|
||||
18
Examples/perl5/import/base.h
Normal file
18
Examples/perl5/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/perl5/import/base.i
Normal file
6
Examples/perl5/import/base.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module baseclass
|
||||
%{
|
||||
#include "base.h"
|
||||
%}
|
||||
|
||||
%include base.h
|
||||
21
Examples/perl5/import/foo.h
Normal file
21
Examples/perl5/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/perl5/import/foo.i
Normal file
8
Examples/perl5/import/foo.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%module foo
|
||||
%{
|
||||
#include "foo.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "foo.h"
|
||||
|
||||
116
Examples/perl5/import/runme.pl
Normal file
116
Examples/perl5/import/runme.pl
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# file: runme.pl
|
||||
# Test various properties of classes defined in separate modules
|
||||
|
||||
print "Testing the %import directive\n";
|
||||
use baseclass;
|
||||
use foo;
|
||||
use bar;
|
||||
use spam;
|
||||
|
||||
# Create some objects
|
||||
|
||||
print "Creating some objects\n";
|
||||
|
||||
$a = new baseclass::Base();
|
||||
$b = new foo::Foo();
|
||||
$c = new bar::Bar();
|
||||
$d = new spam::Spam();
|
||||
|
||||
# Try calling some methods
|
||||
print "Testing some methods\n";
|
||||
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";
|
||||
|
||||
$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\n";
|
||||
} else {
|
||||
print "good swig\n";
|
||||
}
|
||||
|
||||
print " Spam -> Base -> Bar : ";
|
||||
$y = bar::Bar_fromBase($x);
|
||||
if ($y) {
|
||||
print "good swig\n";
|
||||
} else {
|
||||
print "bad swig\n";
|
||||
}
|
||||
|
||||
print " Spam -> Base -> Spam : ";
|
||||
$y = spam::Spam_fromBase($x);
|
||||
if ($y) {
|
||||
print "good swig\n";
|
||||
} else {
|
||||
print "bad swig\n";
|
||||
}
|
||||
|
||||
print " Foo -> Spam : ";
|
||||
#print $b;
|
||||
$y = spam::Spam_fromBase($b);
|
||||
print $y;
|
||||
if ($y) {
|
||||
print "bad swig\n";
|
||||
} else {
|
||||
print "good swig\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
24
Examples/perl5/import/spam.h
Normal file
24
Examples/perl5/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/perl5/import/spam.i
Normal file
9
Examples/perl5/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