Remove obscure mpointer example and replace with member_pointer.i testcase and runtime examples
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9887 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
665917ebae
commit
f5bdd056f7
38 changed files with 397 additions and 929 deletions
|
|
@ -5,7 +5,6 @@ constants
|
||||||
enum
|
enum
|
||||||
extend
|
extend
|
||||||
funcptr
|
funcptr
|
||||||
mpointer
|
|
||||||
multimap
|
multimap
|
||||||
native
|
native
|
||||||
pointer
|
pointer
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-swig
|
|
||||||
CXXSRCS = example.cxx
|
|
||||||
TARGET = example
|
|
||||||
INTERFACE = example.i
|
|
||||||
SWIGOPT =
|
|
||||||
|
|
||||||
all:: java
|
|
||||||
|
|
||||||
java::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
|
|
||||||
javac *.java
|
|
||||||
|
|
||||||
clean::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile java_clean
|
|
||||||
|
|
||||||
check: all
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* File : example.c */
|
|
||||||
|
|
||||||
#include "example.h"
|
|
||||||
#include <math.h>
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
// Example using pointers to member functions
|
|
||||||
|
|
||||||
public class main {
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("example");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String argv[])
|
|
||||||
{
|
|
||||||
// Get the pointers
|
|
||||||
|
|
||||||
SWIGTYPE_m_Shape__f_void__double area_pt = example.areapt();
|
|
||||||
SWIGTYPE_m_Shape__f_void__double perim_pt = example.perimeterpt();
|
|
||||||
|
|
||||||
System.out.println( "area_pt =" + area_pt );
|
|
||||||
System.out.println( "perim_pt = " + perim_pt );
|
|
||||||
|
|
||||||
// Create some objects
|
|
||||||
|
|
||||||
Circle c = new Circle(4);
|
|
||||||
Square s = new Square(10);
|
|
||||||
|
|
||||||
// Do some calculations
|
|
||||||
|
|
||||||
System.out.println( "Circle area = " + example.do_op(c,area_pt) );
|
|
||||||
System.out.println( "Circle perim = " + example.do_op(c,perim_pt) );
|
|
||||||
System.out.println( "Square area = " + example.do_op(s,area_pt) );
|
|
||||||
System.out.println( "Square perim = " + example.do_op(s,perim_pt) );
|
|
||||||
|
|
||||||
System.out.println( "areavar = " + example.getAreavar() );
|
|
||||||
System.out.println( "perimetervar = " + example.getPerimetervar() );
|
|
||||||
|
|
||||||
// Try the variables
|
|
||||||
System.out.println( "Circle area = " + example.do_op(c,example.getAreavar()) );
|
|
||||||
System.out.println( "Circle perim = " + example.do_op(c,example.getPerimetervar()) );
|
|
||||||
System.out.println( "Square area = " + example.do_op(s,example.getAreavar()) );
|
|
||||||
System.out.println( "Square perim = " + example.do_op(s,example.getPerimetervar()) );
|
|
||||||
|
|
||||||
// Modify one of the variables
|
|
||||||
example.setAreavar(perim_pt);
|
|
||||||
|
|
||||||
System.out.println( "Circle perimeter = " + example.do_op(c,example.getAreavar()) );
|
|
||||||
|
|
||||||
// Try the constants
|
|
||||||
|
|
||||||
System.out.println( "example.AREAPT =" + example.AREAPT );
|
|
||||||
System.out.println( "example.PERIMPT=" + example.PERIMPT );
|
|
||||||
System.out.println( "example.NULLPT =" + example.NULLPT );
|
|
||||||
|
|
||||||
System.out.println( "Circle area = " + example.do_op(c,example.AREAPT) );
|
|
||||||
System.out.println( "Circle perim = " + example.do_op(c,example.PERIMPT) );
|
|
||||||
System.out.println( "Square area = " + example.do_op(s,example.AREAPT) );
|
|
||||||
System.out.println( "Square perim = " + example.do_op(s,example.PERIMPT) );
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,7 +5,6 @@ constants2
|
||||||
funcptr
|
funcptr
|
||||||
import
|
import
|
||||||
java
|
java
|
||||||
mpointer
|
|
||||||
multimap
|
multimap
|
||||||
multiple_inheritance
|
multiple_inheritance
|
||||||
pointer
|
pointer
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-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)' perl5_cpp
|
|
||||||
|
|
||||||
static::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static
|
|
||||||
|
|
||||||
clean::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile perl5_clean
|
|
||||||
|
|
||||||
check: all
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* File : example.c */
|
|
||||||
|
|
||||||
#include "example.h"
|
|
||||||
#include <math.h>
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
# Example using pointers to member functions
|
|
||||||
|
|
||||||
use example;
|
|
||||||
|
|
||||||
# Get the pointers
|
|
||||||
|
|
||||||
$area_pt = example::areapt();
|
|
||||||
$perim_pt = example::perimeterpt();
|
|
||||||
|
|
||||||
print "area_pt =", $area_pt, "\n";
|
|
||||||
print "perim_pt = ", $perim_pt, "\n";
|
|
||||||
|
|
||||||
# Create some objects
|
|
||||||
|
|
||||||
$c = new example::Circle(4);
|
|
||||||
$s = new example::Square(10);
|
|
||||||
|
|
||||||
# Do some calculations
|
|
||||||
|
|
||||||
print "Circle area = ", example::do_op($c,$area_pt), "\n";
|
|
||||||
print "Circle perim = ", example::do_op($c,$perim_pt), "\n";
|
|
||||||
print "Square area = ", example::do_op($s,$area_pt), "\n";
|
|
||||||
print "Square perim = ", example::do_op($s,$perim_pt), "\n";
|
|
||||||
|
|
||||||
print "areavar =", $example::areavar, "\n";
|
|
||||||
print "perimetervar =", $example::perimetervar, "\n";
|
|
||||||
|
|
||||||
# Try the variables
|
|
||||||
print "Circle area = ", example::do_op($c,$example::areavar), "\n";
|
|
||||||
print "Circle perim = ", example::do_op($c,$example::perimetervar), "\n";
|
|
||||||
print "Square area = ", example::do_op($s,$example::areavar), "\n";
|
|
||||||
print "Square perim = ", example::do_op($s,$example::perimetervar), "\n";
|
|
||||||
|
|
||||||
# Modify one of the variables
|
|
||||||
$example::areavar = $perim_pt;
|
|
||||||
|
|
||||||
print "Circle perimeter = ", example::do_op($c,$example::areavar), "\n";
|
|
||||||
|
|
||||||
# Try the constants
|
|
||||||
|
|
||||||
print "example.AREAPT =", $example::AREAPT, "\n";
|
|
||||||
print "example.PERIMPT=", $example::PERIMPT, "\n";
|
|
||||||
print "example.NULLPT =", $example::NULLPT, "\n";
|
|
||||||
|
|
||||||
print "Circle area = ", example::do_op($c,$example::AREAPT), "\n";
|
|
||||||
print "Circle perim = ", example::do_op($c,$example::PERIMPT), "\n";
|
|
||||||
print "Square area = ", example::do_op($s,$example::AREAPT), "\n";
|
|
||||||
print "Square perim = ", example::do_op($s,$example::PERIMPT), "\n";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,7 +15,6 @@ import
|
||||||
import_template
|
import_template
|
||||||
java
|
java
|
||||||
#libffi
|
#libffi
|
||||||
mpointer
|
|
||||||
multimap
|
multimap
|
||||||
operator
|
operator
|
||||||
pointer
|
pointer
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-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
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* File : example.c */
|
|
||||||
|
|
||||||
#include "example.h"
|
|
||||||
#include <math.h>
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
# 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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,7 +11,6 @@ import
|
||||||
import_template
|
import_template
|
||||||
java
|
java
|
||||||
mark_function
|
mark_function
|
||||||
mpointer
|
|
||||||
multimap
|
multimap
|
||||||
operator
|
operator
|
||||||
overloading
|
overloading
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-swig
|
|
||||||
CXXSRCS = example.cxx
|
|
||||||
TARGET = example
|
|
||||||
INTERFACE = example.i
|
|
||||||
LIBS = -lm
|
|
||||||
SWIGOPT =
|
|
||||||
|
|
||||||
all::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp
|
|
||||||
|
|
||||||
static::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static
|
|
||||||
|
|
||||||
clean::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile ruby_clean
|
|
||||||
|
|
||||||
check: all
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* File : example.c */
|
|
||||||
|
|
||||||
#include "example.h"
|
|
||||||
#include <math.h>
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* 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);
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
/* 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;
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
# Example using pointers to member functions
|
|
||||||
|
|
||||||
require 'example'
|
|
||||||
|
|
||||||
# Get the pointers
|
|
||||||
|
|
||||||
area_pt = Example::areapt
|
|
||||||
perim_pt = Example::perimeterpt
|
|
||||||
|
|
||||||
puts "area_pt = #{area_pt}"
|
|
||||||
puts "perim_pt = #{perim_pt}"
|
|
||||||
|
|
||||||
# Create some objects
|
|
||||||
|
|
||||||
c = Example::Circle.new(4)
|
|
||||||
s = Example::Square.new(10)
|
|
||||||
|
|
||||||
# Do some calculations
|
|
||||||
|
|
||||||
puts "Circle area = #{Example::do_op(c, area_pt)}"
|
|
||||||
puts "Circle perim = #{Example::do_op(c, perim_pt)}"
|
|
||||||
puts "Square area = #{Example::do_op(s, area_pt)}"
|
|
||||||
puts "Square perim = #{Example::do_op(s, perim_pt)}"
|
|
||||||
|
|
||||||
puts "areavar = #{Example::areavar}"
|
|
||||||
puts "perimetervar = #{Example::perimetervar}"
|
|
||||||
|
|
||||||
# Try the variables
|
|
||||||
puts "Circle area = #{Example::do_op(c, Example::areavar)}"
|
|
||||||
puts "Circle perim = #{Example::do_op(c, Example::perimetervar)}"
|
|
||||||
puts "Square area = #{Example::do_op(s, Example::areavar)}"
|
|
||||||
puts "Square perim = #{Example::do_op(s, Example::perimetervar)}"
|
|
||||||
|
|
||||||
# Modify one of the variables
|
|
||||||
Example::areavar = perim_pt
|
|
||||||
|
|
||||||
puts "Circle perimeter = #{Example::do_op(c, Example::areavar)}"
|
|
||||||
|
|
||||||
# Try the constants
|
|
||||||
|
|
||||||
puts "Example::AREAPT = #{Example::AREAPT}"
|
|
||||||
puts "Example::PERIMPT= #{Example::PERIMPT}"
|
|
||||||
puts "Example::NULLPT = #{Example::NULLPT}"
|
|
||||||
|
|
||||||
puts "Circle area = #{Example::do_op(c, Example::AREAPT)}"
|
|
||||||
puts "Circle perim = #{Example::do_op(c, Example::PERIMPT)}"
|
|
||||||
puts "Square area = #{Example::do_op(s, Example::AREAPT)}"
|
|
||||||
puts "Square perim = #{Example::do_op(s, Example::PERIMPT)}"
|
|
||||||
|
|
@ -6,7 +6,6 @@ enum
|
||||||
funcptr
|
funcptr
|
||||||
import
|
import
|
||||||
java
|
java
|
||||||
mpointer
|
|
||||||
multimap
|
multimap
|
||||||
operator
|
operator
|
||||||
pointer
|
pointer
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-swig
|
|
||||||
CXXSRCS = example.cxx
|
|
||||||
TARGET = example
|
|
||||||
INTERFACE = example.i
|
|
||||||
LIBS = -lm
|
|
||||||
|
|
||||||
all::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp
|
|
||||||
|
|
||||||
static::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static
|
|
||||||
|
|
||||||
clean::
|
|
||||||
$(MAKE) -f $(TOP)/Makefile tcl_clean
|
|
||||||
|
|
||||||
check: all
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* File : example.c */
|
|
||||||
|
|
||||||
#include "example.h"
|
|
||||||
#include <math.h>
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
# Example using pointers to member functions
|
|
||||||
|
|
||||||
catch { load ./example[info sharedlibextension] example}
|
|
||||||
|
|
||||||
# Get the pointers
|
|
||||||
|
|
||||||
set area_pt [ areapt ]
|
|
||||||
set perim_pt [ perimeterpt ]
|
|
||||||
|
|
||||||
puts "area_pt = $area_pt"
|
|
||||||
puts "perim_pt = $perim_pt"
|
|
||||||
|
|
||||||
# Create some objects
|
|
||||||
|
|
||||||
set c [Circle -args 4]
|
|
||||||
set s [Square -args 10]
|
|
||||||
|
|
||||||
# Do some calculations
|
|
||||||
|
|
||||||
puts "Circle area = [do_op $c $area_pt]"
|
|
||||||
puts "Circle perim = [do_op $c $perim_pt]"
|
|
||||||
puts "Square area = [do_op $s $area_pt]"
|
|
||||||
puts "Square perim = [do_op $s $perim_pt]"
|
|
||||||
|
|
||||||
puts "areavar = $areavar";
|
|
||||||
puts "perimetervar = $perimetervar";
|
|
||||||
|
|
||||||
# Try the variables
|
|
||||||
puts "Circle area = [do_op $c $areavar]"
|
|
||||||
puts "Circle perim = [do_op $c $perimetervar]"
|
|
||||||
puts "Square area = [do_op $s $areavar]"
|
|
||||||
puts "Square perim = [do_op $s $perimetervar]"
|
|
||||||
|
|
||||||
# Modify one of the variables
|
|
||||||
set areavar $perim_pt
|
|
||||||
|
|
||||||
puts "Circle perimeter = [do_op $c $areavar]"
|
|
||||||
|
|
||||||
# Try the constants
|
|
||||||
|
|
||||||
puts "example.AREAPT = $AREAPT"
|
|
||||||
puts "example.PERIMPT= $PERIMPT"
|
|
||||||
puts "example.NULLPT = $NULLPT"
|
|
||||||
|
|
||||||
puts "Circle area = [do_op $c $AREAPT]"
|
|
||||||
puts "Circle perim = [do_op $c $PERIMPT]"
|
|
||||||
puts "Square area = [do_op $s $AREAPT]"
|
|
||||||
puts "Square perim = [do_op $s $PERIMPT]"
|
|
||||||
|
|
||||||
|
|
@ -183,6 +183,7 @@ CPP_TEST_CASES += \
|
||||||
li_typemaps \
|
li_typemaps \
|
||||||
li_windows \
|
li_windows \
|
||||||
long_long_apply \
|
long_long_apply \
|
||||||
|
member_pointer \
|
||||||
member_template \
|
member_template \
|
||||||
minherit \
|
minherit \
|
||||||
minherit2 \
|
minherit2 \
|
||||||
|
|
|
||||||
47
Examples/test-suite/csharp/member_pointer_runme.cs
Normal file
47
Examples/test-suite/csharp/member_pointer_runme.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using member_pointerNamespace;
|
||||||
|
|
||||||
|
public class runme {
|
||||||
|
public static SWIGTYPE_m_Shape__f_void__double memberPtr = null;
|
||||||
|
static void Main() {
|
||||||
|
// Get the pointers
|
||||||
|
|
||||||
|
SWIGTYPE_m_Shape__f_void__double area_pt = member_pointer.areapt();
|
||||||
|
SWIGTYPE_m_Shape__f_void__double perim_pt = member_pointer.perimeterpt();
|
||||||
|
|
||||||
|
// Create some objects
|
||||||
|
|
||||||
|
Square s = new Square(10);
|
||||||
|
|
||||||
|
// Do some calculations
|
||||||
|
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,area_pt) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,perim_pt) );
|
||||||
|
|
||||||
|
memberPtr = member_pointer.areavar;
|
||||||
|
memberPtr = member_pointer.perimetervar;
|
||||||
|
|
||||||
|
// Try the variables
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.areavar) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.perimetervar) );
|
||||||
|
|
||||||
|
// Modify one of the variables
|
||||||
|
member_pointer.areavar = perim_pt;
|
||||||
|
|
||||||
|
check( "Square perimeter", 40.0, member_pointer.do_op(s,member_pointer.areavar) );
|
||||||
|
|
||||||
|
// Try the constants
|
||||||
|
|
||||||
|
memberPtr = member_pointer.AREAPT;
|
||||||
|
memberPtr = member_pointer.PERIMPT;
|
||||||
|
memberPtr = member_pointer.NULLPT;
|
||||||
|
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.AREAPT) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.PERIMPT) );
|
||||||
|
|
||||||
|
}
|
||||||
|
private static void check(string what, double expected, double actual) {
|
||||||
|
if (expected != actual)
|
||||||
|
throw new ApplicationException("Failed: " + what + " Expected: " + expected + " Actual: " + actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
Examples/test-suite/java/member_pointer_runme.java
Normal file
58
Examples/test-suite/java/member_pointer_runme.java
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
import member_pointer.*;
|
||||||
|
|
||||||
|
public class member_pointer_runme {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("member_pointer");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SWIGTYPE_m_Shape__f_void__double memberPtr = null;
|
||||||
|
|
||||||
|
public static void main(String argv[]) {
|
||||||
|
// Get the pointers
|
||||||
|
|
||||||
|
SWIGTYPE_m_Shape__f_void__double area_pt = member_pointer.areapt();
|
||||||
|
SWIGTYPE_m_Shape__f_void__double perim_pt = member_pointer.perimeterpt();
|
||||||
|
|
||||||
|
// Create some objects
|
||||||
|
|
||||||
|
Square s = new Square(10);
|
||||||
|
|
||||||
|
// Do some calculations
|
||||||
|
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,area_pt) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,perim_pt) );
|
||||||
|
|
||||||
|
memberPtr = member_pointer.getAreavar();
|
||||||
|
memberPtr = member_pointer.getPerimetervar();
|
||||||
|
|
||||||
|
// Try the variables
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.getAreavar()) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.getPerimetervar()) );
|
||||||
|
|
||||||
|
// Modify one of the variables
|
||||||
|
member_pointer.setAreavar(perim_pt);
|
||||||
|
|
||||||
|
check( "Square perimeter", 40.0, member_pointer.do_op(s,member_pointer.getAreavar()) );
|
||||||
|
|
||||||
|
// Try the constants
|
||||||
|
|
||||||
|
memberPtr = member_pointer.AREAPT;
|
||||||
|
memberPtr = member_pointer.PERIMPT;
|
||||||
|
memberPtr = member_pointer.NULLPT;
|
||||||
|
|
||||||
|
check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.AREAPT) );
|
||||||
|
check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.PERIMPT) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void check(String what, double expected, double actual) {
|
||||||
|
if (expected != actual)
|
||||||
|
throw new RuntimeException("Failed: " + what + " Expected: " + expected + " Actual: " + actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
101
Examples/test-suite/member_pointer.i
Normal file
101
Examples/test-suite/member_pointer.i
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
%module member_pointer
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
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);
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%{
|
||||||
|
# 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(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;
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* Some constants */
|
||||||
|
%constant double (Shape::*AREAPT)(void) = &Shape::area;
|
||||||
|
%constant double (Shape::*PERIMPT)(void) = &Shape::perimeter;
|
||||||
|
%constant double (Shape::*NULLPT)(void) = 0;
|
||||||
|
|
||||||
47
Examples/test-suite/perl5/member_pointer_runme.pl
Normal file
47
Examples/test-suite/perl5/member_pointer_runme.pl
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
|
||||||
|
# member_pointer using pointers to member functions
|
||||||
|
|
||||||
|
use member_pointer;
|
||||||
|
|
||||||
|
sub check($;$;$) {
|
||||||
|
my($what, $expected, $actual) = @_;
|
||||||
|
if ($expected != $actual) {
|
||||||
|
die ("Failed: $what Expected: $expected Actual: $actual");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the pointers
|
||||||
|
|
||||||
|
$area_pt = member_pointer::areapt();
|
||||||
|
$perim_pt = member_pointer::perimeterpt();
|
||||||
|
|
||||||
|
# Create some objects
|
||||||
|
|
||||||
|
$s = new member_pointer::Square(10);
|
||||||
|
|
||||||
|
# Do some calculations
|
||||||
|
|
||||||
|
check "Square area ", 100.0, member_pointer::do_op($s,$area_pt);
|
||||||
|
check "Square perim", 40.0, member_pointer::do_op($s,$perim_pt);
|
||||||
|
|
||||||
|
$memberPtr = $member_pointer::areavar;
|
||||||
|
$memberPtr = $member_pointer::perimetervar;
|
||||||
|
|
||||||
|
# Try the variables
|
||||||
|
check "Square area ", 100.0, member_pointer::do_op($s,$member_pointer::areavar);
|
||||||
|
check "Square perim", 40.0, member_pointer::do_op($s,$member_pointer::perimetervar);
|
||||||
|
|
||||||
|
# Modify one of the variables
|
||||||
|
$member_pointer::areavar = $perim_pt;
|
||||||
|
|
||||||
|
check "Square perimeter", 40.0, member_pointer::do_op($s,$member_pointer::areavar);
|
||||||
|
|
||||||
|
# Try the constants
|
||||||
|
|
||||||
|
$memberPtr = $member_pointer::AREAPT;
|
||||||
|
$memberPtr = $member_pointer::PERIMPT;
|
||||||
|
$memberPtr = $member_pointer::NULLPT;
|
||||||
|
|
||||||
|
check "Square area ", 100.0, member_pointer::do_op($s,$member_pointer::AREAPT);
|
||||||
|
check "Square perim", 40.0, member_pointer::do_op($s,$member_pointer::PERIMPT);
|
||||||
|
|
||||||
43
Examples/test-suite/python/member_pointer_runme.py
Normal file
43
Examples/test-suite/python/member_pointer_runme.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Example using pointers to member functions
|
||||||
|
|
||||||
|
from member_pointer import *
|
||||||
|
|
||||||
|
def check(what, expected, actual):
|
||||||
|
if expected != actual:
|
||||||
|
raise RuntimeError ("Failed: " , what , " Expected: " , expected , " Actual: " , actual)
|
||||||
|
|
||||||
|
# Get the pointers
|
||||||
|
|
||||||
|
area_pt = areapt()
|
||||||
|
perim_pt = perimeterpt()
|
||||||
|
|
||||||
|
# Create some objects
|
||||||
|
|
||||||
|
s = Square(10)
|
||||||
|
|
||||||
|
# Do some calculations
|
||||||
|
|
||||||
|
check ("Square area ", 100.0, do_op(s,area_pt))
|
||||||
|
check ("Square perim", 40.0, do_op(s,perim_pt))
|
||||||
|
|
||||||
|
memberPtr = cvar.areavar
|
||||||
|
memberPtr = cvar.perimetervar
|
||||||
|
|
||||||
|
# Try the variables
|
||||||
|
check ("Square area ", 100.0, do_op(s,cvar.areavar))
|
||||||
|
check ("Square perim", 40.0, do_op(s,cvar.perimetervar))
|
||||||
|
|
||||||
|
# Modify one of the variables
|
||||||
|
cvar.areavar = perim_pt
|
||||||
|
|
||||||
|
check ("Square perimeter", 40.0, do_op(s,cvar.areavar))
|
||||||
|
|
||||||
|
# Try the constants
|
||||||
|
|
||||||
|
memberPtr = AREAPT
|
||||||
|
memberPtr = PERIMPT
|
||||||
|
memberPtr = NULLPT
|
||||||
|
|
||||||
|
check ("Square area ", 100.0, do_op(s,AREAPT))
|
||||||
|
check ("Square perim", 40.0, do_op(s,PERIMPT))
|
||||||
|
|
||||||
54
Examples/test-suite/ruby/member_pointer_runme.rb
Normal file
54
Examples/test-suite/ruby/member_pointer_runme.rb
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# Example using pointers to member functions
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
|
||||||
|
require 'member_pointer'
|
||||||
|
|
||||||
|
include Member_pointer
|
||||||
|
|
||||||
|
def check(what, expected, actual)
|
||||||
|
if not expected == actual
|
||||||
|
raise RuntimeError, "Failed: #{what} Expected: #{expected} Actual: #{actual}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the pointers
|
||||||
|
|
||||||
|
area_pt = Member_pointer::areapt
|
||||||
|
perim_pt = Member_pointer::perimeterpt
|
||||||
|
|
||||||
|
# Create some objects
|
||||||
|
|
||||||
|
s = Member_pointer::Square.new(10)
|
||||||
|
|
||||||
|
# Do some calculations
|
||||||
|
|
||||||
|
check "Square area ", 100.0, Member_pointer::do_op(s, area_pt)
|
||||||
|
check "Square perim", 40.0, Member_pointer::do_op(s, perim_pt)
|
||||||
|
|
||||||
|
memberPtr = Member_pointer::areavar
|
||||||
|
memberPtr = Member_pointer::perimetervar
|
||||||
|
|
||||||
|
# Try the variables
|
||||||
|
check "Square area ", 100.0, Member_pointer::do_op(s, Member_pointer::areavar)
|
||||||
|
check "Square perim", 40.0, Member_pointer::do_op(s, Member_pointer::perimetervar)
|
||||||
|
|
||||||
|
# Modify one of the variables
|
||||||
|
Member_pointer::areavar = perim_pt
|
||||||
|
|
||||||
|
check "Square perimeter", 40.0, Member_pointer::do_op(s, Member_pointer::areavar)
|
||||||
|
|
||||||
|
# Try the constants
|
||||||
|
|
||||||
|
memberPtr = Member_pointer::AREAPT
|
||||||
|
memberPtr = Member_pointer::PERIMPT
|
||||||
|
memberPtr = Member_pointer::NULLPT
|
||||||
|
|
||||||
|
check "Square area ", 100.0, Member_pointer::do_op(s, Member_pointer::AREAPT)
|
||||||
|
check "Square perim", 40.0, Member_pointer::do_op(s, Member_pointer::PERIMPT)
|
||||||
|
|
||||||
46
Examples/test-suite/tcl/member_pointer_runme.tcl
Normal file
46
Examples/test-suite/tcl/member_pointer_runme.tcl
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Example using pointers to member functions
|
||||||
|
|
||||||
|
if [ catch { load ./member_pointer[info sharedlibextension] member_pointer} err_msg ] {
|
||||||
|
puts stderr "Could not load shared object:\n$err_msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
proc check {what expected actual} {
|
||||||
|
if {$expected != $actual } {
|
||||||
|
error "Failed: $what , Expected: $expected , Actual: $actual"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Get the pointers
|
||||||
|
|
||||||
|
set area_pt [ areapt ]
|
||||||
|
set perim_pt [ perimeterpt ]
|
||||||
|
|
||||||
|
# Create some objects
|
||||||
|
|
||||||
|
set s [Square -args 10]
|
||||||
|
|
||||||
|
# Do some calculations
|
||||||
|
|
||||||
|
check "Square area " 100.0 [do_op $s $area_pt]
|
||||||
|
check "Square perim" 40.0 [do_op $s $perim_pt]
|
||||||
|
|
||||||
|
set memberPtr $areavar
|
||||||
|
set memberPtr $perimetervar
|
||||||
|
|
||||||
|
# Try the variables
|
||||||
|
check "Square area " 100.0 [do_op $s $areavar]
|
||||||
|
check "Square perim" 40.0 [do_op $s $perimetervar]
|
||||||
|
|
||||||
|
# Modify one of the variables
|
||||||
|
set areavar $perim_pt
|
||||||
|
|
||||||
|
check "Square perimeter" 40.0 [do_op $s $areavar]
|
||||||
|
|
||||||
|
# Try the constants
|
||||||
|
|
||||||
|
set memberPtr $AREAPT
|
||||||
|
set memberPtr $PERIMPT
|
||||||
|
set memberPtr $NULLPT
|
||||||
|
|
||||||
|
check "Square area " 100.0 [do_op $s $AREAPT]
|
||||||
|
check "Square perim" 40.0 [do_op $s $PERIMPT]
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue