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 
57 namespace 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     %traits_enum(_Tp);
73 
74     %fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header",
75 	      fragment=SWIG_Traits_frag(_Tp),
76 	      fragment="StdVectorTraits") {
77       namespace swig {
78 	template <>  struct traits<std::vector<_Tp, _Alloc > > {
79 	  typedef pointer_category category;
80 	  static const char* type_name() {
81 	    return "std::vector<" #_Tp "," #_Alloc " >";
82 	  }
83 	};
84       }
85     }
86 
87     %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp, _Alloc >);
88 
89 #ifdef %swig_vector_methods
90     // Add swig/language extra methods
91     %swig_vector_methods(std::vector<_Tp, _Alloc >);
92 #endif
93 
94     %std_vector_methods(vector);
95   };
96 
97   // ***
98   // This specialization should disappear or get simplified when
99   // a 'const SWIGTYPE*&' can be defined
100   // ***
101   template<class _Tp, class _Alloc >
102   class vector<_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::vector<_Tp*, _Alloc >), "header",
116 	      fragment=SWIG_Traits_frag(_Tp),
117 	      fragment="StdVectorTraits") {
118       namespace swig {
119 	template <>  struct traits<std::vector<_Tp*, _Alloc > > {
120 	  typedef value_category category;
121 	  static const char* type_name() {
122 	    return "std::vector<" #_Tp " *," #_Alloc " >";
123 	  }
124 	};
125       }
126     }
127 
128     %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp*, _Alloc >);
129 
130 #ifdef %swig_vector_methods_val
131     // Add swig/language extra methods
132     %swig_vector_methods_val(std::vector<_Tp*, _Alloc >);
133 #endif
134 
135     %std_vector_methods_val(vector);
136   };
137 
138   // ***
139   // const pointer specialization
140   // ***
141   template<class _Tp, class _Alloc >
142   class vector<_Tp const *, _Alloc > {
143   public:
144     typedef size_t size_type;
145     typedef ptrdiff_t difference_type;
146     typedef _Tp const * 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(_Tp);
154 
155     %fragment(SWIG_Traits_frag(std::vector<_Tp const*, _Alloc >), "header",
156 	      fragment=SWIG_Traits_frag(_Tp),
157 	      fragment="StdVectorTraits") {
158       namespace swig {
159 	template <>  struct traits<std::vector<_Tp const*, _Alloc > > {
160 	  typedef value_category category;
161 	  static const char* type_name() {
162 	    return "std::vector<" #_Tp " const*," #_Alloc " >";
163 	  }
164 	};
165       }
166     }
167 
168     %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp const*, _Alloc >);
169 
170 #ifdef %swig_vector_methods_val
171     // Add swig/language extra methods
172     %swig_vector_methods_val(std::vector<_Tp const*, _Alloc >);
173 #endif
174 
175     %std_vector_methods_val(vector);
176   };
177 
178   // ***
179   // bool specialization
180   // ***
181 
182   template<class _Alloc >
183   class vector<bool,_Alloc > {
184   public:
185     typedef size_t size_type;
186     typedef ptrdiff_t difference_type;
187     typedef bool value_type;
188     typedef value_type* pointer;
189     typedef const value_type* const_pointer;
190     typedef value_type reference;
191     typedef value_type const_reference;
192     typedef _Alloc allocator_type;
193 
194     %traits_swigtype(bool);
195 
196     %fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header",
197 	      fragment=SWIG_Traits_frag(bool),
198 	      fragment="StdVectorTraits") {
199       namespace swig {
200 	template <>  struct traits<std::vector<bool, _Alloc > > {
201 	  typedef value_category category;
202 	  static const char* type_name() {
203 	    return "std::vector<bool, _Alloc >";
204 	  }
205 	};
206       }
207     }
208 
209     %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >);
210 
211 
212 #ifdef %swig_vector_methods_val
213     // Add swig/language extra methods
214     %swig_vector_methods_val(std::vector<bool, _Alloc >);
215 #endif
216 
217     %std_vector_methods_val(vector);
218 
219 #if defined(SWIG_STD_MODERN_STL) && !defined(SWIG_STD_NOMODERN_STL)
220     void flip();
221 #endif
222 
223   };
224 
225 }
226