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