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

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

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