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:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
10
SWIG/Examples/python/mpointer/.cvsignore
Normal file
10
SWIG/Examples/python/mpointer/.cvsignore
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
example.py
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
21
SWIG/Examples/python/mpointer/Makefile
Normal file
21
SWIG/Examples/python/mpointer/Makefile
Normal 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
|
||||
45
SWIG/Examples/python/mpointer/example.cxx
Normal file
45
SWIG/Examples/python/mpointer/example.cxx
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* 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(void) {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
return 4*width;
|
||||
}
|
||||
|
||||
double do_op(Shape *s, double (Shape::*m)(void)) {
|
||||
return (s->*m)();
|
||||
}
|
||||
|
||||
double (Shape::*areapt())(void) {
|
||||
return &Shape::area;
|
||||
}
|
||||
|
||||
double (Shape::*perimeterpt())(void) {
|
||||
return &Shape::perimeter;
|
||||
}
|
||||
|
||||
/* Member pointer variables */
|
||||
double (Shape::*areavar)(void) = &Shape::area;
|
||||
double (Shape::*perimetervar)(void) = &Shape::perimeter;
|
||||
|
||||
50
SWIG/Examples/python/mpointer/example.h
Normal file
50
SWIG/Examples/python/mpointer/example.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* File : example.h */
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
double *z;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
extern double do_op(Shape *s, double (Shape::*m)(void));
|
||||
|
||||
/* Functions that return member pointers */
|
||||
|
||||
extern double (Shape::*areapt())(void);
|
||||
extern double (Shape::*perimeterpt())(void);
|
||||
|
||||
/* Global variables that are member pointers */
|
||||
extern double (Shape::*areavar)(void);
|
||||
extern double (Shape::*perimetervar)(void);
|
||||
|
||||
|
||||
|
||||
16
SWIG/Examples/python/mpointer/example.i
Normal file
16
SWIG/Examples/python/mpointer/example.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
/* Some constants */
|
||||
|
||||
%constant double (Shape::*AREAPT)(void) = &Shape::area;
|
||||
%constant double (Shape::*PERIMPT)(void) = &Shape::perimeter;
|
||||
%constant double (Shape::*NULLPT)(void) = 0;
|
||||
|
||||
51
SWIG/Examples/python/mpointer/runme.py
Normal file
51
SWIG/Examples/python/mpointer/runme.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Example using pointers to member functions
|
||||
|
||||
import example
|
||||
|
||||
# Get the pointers
|
||||
|
||||
area_pt = example.areapt()
|
||||
perim_pt = example.perimeterpt()
|
||||
|
||||
print "area_pt =", area_pt
|
||||
print "perim_pt = ", perim_pt
|
||||
|
||||
# Create some objects
|
||||
|
||||
c = example.Circle(4)
|
||||
s = example.Square(10)
|
||||
|
||||
# Do some calculations
|
||||
|
||||
print "Circle area = ", example.do_op(c,area_pt)
|
||||
print "Circle perim = ", example.do_op(c,perim_pt)
|
||||
print "Square area = ", example.do_op(s,area_pt)
|
||||
print "Square perim = ", example.do_op(s,perim_pt)
|
||||
|
||||
print "cvar.areavar =", example.cvar.areavar
|
||||
print "cvar.perimetervar =", example.cvar.perimetervar
|
||||
|
||||
# Try the variables
|
||||
print "Circle area = ", example.do_op(c,example.cvar.areavar)
|
||||
print "Circle perim = ", example.do_op(c,example.cvar.perimetervar)
|
||||
print "Square area = ", example.do_op(s,example.cvar.areavar)
|
||||
print "Square perim = ", example.do_op(s,example.cvar.perimetervar)
|
||||
|
||||
# Modify one of the variables
|
||||
example.cvar.areavar = perim_pt
|
||||
|
||||
print "Circle perimeter = ", example.do_op(c,example.cvar.areavar)
|
||||
|
||||
# Try the constants
|
||||
|
||||
print "example.AREAPT =", example.AREAPT
|
||||
print "example.PERIMPT=", example.PERIMPT
|
||||
print "example.NULLPT =", example.NULLPT
|
||||
|
||||
print "Circle area = ", example.do_op(c,example.AREAPT)
|
||||
print "Circle perim = ", example.do_op(c,example.PERIMPT)
|
||||
print "Square area = ", example.do_op(s,example.AREAPT)
|
||||
print "Square perim = ", example.do_op(s,example.PERIMPT)
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue