More extensive member function pointer test
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12336 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7903475571
commit
32769435fd
2 changed files with 84 additions and 0 deletions
|
|
@ -231,6 +231,7 @@ CPP_TEST_CASES += \
|
|||
li_windows \
|
||||
long_long_apply \
|
||||
memberin_extend \
|
||||
member_funcptr_galore \
|
||||
member_pointer \
|
||||
member_template \
|
||||
minherit \
|
||||
|
|
|
|||
83
Examples/test-suite/member_funcptr_galore.i
Normal file
83
Examples/test-suite/member_funcptr_galore.i
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
%module member_pointer
|
||||
|
||||
%inline %{
|
||||
|
||||
namespace FunkSpace {
|
||||
struct Funktions {
|
||||
int addByValue(const int &a, int b) { return a+b; }
|
||||
int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; }
|
||||
int & addByReference(const int &a, int b) { static int val; val = a+b; return val; }
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T> struct Thing {};
|
||||
namespace Space {
|
||||
class Shape {
|
||||
public:
|
||||
double x, y;
|
||||
double *z;
|
||||
|
||||
void move(double dx, double dy);
|
||||
virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int));
|
||||
virtual double abc(Thing<short> ts, Thing< const Space::Shape * > tda[]);
|
||||
};
|
||||
}
|
||||
|
||||
extern double do_op(Space::Shape *s, double (Space::Shape::*m)(void));
|
||||
|
||||
/* Functions that return member pointers */
|
||||
|
||||
extern double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
|
||||
extern double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * > tda[]);
|
||||
|
||||
/* Global variables that are member pointers */
|
||||
extern double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
|
||||
extern double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]);
|
||||
|
||||
%}
|
||||
|
||||
%{
|
||||
void Space::Shape::move(double dx, double dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
double do_op(Space::Shape *s, double (Space::Shape::*m)(void)) {
|
||||
return (s->*m)();
|
||||
}
|
||||
|
||||
double (Space::Shape::*areapt(Space::Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)))(Space::Shape &, int & (FunkSpace::Funktions::*d)(const int &, int)) {
|
||||
return &Space::Shape::area;
|
||||
}
|
||||
|
||||
double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * >[]) {
|
||||
return &Space::Shape::abc;
|
||||
}
|
||||
|
||||
/* Member pointer variables */
|
||||
double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
|
||||
double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
|
||||
%}
|
||||
|
||||
|
||||
/* Some constants */
|
||||
%constant double (Space::Shape::*AREAPT)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
|
||||
%constant double (Space::Shape::*PERIMPT)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
|
||||
%constant double (Space::Shape::*NULLPT)(void) = 0;
|
||||
|
||||
%inline %{
|
||||
|
||||
int call1(int (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
|
||||
int call2(int * (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return *(f.*d)(a, b); }
|
||||
int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
|
||||
%}
|
||||
|
||||
%constant int (FunkSpace::Funktions::*ADD_BY_VALUE)(const int &, int) = &FunkSpace::Funktions::addByValue;
|
||||
%constant int * (FunkSpace::Funktions::*ADD_BY_POINTER)(const int &, int) = &FunkSpace::Funktions::addByPointer;
|
||||
%constant int & (FunkSpace::Funktions::*ADD_BY_REFERENCE)(const int &, int) = &FunkSpace::Funktions::addByReference;
|
||||
|
||||
%inline %{
|
||||
// parameter that is a member pointer containing a function ptr, urgh :)
|
||||
int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
|
||||
int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; }
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue