From 3141dfd599f1a89c87fb71abdfe5c8b0320fd2e5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:08:23 +0000 Subject: [PATCH] Convert to use proxy classes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11601 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/reference/Makefile | 2 +- Examples/php/reference/example.cxx | 3 +-- Examples/php/reference/example.h | 2 +- Examples/php/reference/example.i | 3 +-- Examples/php/reference/runme.php | 43 +++++++++++++++--------------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index 252a72660..1bc0beaab 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -4,7 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -SWIGOPT = -noproxy +SWIGOPT = all:: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/php/reference/example.cxx b/Examples/php/reference/example.cxx index 3e13841d2..13e47eade 100644 --- a/Examples/php/reference/example.cxx +++ b/Examples/php/reference/example.cxx @@ -17,7 +17,7 @@ Vector operator+(const Vector &a, const Vector &b) { return r; } -char *Vector::print() { +char *Vector::as_string() { static char temp[512]; sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); return temp; @@ -47,4 +47,3 @@ int VectorArray::size() { printf("VectorArray: size %d self=%p\n",maxsize,this); return maxsize; } - diff --git a/Examples/php/reference/example.h b/Examples/php/reference/example.h index 4915adb1b..1b88cbf5c 100644 --- a/Examples/php/reference/example.h +++ b/Examples/php/reference/example.h @@ -7,7 +7,7 @@ public: Vector() : x(0), y(0), z(0) { }; Vector(double x, double y, double z) : x(x), y(y), z(z) { }; friend Vector operator+(const Vector &a, const Vector &b); - char *print(); + char *as_string(); }; class VectorArray { diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index 55d1828a8..5502a4420 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -12,7 +12,7 @@ class Vector { public: Vector(double x, double y, double z); ~Vector(); - char *print(); + char *as_string(); }; /* This helper function calls an overloaded operator */ @@ -41,4 +41,3 @@ public: } } }; - diff --git a/Examples/php/reference/runme.php b/Examples/php/reference/runme.php index 00aaa5298..14578cd92 100644 --- a/Examples/php/reference/runme.php +++ b/Examples/php/reference/runme.php @@ -1,18 +1,17 @@ as_string()}\n"; +print " Created b: {$b->as_string()}\n"; # ----- Call an overloaded operator ----- @@ -23,8 +22,8 @@ print " Created b: $b " . Vector_print($b) . "\n"; # It returns a new allocated object. print "Adding a+b\n"; -$c = addv($a,$b); -print " a+b =". Vector_print($c)."\n"; +$c = example::addv($a,$b); +print " a+b ={$c->as_string()}\n"; # Note: Unless we free the result, a memory leak will occur $c = None; @@ -33,46 +32,46 @@ $c = None; # Note: Using the high-level interface here print "Creating an array of vectors\n"; -$va = new_VectorArray(10); +$va = new VectorArray(10); -print " va: $va size=".VectorArray_size($va)."\n"; +print " va: size={$va->size()}\n"; # ----- Set some values in the array ----- # These operators copy the value of $a and $b to the vector array -VectorArray_set($va,0,$a); -VectorArray_set($va,1,$b); +$va->set(0,$a); +$va->set(1,$b); -VectorArray_get($va,0); +$va->get(0); # This will work, but it will cause a memory leak! -VectorArray_set($va,2,addv($a,$b)); +$va->set(2,addv($a,$b)); # The non-leaky way to do it $c = addv($a,$b); -VectorArray_set($va,3,$c); -$c = None; +$va->set(3,$c); +$c = NULL; # Get some values from the array print "Getting some array values\n"; for ($i = 0; $i < 5; $i++) { -print "do $i\n"; - print " va($i) = ". Vector_print(VectorArray_get($va,$i)). "\n"; + print "do $i\n"; + print " va($i) = {$va->get($i)->as_string()}\n"; } # Watch under resource meter to check on this #print "Making sure we don't leak memory.\n"; #for ($i = 0; $i < 1000000; $i++) { -# $c = VectorArray_get($va,$i % 10); +# $c = $va->get($i % 10); #} # ----- Clean up ----- print "Cleaning up\n"; # wants fixing FIXME -$va = None; -$a = None; -$b = None; +$va = NULL; +$a = NULL; +$b = NULL; ?>