PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/constant_pointers.i

#
Swig | 143 lines | 106 code | 34 blank | 3 comment | 0 complexity | 68c800f94cfd93f132107ac69e198db3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /*
  2. This testcase primarily test constant pointers, eg int* const. Only a getter is expected to be produced when wrapping constant pointer variables. A number of other const issues are also tested.
  3. */
  4. %module constant_pointers
  5. %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */
  6. %inline %{
  7. int GlobalInt;
  8. const int ConstInt=2;
  9. int* GlobalIntPtr=&GlobalInt;
  10. int* const GlobalConstIntPtr=&GlobalInt;
  11. #define ARRAY_SIZE 2
  12. class ParametersTest {
  13. public:
  14. void param1(int* a) {}
  15. void param2(const int* a) {}
  16. void param3(int* const a) {}
  17. void param4(int const a) {}
  18. void param5(const int a) {}
  19. void param6(int& a) {}
  20. void param7(const int& a) {}
  21. void param8(int const& a) {}
  22. void param9(int*& a) {}
  23. void param10(int* const& a) {}
  24. void param11(const int* const a) {}
  25. void param_array1(int* a[ARRAY_SIZE]) {}
  26. void param_array2(const int* a[ARRAY_SIZE]) {}
  27. void param_array3(int* const a[ARRAY_SIZE]) {}
  28. void param_array4(int const a[ARRAY_SIZE]) {}
  29. void param_array5(const int a[ARRAY_SIZE]) {}
  30. void param_array6(const int* const a[ARRAY_SIZE]) {}
  31. };
  32. class MemberVariablesTest {
  33. public:
  34. int* member1;
  35. ParametersTest* member2;
  36. int* const member3;
  37. ParametersTest* const member4;
  38. int* array_member1[ARRAY_SIZE];
  39. ParametersTest* array_member2[ARRAY_SIZE];
  40. MemberVariablesTest() : member3(NULL), member4(NULL) {}
  41. };
  42. void foo(const int *const i) {}
  43. typedef int *typedef1, typedef2, *const typedef3;
  44. int int1, int2=2, *int3, *const int4 = &GlobalInt;
  45. int* const global_const_int_ptr_array[ARRAY_SIZE] = { &int1, &int2 };
  46. ParametersTest* const array_member4[ARRAY_SIZE] = { new ParametersTest(), new ParametersTest() };
  47. class ReturnValuesTest {
  48. public:
  49. typedef1 td1;
  50. typedef2 td2;
  51. int int1, int2, *const int3, *int4, array1[ARRAY_SIZE];
  52. int ret1() {return 5;}
  53. const int ret2() {return 5;}
  54. int ret3() {return 5;}
  55. const int* ret4() {return &ConstInt;}
  56. int* const ret5() {return &GlobalInt;}
  57. void ret6(int*& a) {}
  58. int*& ret7() {return GlobalIntPtr;}
  59. ReturnValuesTest() : int3(NULL) {}
  60. };
  61. const int* globalRet1() {return &GlobalInt;}
  62. int* const globalRet2() {return &GlobalInt;}
  63. %}
  64. %{
  65. struct A
  66. {
  67. };
  68. %}
  69. %inline
  70. {
  71. typedef const A* Acptr;
  72. Acptr opaque(Acptr aptr) {
  73. return aptr;
  74. }
  75. struct B
  76. {
  77. B() : ca() {}
  78. const A ca;
  79. A a;
  80. A* ap;
  81. const A* cap;
  82. Acptr acptr;
  83. };
  84. const B* bar(const B* b) {
  85. return b;
  86. }
  87. B const*& cbar(B const*& b) {
  88. return b;
  89. }
  90. }
  91. %{
  92. static int wxEVT_COMMAND_BUTTON_CLICKEDv;
  93. static int **wxEVT_COMMAND_BUTTON_CLICKEDp;
  94. char *langs[] ={"Hello"};
  95. %}
  96. %inline {
  97. #define EWXWEXPORT_VAR
  98. const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
  99. const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDp;
  100. char **languages1 = &langs[0];
  101. char **languages2 = (char **)&langs[0];
  102. }
  103. %inline %{
  104. struct Foo {
  105. const int *icap;
  106. };
  107. const int* icap;
  108. const Foo *cap;
  109. %}