Updated examples to function correctly with new php4 module. Added
some supplemental examples for cpointer, overloading and references using proxies. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7391 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
bc9db8b383
commit
501bd53c4b
44 changed files with 506 additions and 131 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#! /bin/sh -e
|
||||
|
||||
${SWIG:=swig} -php4 -phpfull -c++ -noproxy -withcxx example.cxx example.i
|
||||
phpize && ./configure && make clean && make
|
||||
${SWIG:=swig} -php4 -make -c++ -noproxy -withcxx example.cxx example.i
|
||||
make
|
||||
php -d extension_dir=. runme.php4
|
||||
|
|
|
|||
|
|
@ -1,7 +1,14 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
#include <math.h>
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
int Shape::get_nshapes() {
|
||||
return nshapes;
|
||||
}
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
|
|
@ -11,6 +18,10 @@ void Shape::move(double dx, double dy) {
|
|||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
void Circle::set_radius( double r ) {
|
||||
radius = r;
|
||||
}
|
||||
|
||||
double Circle::area(void) {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public:
|
|||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
static int nshapes;
|
||||
static int get_nshapes();
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
|
|
@ -20,6 +21,8 @@ private:
|
|||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
~Circle() { };
|
||||
void set_radius( double r );
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
|
@ -29,6 +32,7 @@ private:
|
|||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
~Square() { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,22 +35,28 @@ print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
|
|||
|
||||
# ----- Call some methods -----
|
||||
|
||||
# Notice how the Shape_area() and Shape_perimeter() functions really
|
||||
# invoke the appropriate virtual method on each object.
|
||||
print "\nHere are some properties of the shapes:\n";
|
||||
foreach (array($c,$s) as $o) {
|
||||
print " $o\n";
|
||||
print " area = " . Shape_area($o) . "\n";
|
||||
print " perimeter = " . Shape_perimeter($o) . "\n";
|
||||
}
|
||||
# Notice how the Shape_area() and Shape_perimeter() functions really
|
||||
# invoke the appropriate virtual method on each object.
|
||||
|
||||
# ----- Delete everything -----
|
||||
|
||||
print "\nGuess I'll clean up now\n";
|
||||
|
||||
# Note: this invokes the virtual destructor
|
||||
delete_Shape($c);
|
||||
delete_Shape($s);
|
||||
#delete_Shape($c);
|
||||
#delete_Shape($s);
|
||||
$c = NULL;
|
||||
$s = NULL;
|
||||
|
||||
# and don't forget the $o from the for loop above. It still refers to
|
||||
# the square.
|
||||
$o = NULL;
|
||||
|
||||
print nshapes() . " shapes remain\n";
|
||||
print "Goodbye\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue