PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 207 lines | 160 code | 47 blank | 0 comment | 0 complexity | 0affd3607cb084b117672f126c7e154f MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module std_containers
  2. //
  3. // STL containers test suite.
  4. // Tests:
  5. // std::complex, std::string, std::vector, std::set, std::deque,
  6. // std::pair, std::map, std::multiset, std::multimap and IN/OUT functions
  7. // for them, with C++ types.
  8. //
  9. %{
  10. #include <set>
  11. %}
  12. %include std_vector.i
  13. %include std_string.i
  14. %include std_deque.i
  15. %include std_list.i
  16. %include std_set.i
  17. %include std_multiset.i
  18. %include std_pair.i
  19. %include std_map.i
  20. %include std_multimap.i
  21. %include std_complex.i
  22. %template() std::vector<double>;
  23. %template() std::pair<std::string, int>;
  24. %template() std::pair<int,double>;
  25. %template() std::vector< std::vector<double > > ;
  26. %template(ccube) std::vector< std::vector< std::vector<double > > >;
  27. %inline
  28. {
  29. typedef
  30. std::vector<std::vector<std::vector<double > > >
  31. ccube;
  32. ccube cident(const ccube& c)
  33. {
  34. return c;
  35. }
  36. struct C
  37. {
  38. };
  39. }
  40. %template(map_si) std::map<std::string, int>;
  41. %template(pair_iC) std::pair<int, C*>;
  42. %template(map_iC) std::map<int, C*>;
  43. %template(mmap_si) std::multimap<std::string, int>;
  44. %template(set_i) std::set<int>;
  45. %template(multiset_i) std::multiset<int>;
  46. %template(list_i) std::list<int>;
  47. %template(deque_i) std::deque<int>;
  48. %template(vector_b) std::vector<bool>;
  49. %template(vector_i) std::vector<int>;
  50. %template(vector_c) std::vector<std::complex<double> >;
  51. %template(vector_ui) std::vector<unsigned int>;
  52. %template(bmatrix) std::vector<std::vector<bool> >;
  53. %template(imatrix) std::vector<std::vector<int> >;
  54. %template(cmatrix) std::vector<std::vector<std::complex<double> > >;
  55. %apply std::vector<int> *INOUT {std::vector<int> *INOUT2};
  56. %inline
  57. {
  58. typedef std::vector<std::vector<int> > imatrix;
  59. imatrix midenti(const imatrix& v)
  60. {
  61. return v;
  62. }
  63. typedef std::vector<std::vector<bool> > bmatrix;
  64. bmatrix midentb(const bmatrix& v)
  65. {
  66. return v;
  67. }
  68. std::map<int,C*> mapidentc(const std::map<int,C*>& v)
  69. {
  70. return v;
  71. }
  72. std::map<int,int> mapidenti(const std::map<int,int>& v)
  73. {
  74. return v;
  75. }
  76. std::map<std::string,int> mapident(const std::map<std::string,int>& v)
  77. {
  78. return v;
  79. }
  80. std::multimap<std::string,int> mapident(const std::multimap<std::string,int>& v)
  81. {
  82. return v;
  83. }
  84. std::vector<int> vident(const std::vector<int>& v)
  85. {
  86. return v;
  87. }
  88. std::set<int> sident(const std::set<int>& v)
  89. {
  90. return v;
  91. }
  92. std::vector<unsigned int> videntu(const std::vector<unsigned int>& v)
  93. {
  94. return v;
  95. }
  96. int get_elem(const std::vector<int>& v, int index)
  97. {
  98. return v[index];
  99. }
  100. std::pair<int,double> pident(const std::pair<int,double>& p)
  101. {
  102. return p;
  103. }
  104. void
  105. v_inout(std::vector<int> *INOUT) {
  106. *INOUT = *INOUT;
  107. }
  108. void
  109. v_inout2(std::vector<int> *INOUT, std::vector<int> *INOUT2) {
  110. std::swap(*INOUT, *INOUT2);
  111. }
  112. }
  113. %{
  114. template <class C> struct Param
  115. {
  116. };
  117. %}
  118. template <class C> struct Param
  119. {
  120. };
  121. %template(Param_c) Param<std::complex<double> >;
  122. %inline
  123. {
  124. int hello(Param<std::complex<double> > c)
  125. {
  126. return 0;
  127. }
  128. }
  129. %inline
  130. {
  131. struct A
  132. {
  133. A(int aa = 0) : a(aa)
  134. {
  135. }
  136. int a;
  137. };
  138. }
  139. %template() std::pair<A,int>;
  140. %template(pair_iA) std::pair<int,A>;
  141. %template(vector_piA) std::vector<std::pair<int,A> >;
  142. %inline {
  143. std::pair<A,int> ident(std::pair<int,A> a, const std::pair<int,int>& b)
  144. {
  145. return std::pair<A,int>();
  146. }
  147. std::vector<std::pair<int,A> > pia_vident(std::vector<std::pair<int,A> > a )
  148. {
  149. return a;
  150. }
  151. struct Foo
  152. {
  153. Foo(int i) {
  154. }
  155. };
  156. }
  157. %std_nodefconst_type(Foo);
  158. %template(vector_Foo) std::vector<Foo>;
  159. %template(deque_Foo) std::deque<Foo>;
  160. %template(list_Foo) std::list<Foo>;