adding Prabhu's 'weave' example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6768 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a111449e8c
commit
58326f9cc8
5 changed files with 125 additions and 0 deletions
1
Examples/python/weave/.cvsignore
Normal file
1
Examples/python/weave/.cvsignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
example.py example_wrap.cxx example_wrap.h
|
||||||
21
Examples/python/weave/Makefile
Normal file
21
Examples/python/weave/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIG = $(TOP)/../preinst-swig
|
||||||
|
CXXSRCS =
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS = -lm
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
all::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||||
|
|
||||||
|
static::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||||
|
|
||||||
|
clean::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||||
|
rm -f $(TARGET).py
|
||||||
|
|
||||||
|
check: all
|
||||||
18
Examples/python/weave/example.h
Normal file
18
Examples/python/weave/example.h
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef _EXAMPLE_H
|
||||||
|
#define _EXAMPLE_H
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Bar {
|
||||||
|
public:
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FooBar : public Foo, public Bar {
|
||||||
|
public:
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
13
Examples/python/weave/example.i
Normal file
13
Examples/python/weave/example.i
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
%module(directors="1") example
|
||||||
|
%feature("director");
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "std_vector.i"
|
||||||
|
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
|
%template(VectorBar) std::vector<Bar*>;
|
||||||
|
%template(VectorFoo) std::vector<Foo*>;
|
||||||
72
Examples/python/weave/runme.py
Normal file
72
Examples/python/weave/runme.py
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
"""
|
||||||
|
Test weave support for SWIG wrapped objects.
|
||||||
|
|
||||||
|
This example requires that one has weave installed. Weave is
|
||||||
|
distributed as part of SciPy (http://www.scipy.org). More information
|
||||||
|
on Weave may be had from here:
|
||||||
|
|
||||||
|
http://www.scipy.org/documentation/weave
|
||||||
|
|
||||||
|
As of November 22, 2004, this only works with weave from CVS. If
|
||||||
|
there is a more recent release of SciPy after this data, it should
|
||||||
|
work fine.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import example
|
||||||
|
import weave
|
||||||
|
from weave import converters
|
||||||
|
from weave import swig2_spec
|
||||||
|
|
||||||
|
# Weave does not support swig2 by default (yet). So add this to the
|
||||||
|
# list of default converters to test.
|
||||||
|
converters.default.insert(0, swig2_spec.swig2_converter())
|
||||||
|
|
||||||
|
def test():
|
||||||
|
""" A simple test case for weave."""
|
||||||
|
a = example.Foo()
|
||||||
|
a.x = 1
|
||||||
|
b = example.Bar()
|
||||||
|
b.y = 2
|
||||||
|
c = example.FooBar()
|
||||||
|
c.x = 1
|
||||||
|
c.y = 2
|
||||||
|
c.z = 3
|
||||||
|
v = example.VectorBar()
|
||||||
|
v.append(b)
|
||||||
|
v.append(c)
|
||||||
|
d = v[0]
|
||||||
|
e = v[1]
|
||||||
|
v = example.VectorFoo()
|
||||||
|
v.append(a)
|
||||||
|
v.append(c)
|
||||||
|
f = v[0]
|
||||||
|
g = v[1]
|
||||||
|
|
||||||
|
code = """
|
||||||
|
std::cout << a->x << std::endl;
|
||||||
|
assert(a->x == 1);
|
||||||
|
std::cout << b->y << std::endl;
|
||||||
|
assert(b->y == 2);
|
||||||
|
std::cout << c->x << std::endl;
|
||||||
|
std::cout << c->y << std::endl;
|
||||||
|
std::cout << c->z << std::endl;
|
||||||
|
assert(c->x == 1);
|
||||||
|
assert(c->y == 2);
|
||||||
|
assert(c->z == 3);
|
||||||
|
std::cout << d->y << std::endl;
|
||||||
|
assert(d->y == 2);
|
||||||
|
std::cout << e->y << std::endl;
|
||||||
|
assert(e->y == 2);
|
||||||
|
std::cout << f->x << std::endl;
|
||||||
|
assert(f->x == 1);
|
||||||
|
std::cout << g->x << std::endl;
|
||||||
|
assert(g->x == 1);
|
||||||
|
"""
|
||||||
|
weave.inline(code, ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
||||||
|
include_dirs=['.'],
|
||||||
|
headers=['"example.h"'],
|
||||||
|
verbose=2)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue