def exercise(): c = example.Circle(10) c.x = 20 c.y = 30 s = example.Square(10) s.x = -10 s.y = 5 forever = "--forever" in sys.argv[1:] while True: boost_python_swig_args_ext.show(c.this) boost_python_swig_args_ext.show(s.this) if (not forever): break
import math import example from swimport.tests.resources import * with AssertError(AttributeError): shape = example.Shape() circle = example.Circle(0, 20, 5) assert_isinstance(circle, example.Shape) assert_isinstance(circle, example.Circle) assert_eq(circle.x_min(), -5) assert_eq(circle.x_max(), 5) assert_true(circle.Contains(3, 23)) assert_true(circle.Contains(3, 17.9)) assert_isclose(circle.area(), 5 * 5 * math.pi, rel_tol=1e-1) rect = example.Rectangle(10, 50, 6, 20) assert_true(rect.Contains(11, 56)) assert_isinstance(rect, example.Shape) assert_isinstance(rect, example.Rectangle) assert_eq(rect.area(), 120)
import example # Create the Circle object r = 2 print " Creating circle (radium: %d) :" % r c = example.Circle(r) # Set the location of the object c.x = 20 c.y = 30 print " Here is its current position:" print " Circle = (%f, %f)" % (c.x, c.y) # ----- Call some methods ----- print "\n Here are some properties of the Circle:" print " area = ", c.area() print " perimeter = ", c.perimeter() dx = 1 dy = 1 print " Moving with (%d, %d)..." % (dx, dy) c.move(dx, dy) del c print "===================================" # test move function */ r = 2
# file: runme.py # This file illustrates the proxy class C++ interface generated # by alaqil. import example # ----- Object creation ----- print "Creating some objects:" cc = example.Circle(10) c = example.ShapePtr(cc) print " Created circle", c ss = example.Square(10) s = example.ShapePtr(ss) print " Created square", s # ----- Access a static member ----- print "\nA total of", example.cvar.Shape_nshapes, "shapes were created" # ----- Member data access ----- # Set the location of the object c.x = 20 c.y = 30 s.x = -10 s.y = 5
import example # Call the Circle() function correctly x = 1 y = 1 r = 3 c = example.Circle(x, y, r) print "The return value of Circle(%d, %d, %d) is %d" % (x, y, r, c) # test pre-assertion x = 1 y = -1 r = 3 c = example.Circle(x, y, r) print "The return value of Circle(%d, %d, %d) is %d" % (x, y, r, c)
# Example using pointers to member functions import example # Get the pointers area_pt = example.areapt() perim_pt = example.perimeterpt() print "area_pt =", area_pt print "perim_pt = ", perim_pt # Create some objects c = example.Circle(4) s = example.Square(10) # Do some calculations print "Circle area = ", example.do_op(c, area_pt) print "Circle perim = ", example.do_op(c, perim_pt) print "Square area = ", example.do_op(s, area_pt) print "Square perim = ", example.do_op(s, perim_pt) print "cvar.areavar =", example.cvar.areavar print "cvar.perimetervar =", example.cvar.perimetervar # Try the variables print "Circle area = ", example.do_op(c, example.cvar.areavar) print "Circle perim = ", example.do_op(c, example.cvar.perimetervar) print "Square area = ", example.do_op(s, example.cvar.areavar)