1 // 2 // std::list 3 // 4 5 %include <std_container.i> 6 7 // List 8 9 %define %std_list_methods(list) 10 %std_sequence_methods(list) 11 12 void pop_front(); 13 void push_front(const value_type& x); 14 15 void reverse(); 16 17 %enddef 18 19 20 %define %std_list_methods_val(list) 21 %std_sequence_methods_val(list) 22 23 void pop_front(); 24 void push_front(value_type x); 25 26 void remove(value_type x); 27 void unique(); 28 void reverse(); 29 void sort(); 30 31 void merge(list& x); 32 %enddef 33 34 // ------------------------------------------------------------------------ 35 // std::list 36 // 37 // const declarations are used to guess the intent of the function being 38 // exported; therefore, the following rationale is applied: 39 // 40 // -- f(std::list<T>), f(const std::list<T>&): 41 // the parameter being read-only, either a sequence or a 42 // previously wrapped std::list<T> can be passed. 43 // -- f(std::list<T>&), f(std::list<T>*): 44 // the parameter may be modified; therefore, only a wrapped std::list 45 // can be passed. 46 // -- std::list<T> f(), const std::list<T>& f(): 47 // the list is returned by copy; therefore, a sequence of T:s 48 // is returned which is most easily used in other functions 49 // -- std::list<T>& f(), std::list<T>* f(): 50 // the list is returned by reference; therefore, a wrapped std::list 51 // is returned 52 // -- const std::list<T>* f(), f(const std::list<T>*): 53 // for consistency, they expect and return a plain list pointer. 54 // ------------------------------------------------------------------------ 55 56 %{ 57 #include <list> 58 %} 59 60 // exported classes 61 62 namespace std { 63 64 template<class _Tp, class _Alloc = allocator<_Tp> > 65 class list { 66 public: 67 typedef size_t size_type; 68 typedef ptrdiff_t difference_type; 69 typedef _Tp value_type; 70 typedef value_type* pointer; 71 typedef const value_type* const_pointer; 72 typedef value_type& reference; 73 typedef const value_type& const_reference; 74 typedef _Alloc allocator_type; 75 76 %traits_swigtype(_Tp); 77 78 %fragment(SWIG_Traits_frag(std::list<_Tp, _Alloc >), "header", 79 fragment=SWIG_Traits_frag(_Tp), 80 fragment="StdListTraits") { 81 namespace swig { 82 template <> struct traits<std::list<_Tp, _Alloc > > { 83 typedef pointer_category category; 84 static const char* type_name() { 85 return "std::list<" #_Tp ", " #_Alloc " >"; 86 } 87 }; 88 } 89 } 90 91 %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp, _Alloc >); 92 93 #ifdef %swig_list_methods 94 // Add swig/language extra methods 95 %swig_list_methods(std::list<_Tp, _Alloc >); 96 #endif 97 98 %std_list_methods(list); 99 }; 100 101 template<class _Tp, class _Alloc > 102 class list<_Tp*, _Alloc> { 103 public: 104 typedef size_t size_type; 105 typedef ptrdiff_t difference_type; 106 typedef _Tp* value_type; 107 typedef value_type* pointer; 108 typedef const value_type* const_pointer; 109 typedef value_type reference; 110 typedef value_type const_reference; 111 typedef _Alloc allocator_type; 112 113 %traits_swigtype(_Tp); 114 115 %fragment(SWIG_Traits_frag(std::list<_Tp*, _Alloc >), "header", 116 fragment=SWIG_Traits_frag(_Tp), 117 fragment="StdListTraits") { 118 namespace swig { 119 template <> struct traits<std::list<_Tp*, _Alloc > > { 120 typedef value_category category; 121 static const char* type_name() { 122 return "std::list<" #_Tp " *," #_Alloc " >"; 123 } 124 }; 125 } 126 } 127 128 %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp*, _Alloc >); 129 130 #ifdef %swig_list_methods_val 131 // Add swig/language extra methods 132 %swig_list_methods_val(std::list<_Tp*, _Alloc >); 133 #endif 134 135 %std_list_methods_val(list); 136 }; 137 138 } 139 140 %define %std_extequal_list(...) 141 %extend std::list<__VA_ARGS__ > { 142 void remove(const value_type& x) { self->remove(x); } 143 void merge(std::list<__VA_ARGS__ >& x){ self->merge(x); } 144 void unique() { self->unique(); } 145 void sort() { self->sort(); } 146 } 147 %enddef 148 149