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