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
4
SWIG/Examples/ruby/import/.cvsignore
Normal file
4
SWIG/Examples/ruby/import/.cvsignore
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
bar_wrap.cxx
|
||||
base_wrap.cxx
|
||||
foo_wrap.cxx
|
||||
spam_wrap.cxx
|
||||
20
SWIG/Examples/ruby/import/Makefile
Normal file
20
SWIG/Examples/ruby/import/Makefile
Normal 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
|
||||
28
SWIG/Examples/ruby/import/README
Normal file
28
SWIG/Examples/ruby/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 '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.
|
||||
|
||||
|
||||
|
||||
|
||||
21
SWIG/Examples/ruby/import/bar.h
Normal file
21
SWIG/Examples/ruby/import/bar.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "base.h"
|
||||
|
||||
class Bar : public Base {
|
||||
public:
|
||||
Bar() { }
|
||||
~Bar() { }
|
||||
virtual const char * A() const {
|
||||
return "Bar::A";
|
||||
}
|
||||
const char * B() const {
|
||||
return "Bar::B";
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
static Bar *fromBase(Base *b) {
|
||||
return dynamic_cast<Bar *>(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
9
SWIG/Examples/ruby/import/bar.i
Normal file
9
SWIG/Examples/ruby/import/bar.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module bar
|
||||
%{
|
||||
#include "bar.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "bar.h"
|
||||
|
||||
|
||||
16
SWIG/Examples/ruby/import/base.h
Normal file
16
SWIG/Examples/ruby/import/base.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class Base {
|
||||
public:
|
||||
Base() { };
|
||||
~Base() { };
|
||||
virtual const char * A() const {
|
||||
return "Base::A";
|
||||
}
|
||||
const char * B() const {
|
||||
return "Base::B";
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
6
SWIG/Examples/ruby/import/base.i
Normal file
6
SWIG/Examples/ruby/import/base.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module base
|
||||
%{
|
||||
#include "base.h"
|
||||
%}
|
||||
|
||||
%include base.h
|
||||
21
SWIG/Examples/ruby/import/foo.h
Normal file
21
SWIG/Examples/ruby/import/foo.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "base.h"
|
||||
|
||||
class Foo : public Base {
|
||||
public:
|
||||
Foo() { }
|
||||
~Foo() { }
|
||||
virtual const char * A() const {
|
||||
return "Foo::A";
|
||||
}
|
||||
const char * B() const {
|
||||
return "Foo::B";
|
||||
}
|
||||
virtual Base *toBase() {
|
||||
return static_cast<Base *>(this);
|
||||
}
|
||||
static Foo *fromBase(Base *b) {
|
||||
return dynamic_cast<Foo *>(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
8
SWIG/Examples/ruby/import/foo.i
Normal file
8
SWIG/Examples/ruby/import/foo.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%module foo
|
||||
%{
|
||||
#include "foo.h"
|
||||
%}
|
||||
|
||||
%import base.i
|
||||
%include "foo.h"
|
||||
|
||||
90
SWIG/Examples/ruby/import/runme.rb
Normal file
90
SWIG/Examples/ruby/import/runme.rb
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# file: runme.rb
|
||||
# Test various properties of classes defined in separate modules
|
||||
|
||||
puts "Testing the %import directive"
|
||||
|
||||
require 'base'
|
||||
require 'foo'
|
||||
require 'bar'
|
||||
require 'spam'
|
||||
|
||||
# Create some objects
|
||||
|
||||
puts "Creating some objects"
|
||||
|
||||
a = Base::Base.new
|
||||
b = Foo::Foo.new
|
||||
c = Bar::Bar.new
|
||||
d = Spam::Spam.new
|
||||
|
||||
# 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"
|
||||
|
||||
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::Foo.fromBase(x)
|
||||
if y != nil
|
||||
puts "bad swig"
|
||||
else
|
||||
puts "good swig"
|
||||
end
|
||||
|
||||
puts " Spam -> Base -> Bar : "
|
||||
y = Bar::Bar.fromBase(x)
|
||||
if y != nil
|
||||
puts "good swig"
|
||||
else
|
||||
puts "bad swig"
|
||||
end
|
||||
|
||||
puts " Spam -> Base -> Spam : "
|
||||
y = Spam::Spam.fromBase(x)
|
||||
if y != nil
|
||||
puts "good swig"
|
||||
else
|
||||
puts "bad swig"
|
||||
end
|
||||
|
||||
puts " Foo -> Spam : "
|
||||
y = Spam::Spam.fromBase(b)
|
||||
if y != nil
|
||||
puts "bad swig"
|
||||
else
|
||||
puts "good swig"
|
||||
end
|
||||
24
SWIG/Examples/ruby/import/spam.h
Normal file
24
SWIG/Examples/ruby/import/spam.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "bar.h"
|
||||
|
||||
class Spam : public Bar {
|
||||
public:
|
||||
Spam() { }
|
||||
~Spam() { }
|
||||
virtual const char * A() const {
|
||||
return "Spam::A";
|
||||
}
|
||||
const char * B() const {
|
||||
return "Spam::B";
|
||||
}
|
||||
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/ruby/import/spam.i
Normal file
9
SWIG/Examples/ruby/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