File: runme.php4

package info (click to toggle)
cableswig 0.1.0%2Bcvs20060311-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 16,044 kB
  • ctags: 10,703
  • sloc: cpp: 33,966; ansic: 32,676; yacc: 3,999; makefile: 3,822; python: 2,387; ruby: 2,063; lisp: 1,841; java: 1,817; tcl: 1,097; php: 908; ml: 804; perl: 686; cs: 206; sh: 161
file content (78 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

# This file illustrates the manipulation of C++ references in Php.
# This uses the low-level interface.  Shadow classes work differently.

require "example.php";

# ----- Object creation -----

print "Creating some objects:\n";
$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";

# ----- Call an overloaded operator -----

# This calls the wrapper we placed around
#
#      operator+(const Vector &a, const Vector &) 
#
# It returns a new allocated object.

print "Adding a+b\n";
$c = addv($a,$b);
print "    a+b =". Vector_print($c)."\n";

# Note: Unless we free the result, a memory leak will occur
delete_Vector($c);

# ----- Create a vector array -----

# Note: Using the high-level interface here
print "Creating an array of vectors\n";
$va = new_VectorArray(10);

print "    va: $va size=".VectorArray_size($va)."\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);

VectorArray_get($va,0);
# This will work, but it will cause a memory leak!

VectorArray_set($va,2,addv($a,$b));

# The non-leaky way to do it

$c = addv($a,$b);
VectorArray_set($va,3,$c);
delete_Vector($c);

# 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";
}

# 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);
#}

# ----- Clean up -----
print "Cleaning up\n";
# wants fixing FIXME
#delete_VectorArray($va);
delete_Vector($a);
delete_Vector($b);

?>