The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

View file

@ -0,0 +1,9 @@
*_wrap.c
*_wrap.cxx
*.dll
*.dsw
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -0,0 +1,19 @@
TOP = ../..
SWIG = $(TOP)/../swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
all:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
static:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

@ -0,0 +1,48 @@
/* File : example.c */
#include "example.h"
#include <stdio.h>
#define M_PI 3.14159265358979323846
// Static member initializer
int Shape::nshapes = 0;
// Constructor
Shape::Shape() {
// printf("Shape::Shape(), this = 0x%08x\n", this);
nshapes++;
}
// Move the shape to a new location
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
// Destructor
Shape::~Shape() {
// printf("Shape::~Shape(), this = 0x%08x\n", this);
nshapes--;
}
// Circle area
double Circle::area() {
return M_PI*radius*radius;
}
// Circle perimeter
double Circle::perimeter() {
return 2*M_PI*radius;
}
// Square area
double Square::area() {
return width*width;
}
// Square perimeter
double Square::perimeter() {
return 4*width;
}

View file

@ -0,0 +1,35 @@
/* File : example.h */
class Shape {
public:
Shape();
virtual ~Shape();
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -0,0 +1,10 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,61 @@
import .example;
int main()
{
// ----- Object creation -----
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");
// ----- 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()));
// ----- 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(" The square:\n");
write(sprintf(" area = %f.\n", s->area()));
write(sprintf(" 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));
write("Goodbye\n");
return 0;
}