PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 111 lines | 92 code | 19 blank | 0 comment | 0 complexity | e80d953b6dab5513ef064b81703a4293 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module template_typemaps_typedef2
  2. // Identical to template_typemaps_typedef, except for %template
  3. // Similar to template_typedef_class_template
  4. // Testing typemaps of a typedef of a nested class in a template and where the template uses default parameters
  5. %inline %{
  6. namespace Standard {
  7. template <class T, class U > struct Pair {
  8. T first;
  9. U second;
  10. };
  11. }
  12. %}
  13. %{
  14. namespace Standard {
  15. template<class Key, class T, class J = int> class Multimap {
  16. public:
  17. typedef Key key_type;
  18. typedef T mapped_type;
  19. class iterator {
  20. public:
  21. mapped_type mm;
  22. iterator(mapped_type m = mapped_type()) : mm(m) {}
  23. };
  24. mapped_type typemap_test(Standard::Pair<iterator,iterator> pp) { return pp.second.mm; }
  25. Standard::Pair<iterator,iterator>* make_dummy_pair() { return new Standard::Pair<iterator, iterator>(); }
  26. };
  27. }
  28. %}
  29. namespace Standard {
  30. template<class Key, class T, class J = int> class Multimap {
  31. public:
  32. typedef Key key_type;
  33. typedef T mapped_type;
  34. class iterator;
  35. %typemap(in) Standard::Pair<iterator,iterator> "$1 = default_general< Key, T >();"
  36. mapped_type typemap_test(Standard::Pair<iterator,iterator> pii1);
  37. Standard::Pair<iterator,iterator>* make_dummy_pair();
  38. };
  39. }
  40. // specialization
  41. namespace Standard {
  42. template<> class Multimap<A, int> {
  43. public:
  44. typedef A key_type;
  45. typedef int mapped_type;
  46. class iterator;
  47. // Note uses a different function to the non-specialized version
  48. %typemap(in) Standard::Pair<iterator,iterator> "$1 = default_A_int< A, int >();"
  49. mapped_type typemap_test(Standard::Pair<iterator,iterator> pii2);
  50. Standard::Pair<iterator,iterator>* make_dummy_pair();
  51. };
  52. }
  53. %inline %{
  54. struct A {
  55. int val;
  56. A(int v = 0): val(v) {}
  57. };
  58. %}
  59. %{
  60. // For < int, A >
  61. template<typename Key, typename T> Standard::Pair< typename Standard::Multimap< Key, T >::iterator, typename Standard::Multimap< Key, T >::iterator > default_general() {
  62. Standard::Pair< typename Standard::Multimap< Key, T >::iterator, typename Standard::Multimap< Key, T >::iterator > default_value;
  63. default_value.second.mm = A(1234);
  64. return default_value;
  65. }
  66. // For < A, int >
  67. template<typename Key, typename T> Standard::Pair< typename Standard::Multimap< Key, T >::iterator, typename Standard::Multimap< Key, T >::iterator > default_A_int() {
  68. Standard::Pair< typename Standard::Multimap< Key, T >::iterator, typename Standard::Multimap< Key, T >::iterator > default_value;
  69. default_value.second.mm = 4321;
  70. return default_value;
  71. }
  72. %}
  73. %inline %{
  74. typedef A AA;
  75. namespace Space {
  76. typedef AA AB;
  77. }
  78. %}
  79. %template(PairIntA) Standard::Pair<int, Space::AB>;
  80. %template(MultimapIntA) Standard::Multimap<int, Space::AB>;
  81. %template(PairAInt) Standard::Pair<Space::AB, int>;
  82. %template(MultimapAInt) Standard::Multimap<Space::AB, int>;
  83. %inline %{
  84. // Extend the test with some typedefs in the template parameters
  85. Standard::Multimap< int, AA >::mapped_type typedef_test1(Standard::Pair< Standard::Multimap< int, AA >::iterator, Standard::Multimap< int, AA >::iterator > pp) { return pp.second.mm; }
  86. Standard::Multimap< int, A >::mapped_type typedef_test2(Standard::Pair< Standard::Multimap< int, A >::iterator, Standard::Multimap< int, A >::iterator > pp) { return pp.second.mm; }
  87. Standard::Multimap< int, AA, int >::mapped_type typedef_test3(Standard::Pair< Standard::Multimap< int, AA, int >::iterator, Standard::Multimap< int, AA, int >::iterator > pp) { return pp.second.mm; }
  88. Standard::Multimap< int, A , int >::mapped_type typedef_test4(Standard::Pair< Standard::Multimap< int, A , int >::iterator, Standard::Multimap< int, A , int >::iterator > pp) { return pp.second.mm; }
  89. using namespace Space;
  90. Standard::Multimap< int, AB >::mapped_type typedef_test5(Standard::Pair< Standard::Multimap< int, AB >::iterator, Standard::Multimap< int, AB >::iterator > pp) { return pp.second.mm; }
  91. Standard::Multimap< int, AB, int >::mapped_type typedef_test6(Standard::Pair< Standard::Multimap< int, AB, int >::iterator, Standard::Multimap< int, AB, int >::iterator > pp) { return pp.second.mm; }
  92. %}