PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

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