The great merge

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

View file

@ -0,0 +1,21 @@
TOP = ../..
SWIG = $(TOP)/../swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
SWIGOPT =
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
static::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py
check: all

View file

@ -0,0 +1,28 @@
/* File : example.c */
#include "example.h"
#include <math.h>
/* 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,39 @@
/* 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,20 @@
/* File : example.i */
%module example
%{
#include "example.h"
#include "smartptr.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
/* Grab smart pointer template */
%include "smartptr.h"
/* Instantiate smart-pointers */
%template(ShapePtr) SmartPtr<Shape>;

View file

@ -0,0 +1,55 @@
# file: runme.py
# This file illustrates the shadow-class C++ interface generated
# by SWIG.
import example
# ----- Object creation -----
print "Creating some objects:"
cc = example.Circle(10)
c = example.ShapePtr(cc)
print " Created circle", c
ss = example.Square(10)
s = example.ShapePtr(ss)
print " Created square", s
# ----- Access a static member -----
print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
# ----- Member data access -----
# Set the location of the object
c.x = 20
c.y = 30
s.x = -10
s.y = 5
print "\nHere is their current position:"
print " Circle = (%f, %f)" % (c.x,c.y)
print " Square = (%f, %f)" % (s.x,s.y)
# ----- Call some methods -----
print "\nHere are some properties of the shapes:"
for o in [c,s]:
print " ", o
print " area = ", o.area()
print " perimeter = ", o.perimeter()
print "\nGuess I'll clean up now"
# Note: this invokes the virtual destructor
del c
del s
del cc
del ss
s = 3
print example.cvar.Shape_nshapes,"shapes remain"
print "Goodbye"

View file

@ -0,0 +1,13 @@
template<class T> class SmartPtr {
public:
SmartPtr(T *realPtr = 0) { pointee = realPtr; }
T *operator->() const {
return pointee;
}
T &operator*() const {
return *pointee;
}
private:
T *pointee;
};