diff options
author | Olly Betts <olly@survex.com> | 2014-02-23 18:05:50 +1300 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2014-02-23 18:24:51 +1300 |
commit | 34c97ffdbd528f4c53873ccc8f60238579c2a22d (patch) | |
tree | 9a4de3f3c7bfcf424fb5ddc5a00c02b081b11aec /Examples/php | |
parent | 2f3bf144c685585dab7d4d8ae1ae805dda0edab8 (diff) | |
download | swig-34c97ffdbd528f4c53873ccc8f60238579c2a22d.tar.gz |
Improve the class example for several languages.
Fix numerous inaccuracies in index.html (where it exists) and eliminate
unnecessary differences between the example code being wrapped.
Diffstat (limited to 'Examples/php')
-rw-r--r-- | Examples/php/class/example.cxx | 23 | ||||
-rw-r--r-- | Examples/php/class/example.h | 16 | ||||
-rw-r--r-- | Examples/php/class/runme.php | 4 |
3 files changed, 14 insertions, 29 deletions
diff --git a/Examples/php/class/example.cxx b/Examples/php/class/example.cxx index f171f10e9..046304519 100644 --- a/Examples/php/class/example.cxx +++ b/Examples/php/class/example.cxx @@ -1,14 +1,7 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" -#include <math.h> -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -int Shape::get_nshapes() { - return nshapes; -} +#define M_PI 3.14159265358979323846 /* Move the shape to a new location */ void Shape::move(double dx, double dy) { @@ -18,22 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -void Circle::set_radius( double r ) { - radius = r; -} - -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/php/class/example.h b/Examples/php/class/example.h index 02eaf7232..0dff185b2 100644 --- a/Examples/php/class/example.h +++ b/Examples/php/class/example.h @@ -10,10 +10,9 @@ public: } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; - static int get_nshapes(); }; class Circle : public Shape { @@ -21,10 +20,8 @@ private: double radius; public: Circle(double r) : radius(r) { } - ~Circle() { } - void set_radius( double r ); - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { @@ -32,7 +29,6 @@ private: double width; public: Square(double w) : width(w) { } - ~Square() { } - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php index 12b686052..99c253b46 100644 --- a/Examples/php/class/runme.php +++ b/Examples/php/class/runme.php @@ -14,7 +14,7 @@ print " Created square\n"; # ----- Access a static member ----- -print "\nA total of " . Shape::get_nshapes() . " shapes were created\n"; +print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Member data access ----- @@ -54,7 +54,7 @@ $s = NULL; # the square. $o = NULL; -print Shape::get_nshapes() . " shapes remain\n"; +print Shape::nshapes() . " shapes remain\n"; print "Goodbye\n"; ?> |