PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/test-suite/member_funcptr_galore.i

#
Swig | 95 lines | 69 code | 22 blank | 4 comment | 0 complexity | e9276ac7e88e96c418ce85f47266fe22 MD5 | raw file
 1%module member_funcptr_galore
 2
 3%{
 4#if defined(__SUNPRO_CC)
 5#pragma error_messages (off, badargtype2w) /* Formal argument ... is being passed extern "C" ... */
 6#pragma error_messages (off, wbadinit) /* Using extern "C" ... to initialize ... */
 7#pragma error_messages (off, wbadasg) /* Assigning extern "C" ... */
 8#endif
 9%}
10
11%inline %{
12
13namespace FunkSpace {
14struct Funktions {
15  int addByValue(const int &a, int b) { return a+b; }
16  int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; }
17  int & addByReference(const int &a, int b) { static int val; val = a+b; return val; }
18};
19}
20
21template <typename T> struct Thing {};
22namespace Space {
23class Shape {
24public:
25  double  x, y;   
26  double  *z;
27
28  void    move(double dx, double dy);
29  virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)) { return 0.0; }
30  virtual double abc(Thing<short> ts, Thing< const Space::Shape * > tda[]) { return 0.0; }
31};
32}
33
34extern double do_op(Space::Shape *s, double (Space::Shape::*m)(void));
35
36/* Functions that return member pointers */
37
38extern double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
39extern double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * > tda[]);
40
41/* Global variables that are member pointers */
42extern double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
43extern double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]);
44
45%}
46
47%{
48void Space::Shape::move(double dx, double dy) {
49  x += dx;
50  y += dy;
51}
52
53double do_op(Space::Shape *s, double (Space::Shape::*m)(void)) {
54  return (s->*m)();
55}
56
57double (Space::Shape::*areapt(Space::Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)))(Space::Shape &, int & (FunkSpace::Funktions::*d)(const int &, int)) {
58  return &Space::Shape::area;
59}
60
61double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) {
62  return 0;
63}
64
65double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * >[]) {
66  return &Space::Shape::abc;
67}
68
69/* Member pointer variables */
70double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
71double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
72%}
73
74
75/* Some constants */
76%constant double (Space::Shape::*AREAPT)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
77%constant double (Space::Shape::*PERIMPT)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
78%constant double (Space::Shape::*NULLPT)(void) = 0;
79
80%inline %{
81
82int call1(int (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
83int call2(int * (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return *(f.*d)(a, b); }
84int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
85%}
86
87%constant int (FunkSpace::Funktions::*ADD_BY_VALUE)(const int &, int) = &FunkSpace::Funktions::addByValue;
88%constant int * (FunkSpace::Funktions::*ADD_BY_POINTER)(const int &, int) = &FunkSpace::Funktions::addByPointer;
89%constant int & (FunkSpace::Funktions::*ADD_BY_REFERENCE)(const int &, int) = &FunkSpace::Funktions::addByReference;
90
91%inline %{
92// parameter that is a member pointer containing a function ptr, urgh :)
93int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
94int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; }
95%}