Convert to use proxy classes.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11601 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3283728cf5
commit
3141dfd599
5 changed files with 25 additions and 28 deletions
|
|
@ -1,18 +1,17 @@
|
|||
<?php
|
||||
|
||||
# This file illustrates the manipulation of C++ references in Php.
|
||||
# This uses the low-level interface. Proxy classes work differently.
|
||||
# This file illustrates the manipulation of C++ references in PHP.
|
||||
|
||||
require "example.php";
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$a = new_Vector(3,4,5);
|
||||
$b = new_Vector(10,11,12);
|
||||
$a = new Vector(3,4,5);
|
||||
$b = new Vector(10,11,12);
|
||||
|
||||
print " Created a: $a " . Vector_print($a) . "\n";
|
||||
print " Created b: $b " . Vector_print($b) . "\n";
|
||||
print " Created a: {$a->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;
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue