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