Various and sundry updates for the Pike module.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4758 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Logan Johnson 2003-04-30 22:22:11 +00:00
commit c478c13cf0
6 changed files with 147 additions and 59 deletions

View file

@ -1,4 +1,5 @@
# see top-level Makefile.in
class
constants
enum
simple

View file

@ -11,7 +11,6 @@ int Shape::nshapes = 0;
// Constructor
Shape::Shape() {
// printf("Shape::Shape(), this = 0x%08x\n", this);
nshapes++;
}
@ -23,26 +22,25 @@ void Shape::move(double dx, double dy) {
// Destructor
Shape::~Shape() {
// printf("Shape::~Shape(), this = 0x%08x\n", this);
nshapes--;
}
// Circle area
double Circle::area() {
double Circle::area() const {
return M_PI*radius*radius;
}
// Circle perimeter
double Circle::perimeter() {
double Circle::perimeter() const {
return 2*M_PI*radius;
}
// Square area
double Square::area() {
double Square::area() const {
return width*width;
}
// Square perimeter
double Square::perimeter() {
double Square::perimeter() const {
return 4*width;
}

View file

@ -6,8 +6,8 @@ public:
virtual ~Shape();
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
virtual double area() const = 0;
virtual double perimeter() const = 0;
static int nshapes;
};
@ -16,8 +16,8 @@ private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
virtual double area() const;
virtual double perimeter() const;
};
class Square : public Shape {
@ -25,8 +25,8 @@ private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
virtual double area() const;
virtual double perimeter() const;
};

View file

@ -6,55 +6,47 @@ int main()
write("Creating some objects:\n");
Circle c = Circle(10.0);
// write(" Created circle " + (string) c + ".\n");
write(" Created circle.\n");
Square s = Square(10.0);
// write(" Created square " + (string) s + ".\n");
write(" Created square.\n");
// ----- Access a static member -----
// write("\nA total of " + Shape->nshapes + " shapes were created\n");
write("\nA total of " + Shape_nshapes_get() + " shapes were created\n");
// ----- Member data access -----
// Set the location of the object
// c->x = 20.0;
// c->y = 30.0;
c->x_set(20.0);
c->y_set(30.0);
// s->x = -10.0;
// s->y = 5.0;
s->x_set(-10.0);
s->y_set(5.0);
write("\nHere is their current position:\n");
// write(sprintf(" Circle = (%f, %f)\n", c->x, c->y));
// write(sprintf(" Square = (%f, %f)\n", s->x, s->y));
write(sprintf(" Circle = (%f, %f)\n", c->x_get(), c->y_get()));
write(sprintf(" Square = (%f, %f)\n", s->x_get(), s->y_get()));
write(" Circle = (%f, %f)\n", c->x_get(), c->y_get());
write(" Square = (%f, %f)\n", s->x_get(), s->y_get());
// ----- Call some methods -----
write("\nHere are some properties of the shapes:\n");
write(" The circle:\n");
write(sprintf(" area = %f.\n", c->area()));
write(sprintf(" perimeter = %f.\n", c->perimeter()));
// write(" " + (string) s + ".\n");
write(" area = %f.\n", c->area());
write(" perimeter = %f.\n", c->perimeter());
write(" The square:\n");
write(sprintf(" area = %f.\n", s->area()));
write(sprintf(" perimeter = %f.\n", s->perimeter()));
write(" area = %f.\n", s->area());
write(" perimeter = %f.\n", s->perimeter());
write("\nGuess I'll clean up now\n");
// Note: this invokes the virtual destructor
// del c;
// del s;
// s = 3;
// write(sprintf("%d shapes remain\n", Shape->nshapes));
/* See if we can force 's' to be garbage-collected */
s = 0;
/* Now we should be down to only 1 shape */
write("%d shapes remain\n", Shape_nshapes_get());
/* Done */
write("Goodbye\n");
return 0;