Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean

View File

@@ -0,0 +1,28 @@
/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area() {
return M_PI*radius*radius;
}
double Circle::perimeter() {
return 2*M_PI*radius;
}
double Square::area() {
return width*width;
}
double Square::perimeter() {
return 4*width;
}

View File

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

View File

@@ -0,0 +1,9 @@
/* 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,53 @@
import .example;
int main()
{
// ----- Object creation -----
write("Creating some objects:\n");
Circle c = Circle(10.0);
write(" Created circle.\n");
Square s = Square(10.0);
write(" Created square.\n");
// ----- Access a static member -----
write("\nA total of " + Shape_nshapes_get() + " shapes were created\n");
// ----- Member data access -----
// Set the location of the object
c->x_set(20.0);
c->y_set(30.0);
s->x_set(-10.0);
s->y_set(5.0);
write("\nHere is their current position:\n");
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(" area = %f.\n", c->area());
write(" perimeter = %f.\n", c->perimeter());
write(" The square:\n");
write(" area = %f.\n", s->area());
write(" perimeter = %f.\n", s->perimeter());
write("\nGuess I'll clean up now\n");
/* 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;
}