PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 159 lines | 120 code | 36 blank | 3 comment | 0 complexity | 4ef652e9eace48e57723bb69640f17aa 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. %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */
  7. %inline %{
  8. int GlobalInt;
  9. const int ConstInt=2;
  10. int* GlobalIntPtr=&GlobalInt;
  11. int* const GlobalConstIntPtr=&GlobalInt;
  12. #define ARRAY_SIZE 2
  13. class ParametersTest {
  14. public:
  15. void param1(int* a) {}
  16. void param2(const int* a) {}
  17. void param3(int* const a) {}
  18. void param4(int const a) {}
  19. void param5(const int a) {}
  20. void param6(int& a) {}
  21. void param7(const int& a) {}
  22. void param8(int const& a) {}
  23. void param9(int*& a) {}
  24. void param10(int* const& a) {}
  25. void param11(const int* const a) {}
  26. void param_array1(int* a[ARRAY_SIZE]) {}
  27. void param_array2(const int* a[ARRAY_SIZE]) {}
  28. void param_array3(int* const a[ARRAY_SIZE]) {}
  29. void param_array4(int const a[ARRAY_SIZE]) {}
  30. void param_array5(const int a[ARRAY_SIZE]) {}
  31. void param_array6(const int* const a[ARRAY_SIZE]) {}
  32. };
  33. class MemberVariablesTest {
  34. public:
  35. int* member1;
  36. ParametersTest* member2;
  37. int* const member3;
  38. ParametersTest* const member4;
  39. int* array_member1[ARRAY_SIZE];
  40. ParametersTest* array_member2[ARRAY_SIZE];
  41. MemberVariablesTest() : member3(NULL), member4(NULL) {}
  42. private:
  43. MemberVariablesTest& operator=(const MemberVariablesTest&);
  44. };
  45. void foofunction(const int *const i) {}
  46. typedef int *typedef1, typedef2, *const typedef3;
  47. int int1, int2=2, *int3, *const int4 = &GlobalInt;
  48. int* const global_const_int_ptr_array[ARRAY_SIZE] = { &int1, &int2 };
  49. ParametersTest* const array_member4[ARRAY_SIZE] = { new ParametersTest(), new ParametersTest() };
  50. class ReturnValuesTest {
  51. public:
  52. typedef1 td1;
  53. typedef2 td2;
  54. int int1, int2, *const int3, *int4, array1[ARRAY_SIZE];
  55. int ret1() {return 5;}
  56. const int ret2() {return 5;}
  57. int ret3() {return 5;}
  58. const int* ret4() {return &ConstInt;}
  59. int* const ret5() {return &GlobalInt;}
  60. void ret6(int*& a) {}
  61. int*& ret7() {return GlobalIntPtr;}
  62. void ret8(int*const& a) {}
  63. int*const& ret9() {return GlobalIntPtr;}
  64. ReturnValuesTest() : int3(NULL) {}
  65. private:
  66. ReturnValuesTest& operator=(const ReturnValuesTest&);
  67. };
  68. const int* globalRet1() {return &GlobalInt;}
  69. int* const globalRet2() {return &GlobalInt;}
  70. %}
  71. %{
  72. struct A
  73. {
  74. };
  75. %}
  76. %inline
  77. {
  78. typedef const A* Acptr;
  79. Acptr opaque(Acptr aptr) {
  80. return aptr;
  81. }
  82. struct B
  83. {
  84. B() : ca() {}
  85. const A ca;
  86. A a;
  87. A* ap;
  88. const A* cap;
  89. Acptr acptr;
  90. private:
  91. B& operator=(const B&);
  92. };
  93. const B* bar(const B* b) {
  94. return b;
  95. }
  96. B *const& cbar(B *const& b) {
  97. return b;
  98. }
  99. }
  100. %{
  101. static int wxEVT_COMMAND_BUTTON_CLICKEDv;
  102. static int *wxEVT_COMMAND_BUTTON_CLICKEDp;
  103. static int **wxEVT_COMMAND_BUTTON_CLICKEDpp = &wxEVT_COMMAND_BUTTON_CLICKEDp;
  104. #if defined(SWIGR)
  105. #undef lang1 /* conflicts with symbol in R internals */
  106. #endif
  107. char lang1[16] = "Hello";
  108. char *langs[] ={ lang1 };
  109. %}
  110. %inline {
  111. #define EWXWEXPORT_VAR
  112. const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
  113. const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDpp;
  114. char **languages1 = &langs[0];
  115. char **languages2 = (char **)&langs[0];
  116. }
  117. %inline %{
  118. struct Foo {
  119. const int *icap;
  120. };
  121. const int* icap;
  122. const Foo *cap;
  123. %}