1// 2// std::vector 3// 4 5%include <std_container.i> 6 7// Vector 8 9%define %std_vector_methods(vector...) 10 %std_sequence_methods(vector) 11 12 void reserve(size_type n); 13 size_type capacity() const; 14%enddef 15 16 17%define %std_vector_methods_val(vector...) 18 %std_sequence_methods_val(vector) 19 20 void reserve(size_type n); 21 size_type capacity() const; 22%enddef 23 24 25// ------------------------------------------------------------------------ 26// std::vector 27// 28// The aim of all that follows would be to integrate std::vector with 29// as much as possible, namely, to allow the user to pass and 30// be returned tuples or lists. 31// const declarations are used to guess the intent of the function being 32// exported; therefore, the following rationale is applied: 33// 34// -- f(std::vector<T>), f(const std::vector<T>&): 35// the parameter being read-only, either a sequence or a 36// previously wrapped std::vector<T> can be passed. 37// -- f(std::vector<T>&), f(std::vector<T>*): 38// the parameter may be modified; therefore, only a wrapped std::vector 39// can be passed. 40// -- std::vector<T> f(), const std::vector<T>& f(): 41// the vector is returned by copy; therefore, a sequence of T:s 42// is returned which is most easily used in other functions 43// -- std::vector<T>& f(), std::vector<T>* f(): 44// the vector is returned by reference; therefore, a wrapped std::vector 45// is returned 46// -- const std::vector<T>* f(), f(const std::vector<T>*): 47// for consistency, they expect and return a plain vector pointer. 48// ------------------------------------------------------------------------ 49 50%{ 51#include <vector> 52%} 53 54// exported classes 55 56 57namespace std { 58 59 template<class _Tp, class _Alloc = allocator< _Tp > > 60 class vector { 61 public: 62 typedef size_t size_type; 63 typedef ptrdiff_t difference_type; 64 typedef _Tp value_type; 65 typedef value_type* pointer; 66 typedef const value_type* const_pointer; 67 typedef _Tp& reference; 68 typedef const _Tp& const_reference; 69 typedef _Alloc allocator_type; 70 71 %traits_swigtype(_Tp); 72 73 %fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header", 74 fragment=SWIG_Traits_frag(_Tp), 75 fragment="StdVectorTraits") { 76 namespace swig { 77 template <> struct traits<std::vector<_Tp, _Alloc > > { 78 typedef pointer_category category; 79 static const char* type_name() { 80 return "std::vector<" #_Tp "," #_Alloc " >"; 81 } 82 }; 83 } 84 } 85 86 %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp, _Alloc >); 87 88#ifdef %swig_vector_methods 89 // Add swig/language extra methods 90 %swig_vector_methods(std::vector<_Tp, _Alloc >); 91#endif 92 93 %std_vector_methods(vector); 94 }; 95 96 // *** 97 // This specialization should dissapear or get simplified when 98 // a 'const SWIGTYPE*&' can be defined 99 // *** 100 template<class _Tp, class _Alloc > 101 class vector<_Tp*, _Alloc > { 102 public: 103 typedef size_t size_type; 104 typedef ptrdiff_t difference_type; 105 typedef _Tp* value_type; 106 typedef value_type* pointer; 107 typedef const value_type* const_pointer; 108 typedef value_type reference; 109 typedef value_type const_reference; 110 typedef _Alloc allocator_type; 111 112 %traits_swigtype(_Tp); 113 114 %fragment(SWIG_Traits_frag(std::vector<_Tp*, _Alloc >), "header", 115 fragment=SWIG_Traits_frag(_Tp), 116 fragment="StdVectorTraits") { 117 namespace swig { 118 template <> struct traits<std::vector<_Tp*, _Alloc > > { 119 typedef value_category category; 120 static const char* type_name() { 121 return "std::vector<" #_Tp " *," #_Alloc " >"; 122 } 123 }; 124 } 125 } 126 127 %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp*, _Alloc >); 128 129#ifdef %swig_vector_methods_val 130 // Add swig/language extra methods 131 %swig_vector_methods_val(std::vector<_Tp*, _Alloc >); 132#endif 133 134 %std_vector_methods_val(vector); 135 }; 136 137 // *** 138 // *** 139 // bool specialization 140 141 template<class _Alloc > 142 class vector<bool,_Alloc > { 143 public: 144 typedef size_t size_type; 145 typedef ptrdiff_t difference_type; 146 typedef bool value_type; 147 typedef value_type* pointer; 148 typedef const value_type* const_pointer; 149 typedef value_type reference; 150 typedef value_type const_reference; 151 typedef _Alloc allocator_type; 152 153 %traits_swigtype(bool); 154 155 %fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header", 156 fragment=SWIG_Traits_frag(bool), 157 fragment="StdVectorTraits") { 158 namespace swig { 159 template <> struct traits<std::vector<bool, _Alloc > > { 160 typedef value_category category; 161 static const char* type_name() { 162 return "std::vector<bool, _Alloc >"; 163 } 164 }; 165 } 166 } 167 168 %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >); 169 170 171#ifdef %swig_vector_methods_val 172 // Add swig/language extra methods 173 %swig_vector_methods_val(std::vector<bool, _Alloc >); 174#endif 175 176 %std_vector_methods_val(vector); 177 178#if defined(SWIG_STD_MODERN_STL) && !defined(SWIG_STD_NOMODERN_STL) 179 void flip(); 180#endif 181 182 }; 183 184} 185