PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 166 lines | 122 code | 43 blank | 1 comment | 0 complexity | aac1e580ce44e68f0fc4bf72d68c6733 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module mixed_types
  2. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) hi; /* Ruby, wrong constant name */
  3. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) hello; /* Ruby, wrong constant name */
  4. %warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'hello' due to Go name ('Hello') conflict with 'Hello' */
  5. %inline
  6. {
  7. const void* ref_pointer(const void*& a) {
  8. return a;
  9. }
  10. struct A
  11. {
  12. };
  13. const A* ref_pointer(A* const& a) {
  14. return a;
  15. }
  16. const A** ref_pointer_1(const A**& a) {
  17. return a;
  18. }
  19. A* pointer_1(A* a) {
  20. return a;
  21. }
  22. const A& ref_const(const A& a) {
  23. return a;
  24. }
  25. enum Hello { hi,hello };
  26. int sint(int a) {
  27. return a;
  28. }
  29. const int& ref_int(const int& a) {
  30. return a;
  31. }
  32. Hello senum(Hello a) {
  33. return a;
  34. }
  35. const Hello& ref_enum(const Hello& a) {
  36. return a;
  37. }
  38. typedef A *Aptr;
  39. const Aptr& rptr_const(const Aptr& a) {
  40. return a;
  41. }
  42. const Aptr& rptr_const2(const Aptr& a) {
  43. return a;
  44. }
  45. const void*& rptr_void(const void*& a) {
  46. return a;
  47. }
  48. const A& cref_a(const A& a) {
  49. return a;
  50. }
  51. A& ref_a(A& a) {
  52. return a;
  53. }
  54. template <class T> struct NameT {
  55. };
  56. typedef char name[8];
  57. typedef char namea[];
  58. typedef NameT<char> name_t[8];
  59. char* test_a(char hello[8],
  60. char hi[],
  61. const char chello[8],
  62. const char chi[]) {
  63. return hi;
  64. }
  65. int test_b(name n2) {
  66. return 1;
  67. }
  68. /* gcc doesn't like this one. Removing until reason resolved.*/
  69. int test_c(const name& n1) {
  70. return 1;
  71. }
  72. int test_d(name* n1) {
  73. return 1;
  74. }
  75. int test_e(const name_t& n1) {
  76. return 1;
  77. }
  78. int test_f(name_t n1) {
  79. return 1;
  80. }
  81. int test_g(name_t* n1) {
  82. return 1;
  83. }
  84. struct Foo
  85. {
  86. int foo(const Aptr&a);
  87. int foon(const char (&a)[8]);
  88. };
  89. inline int Foo::foo(A* const& a) { return 1; }
  90. }
  91. %{
  92. inline int Foo::foon(const name& a) { return a[0]; }
  93. %}
  94. %inline %{
  95. #define ARRAY_LEN_X 2
  96. #define ARRAY_LEN_Y 4
  97. typedef enum {One, Two, Three, Four, Five} finger;
  98. typedef struct {
  99. double double_field;
  100. } SimpleStruct;
  101. char array_c [ARRAY_LEN_X][ARRAY_LEN_Y];
  102. signed char array_sc[ARRAY_LEN_X][ARRAY_LEN_Y];
  103. unsigned char array_uc[ARRAY_LEN_X][ARRAY_LEN_Y];
  104. short array_s [ARRAY_LEN_X][ARRAY_LEN_Y];
  105. unsigned short array_us[ARRAY_LEN_X][ARRAY_LEN_Y];
  106. int array_i [ARRAY_LEN_X][ARRAY_LEN_Y];
  107. unsigned int array_ui[ARRAY_LEN_X][ARRAY_LEN_Y];
  108. long array_l [ARRAY_LEN_X][ARRAY_LEN_Y];
  109. unsigned long array_ul[ARRAY_LEN_X][ARRAY_LEN_Y];
  110. long long array_ll[ARRAY_LEN_X][ARRAY_LEN_Y];
  111. float array_f [ARRAY_LEN_X][ARRAY_LEN_Y];
  112. double array_d [ARRAY_LEN_X][ARRAY_LEN_Y];
  113. SimpleStruct array_struct[ARRAY_LEN_X][ARRAY_LEN_Y];
  114. SimpleStruct* array_structpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
  115. int* array_ipointers [ARRAY_LEN_X][ARRAY_LEN_Y];
  116. finger array_enum[ARRAY_LEN_X][ARRAY_LEN_Y];
  117. finger* array_enumpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
  118. const int array_const_i[ARRAY_LEN_X][ARRAY_LEN_Y] = { {10, 11, 12, 13}, {14, 15, 16, 17} };
  119. void fn_taking_arrays(SimpleStruct array_struct[ARRAY_LEN_X][ARRAY_LEN_Y]) {}
  120. int get_2d_array(int (*array)[ARRAY_LEN_Y], int x, int y){
  121. return array[x][y];
  122. }
  123. %}