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:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

View file

@ -0,0 +1,4 @@
bar_wrap.cxx
base_wrap.cxx
foo_wrap.cxx
spam_wrap.cxx

View file

@ -0,0 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIGOPT = -c
#If your system requires linking with the runtime libraries then set the directory location here
RUNTIMEDIR = /usr/local/lib
all::
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='base' INTERFACE='base.i' ruby_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='foo' INTERFACE='foo.i' ruby_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='bar' INTERFACE='bar.i' ruby_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='spam' INTERFACE='spam.i' ruby_multi_cpp
clean::
$(MAKE) -f $(TOP)/Makefile ruby_clean
check: all

View file

@ -0,0 +1,30 @@
This example tests the SWIG run-time libraries and use of the
%import directive to work with multiple modules. However,
unlike the import example, this uses templates to really
stress test the type-system.
Use 'ruby runme.rb' 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.

View file

@ -0,0 +1,22 @@
#include "base.h"
template<class T> class Bar : public Base<T> {
public:
Bar() { }
~Bar() { }
virtual const char * A() const {
return "Bar::A";
}
const char * B() const {
return "Bar::B";
}
virtual Base<T> *toBase() {
return static_cast<Base<T> *>(this);
}
static Bar<T> *fromBase(Base<T> *b) {
return dynamic_cast<Bar<T> *>(b);
}
};

View file

@ -0,0 +1,11 @@
%module bar
%{
#include "bar.h"
%}
%import base.i
%include "bar.h"
%template(IntBar) Bar<int>;

View file

@ -0,0 +1,18 @@
#include <stdio.h>
template<class T> class Base {
public:
Base() { };
~Base() { };
virtual const char * A() const {
return "Base::A";
}
const char * B() const {
return "Base::B";
}
virtual Base<T> *toBase() {
return static_cast<Base<T> *>(this);
}
};

View file

@ -0,0 +1,7 @@
%module base
%{
#include "base.h"
%}
%include base.h
%template(IntBase) Base<int>;

View file

@ -0,0 +1,21 @@
#include "base.h"
template<class T> class Foo : public Base<T> {
public:
Foo() { }
~Foo() { }
virtual const char * A() const {
return "Foo::A";
}
const char * B() const {
return "Foo::B";
}
virtual Base<T> *toBase() {
return static_cast<Base<T> *>(this);
}
static Foo<T> *fromBase(Base<T> *b) {
return dynamic_cast<Foo<T> *>(b);
}
};

View file

@ -0,0 +1,10 @@
%module foo
%{
#include "foo.h"
%}
%import base.i
%include "foo.h"
%template(IntFoo) Foo<int>;

View file

@ -0,0 +1,92 @@
# file: runme.rb
# Test various properties of classes defined in separate modules
puts "Testing the %import directive with templates"
require 'base'
require 'foo'
require 'bar'
require 'spam'
# Create some objects
puts "Creating some objects"
a = Base::IntBase.new
b = Foo::IntFoo.new
c = Bar::IntBar.new
d = Spam::IntSpam.new
# Try calling some methods
puts "Testing some methods"
puts ""
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"
puts ""
x = a.toBase
puts "Should see 'Base::A' ---> #{x.A}"
puts "Should see 'Base::B' ---> #{x.B}"
x = b.toBase
puts "Should see 'Foo::A' ---> #{x.A}"
puts "Should see 'Base::B' ---> #{x.B}"
x = c.toBase
puts "Should see 'Bar::A' ---> #{x.A}"
puts "Should see 'Base::B' ---> #{x.B}"
x = d.toBase
puts "Should see 'Spam::A' ---> #{x.A}"
puts "Should see 'Base::B' ---> #{x.B}"
x = d.toBar
puts "Should see 'Bar::B' ---> #{x.B}"
puts "\nTesting some dynamic casts\n"
x = d.toBase
puts " Spam -> Base -> Foo : "
y = Foo::IntFoo.fromBase(x)
if y != nil
puts "bad swig"
else
puts "good swig"
end
puts " Spam -> Base -> Bar : "
y = Bar::IntBar.fromBase(x)
if y != nil
puts "good swig"
else
puts "bad swig"
end
puts " Spam -> Base -> Spam : "
y = Spam::IntSpam.fromBase(x)
if y != nil
puts "good swig"
else
puts "bad swig"
end
puts " Foo -> Spam : "
y = Spam::IntSpam.fromBase(b)
if y != nil
puts "bad swig"
else
puts "good swig"
end

View file

@ -0,0 +1,24 @@
#include "bar.h"
template<class T> class Spam : public Bar<T> {
public:
Spam() { }
~Spam() { }
virtual const char * A() const {
return "Spam::A";
}
const char * B() const {
return "Spam::B";
}
virtual Base<T> *toBase() {
return static_cast<Base<T> *>(this);
}
virtual Bar<T> *toBar() {
return static_cast<Bar<T> *>(this);
}
static Spam<T> *fromBase(Base<T> *b) {
return dynamic_cast<Spam<T> *>(b);
}
};

View file

@ -0,0 +1,10 @@
%module spam
%{
#include "spam.h"
%}
%import bar.i
%include "spam.h"
%template(IntSpam) Spam<int>;