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
9
Examples/python/reference/.cvsignore
Normal file
9
Examples/python/reference/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
|
|
@ -14,6 +14,7 @@ static::
|
|||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include "example.h"
|
||||
%}
|
||||
|
||||
%rename(cprint) print;
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
Vector(double x, double y, double z);
|
||||
|
|
@ -31,7 +33,7 @@ public:
|
|||
int size();
|
||||
|
||||
/* This wrapper provides an alternative to the [] operator */
|
||||
%addmethods {
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ import example
|
|||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:"
|
||||
a = example.new_Vector(3,4,5)
|
||||
b = example.new_Vector(10,11,12)
|
||||
a = example.Vector(3,4,5)
|
||||
b = example.Vector(10,11,12)
|
||||
|
||||
print " Created",example.Vector_print(a)
|
||||
print " Created",example.Vector_print(b)
|
||||
print " Created",a.cprint()
|
||||
print " Created",b.cprint()
|
||||
|
||||
# ----- Call an overloaded operator -----
|
||||
|
||||
|
|
@ -24,49 +24,41 @@ print " Created",example.Vector_print(b)
|
|||
|
||||
print "Adding a+b"
|
||||
c = example.addv(a,b)
|
||||
print " a+b =", example.Vector_print(c)
|
||||
print " a+b =", c.cprint()
|
||||
|
||||
# Note: Unless we free the result, a memory leak will occur
|
||||
example.delete_Vector(c)
|
||||
del c
|
||||
|
||||
# ----- Create a vector array -----
|
||||
|
||||
# Note: Using the high-level interface here
|
||||
print "Creating an array of vectors"
|
||||
va = example.new_VectorArray(10)
|
||||
va = example.VectorArray(10)
|
||||
print " va = ",va
|
||||
|
||||
# ----- Set some values in the array -----
|
||||
|
||||
# These operators copy the value of $a and $b to the vector array
|
||||
example.VectorArray_set(va,0,a)
|
||||
example.VectorArray_set(va,1,b)
|
||||
va.set(0,a)
|
||||
va.set(1,b)
|
||||
|
||||
# This will work, but it will cause a memory leak!
|
||||
|
||||
example.VectorArray_set(va,2,example.addv(a,b))
|
||||
|
||||
# The non-leaky way to do it
|
||||
|
||||
c = example.addv(a,b)
|
||||
example.VectorArray_set(va,3,c)
|
||||
example.delete_Vector(c)
|
||||
va.set(2,example.addv(a,b))
|
||||
|
||||
# Get some values from the array
|
||||
|
||||
print "Getting some array values"
|
||||
for i in range(0,5):
|
||||
print " va(%d) = %s" % (i, example.Vector_print(example.VectorArray_get(va,i)))
|
||||
print " va(%d) = %s" % (i, va.get(i).cprint())
|
||||
|
||||
# Watch under resource meter to check on this
|
||||
print "Making sure we don't leak memory."
|
||||
for i in xrange(0,1000000):
|
||||
c = example.VectorArray_get(va,i % 10)
|
||||
c = va.get(i % 10)
|
||||
|
||||
# ----- Clean up -----
|
||||
print "Cleaning up"
|
||||
|
||||
example.delete_VectorArray(va)
|
||||
example.delete_Vector(a)
|
||||
example.delete_Vector(b)
|
||||
del va
|
||||
del a
|
||||
del b
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue