PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/perl5/class/runme.pl

#
Perl | 60 lines | 34 code | 14 blank | 12 comment | 0 complexity | 11aefd974cf79dd061bb9840da66f1ff MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.pl
  2. # This file illustrates the low-level C++ interface
  3. # created by SWIG. In this case, all of our C++ classes
  4. # get converted into function calls.
  5. use example;
  6. # ----- Object creation -----
  7. print "Creating some objects:\n";
  8. $c = new example::Circle(10);
  9. print " Created circle $c\n";
  10. $s = new example::Square(10);
  11. print " Created square $s\n";
  12. # ----- Access a static member -----
  13. print "\nA total of $example::Shape::nshapes shapes were created\n";
  14. # ----- Member data access -----
  15. # Set the location of the object.
  16. # Note: methods in the base class Shape are used since
  17. # x and y are defined there.
  18. $c->{x} = 20;
  19. $c->{y} = 30;
  20. $s->{x} = -10;
  21. $s->{y} = 5;
  22. print "\nHere is their current position:\n";
  23. print " Circle = (",$c->{x},",", $c->{y},")\n";
  24. print " Square = (",$s->{x},",", $s->{y},")\n";
  25. # ----- Call some methods -----
  26. print "\nHere are some properties of the shapes:\n";
  27. foreach $o ($c,$s) {
  28. print " $o\n";
  29. print " area = ", $o->area(), "\n";
  30. print " perimeter = ", $o->perimeter(), "\n";
  31. }
  32. # ----- Delete everything -----
  33. print "\nGuess I'll clean up now\n";
  34. # Note: this invokes the virtual destructor
  35. $c->DESTROY();
  36. $s->DESTROY();
  37. print $example::Shape::nshapes," shapes remain\n";
  38. $square = example::CFoo::MakeSquare();
  39. $tsquare = example::CFoo::MakeTSquare();
  40. print "Areas ", $square->area(), " ", $tsquare->area(),"\n";
  41. print "Goodbye\n";