PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/test-suite/mixed_types.i

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