Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SWIGOPT =
LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean

View File

@@ -0,0 +1,30 @@
This example tests the %import directive and working 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 uses %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 okay, all of the modules will load properly and
type checking will work correctly. Caveat: Some compilers, for example
gcc-3.2.x, generate broken vtables with the inline methods in this test.
This is not a SWIG problem and can usually be solved with non-inlined
destructors compiled into separate shared objects/DLLs.
Unix:
-----
- Run make
- Run the test as described above

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() { };
virtual ~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>;