PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/python/reference/runme.py

#
Python | 63 lines | 26 code | 20 blank | 17 comment | 4 complexity | 88a45df6717e7fb940a1fd265e9a0d2b MD5 | raw file
 1# file: runme.py
 2
 3# This file illustrates the manipulation of C++ references in Python
 4
 5import example
 6
 7# ----- Object creation -----
 8
 9print "Creating some objects:"
10a = example.Vector(3,4,5)
11b = example.Vector(10,11,12)
12
13print "    Created",a.cprint()
14print "    Created",b.cprint()
15
16# ----- Call an overloaded operator -----
17
18# This calls the wrapper we placed around
19#
20#      operator+(const Vector &a, const Vector &) 
21#
22# It returns a new allocated object.
23
24print "Adding a+b"
25c = example.addv(a,b)
26print "    a+b =", c.cprint()
27
28# Note: Unless we free the result, a memory leak will occur
29del c
30
31# ----- Create a vector array -----
32
33# Note: Using the high-level interface here
34print "Creating an array of vectors"
35va = example.VectorArray(10)
36print "    va = ",va
37
38# ----- Set some values in the array -----
39
40# These operators copy the value of $a and $b to the vector array
41va.set(0,a)
42va.set(1,b)
43
44va.set(2,example.addv(a,b))
45
46# Get some values from the array
47
48print "Getting some array values"
49for i in range(0,5):
50    print "    va(%d) = %s" % (i, va.get(i).cprint())
51
52# Watch under resource meter to check on this
53print "Making sure we don't leak memory."
54for i in xrange(0,1000000):
55    c = va.get(i % 10)
56
57# ----- Clean up -----
58print "Cleaning up"
59
60del va
61del a
62del b
63