]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/vector.h
Correctly link to wxWebViewNavigationError from wxWebViewEvent.
[wxWidgets.git] / interface / wx / vector.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: vector.h
e54c96f1 3// Purpose: interface of wxVector<T>
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
7c913512 10
f016d3b4
VS
11 wxVector<T> is a template class which implements most of the @c std::vector
12 class and can be used like it.
7c913512 13
09ad05fa
BP
14 If wxWidgets is compiled in STL mode, wxVector will just be a typedef to
15 @c std::vector. Just like for @c std::vector, objects stored in wxVector<T>
16 need to be @e assignable but don't have to be @e "default constructible".
f016d3b4
VS
17
18 Please refer to the STL documentation for further information.
7c913512 19
e18e78a7 20 @nolibrary
f016d3b4 21 @category{containers}
7c913512 22
38723be1 23 @see @ref overview_container, wxList<T>, wxArray<T>, wxVectorSort<T>
23324ae1 24*/
f016d3b4 25template<typename T>
7c913512 26class wxVector<T>
23324ae1
FM
27{
28public:
f016d3b4 29 typedef size_t size_type;
946954d3 30 typedef size_t difference_type;
f016d3b4 31 typedef T value_type;
946954d3 32 typedef value_type* pointer;
f016d3b4
VS
33 typedef value_type* iterator;
34 typedef const value_type* const_iterator;
35 typedef value_type& reference;
36
23324ae1
FM
37 /**
38 Constructor.
39 */
f016d3b4
VS
40 wxVector();
41
664e5ff9
VZ
42 /**
43 Constructor initializing the vector with the given number of
44 default-constructed objects.
45 */
46 wxVector(size_type size);
47
48 /**
49 Constructor initializing the vector with the given number of
50 copies of the given object.
51 */
52 wxVector(size_type size, const value_type& value);
53
4a8e9799
VZ
54 /**
55 Constructor initializing the vector with the elements in the given
56 range.
57
58 The @a InputIterator template parameter must be an input iterator type.
59 This constructor adds all elements from @a first until, not not
60 including, @a last to the vector.
61
62 @since 2.9.5
63 */
64 template <class InputIterator>
65 wxVector(InputIterator first, InputIterator last);
66
f016d3b4 67 /**
d13b34d3 68 Copy constructor.
f016d3b4
VS
69 */
70 wxVector(const wxVector<T>& c);
23324ae1
FM
71
72 /**
73 Destructor.
74 */
f016d3b4
VS
75 ~wxVector();
76
2ff86a86
VZ
77 /**
78 Resizes the vector to @a n and assigns @a v to all elements.
79
80 @see resize()
81
82 @since 2.9.5
83 */
84 void assign(size_type n, const value_type& v);
85
4a8e9799
VZ
86 /**
87 Assigns the elements in the given range to the vector.
88
89 The @a InputIterator template parameter must be an input iterator type.
90 This method clears the vector and then adds all elements from @a first
91 until, not not including, @a last to it.
92
93 @since 2.9.5
94 */
95 template <class InputIterator>
96 void assign(InputIterator first, InputIterator last);
97
f016d3b4 98 /**
09ad05fa 99 Returns item at position @a idx.
f016d3b4
VS
100 */
101 const value_type& at(size_type idx) const;
23324ae1 102
23324ae1 103 /**
09ad05fa 104 Returns item at position @a idx.
23324ae1 105 */
f016d3b4 106 value_type& at(size_type idx);
23324ae1 107
23324ae1 108 /**
f016d3b4 109 Return the last item.
23324ae1 110 */
f016d3b4
VS
111 const value_type& back() const;
112
113 /**
114 Return the last item.
115 */
116 value_type& back();
117
118 /**
119 Return iterator to beginning of the vector.
120 */
121 const_iterator begin() const;
23324ae1 122
23324ae1
FM
123 /**
124 Return iterator to beginning of the vector.
125 */
f016d3b4 126 iterator begin();
23324ae1 127
946954d3
RR
128 /**
129 Return reverse iterator to end of the vector.
130 */
131 reverse_iterator rbegin();
e068310a 132
946954d3
RR
133 /**
134 Return reverse iterator to beginning of the vector.
135 */
136 reverse_iterator rend();
137
138
23324ae1 139 /**
0824e369 140 Returns vector's current capacity, i.e.\ how much memory is allocated.
3c4f71cc 141
f016d3b4 142 @see reserve()
23324ae1 143 */
328f5751 144 size_type capacity() const;
23324ae1
FM
145
146 /**
147 Clears the vector.
148 */
149 void clear();
150
151 /**
152 Returns @true if the vector is empty.
153 */
328f5751 154 bool empty() const;
23324ae1 155
23324ae1
FM
156 /**
157 Returns iterator to the end of the vector.
158 */
f016d3b4
VS
159 const_iterator end() const;
160
161 /**
162 Returns iterator to the end of the vector.
163 */
164 iterator end();
23324ae1 165
23324ae1 166 /**
f016d3b4
VS
167 Erase item pointed to by iterator @a it.
168
169 @return Iterator pointing to the item immediately after the erased one.
23324ae1
FM
170 */
171 iterator erase(iterator it);
f016d3b4
VS
172
173 /**
174 Erase items in the range @a first to @a last (@a last is not erased).
175
09ad05fa
BP
176 @return Iterator pointing to the item immediately after the erased
177 range.
f016d3b4 178 */
7c913512 179 iterator erase(iterator first, iterator last);
23324ae1 180
23324ae1 181 /**
f016d3b4 182 Returns the first item.
23324ae1 183 */
f016d3b4 184 const value_type& front() const;
23324ae1
FM
185
186 /**
f016d3b4 187 Returns the first item.
23324ae1 188 */
f016d3b4
VS
189 value_type& front();
190
191 /**
192 Insert item @a v at given position @a it.
193
194 @return Iterator for the inserted item.
195 */
196 iterator insert(iterator it, const value_type& v = value_type());
23324ae1
FM
197
198 /**
199 Assignment operator.
200 */
09ad05fa 201 wxVector& operator=(const wxVector& vb);
23324ae1 202
23324ae1 203 /**
09ad05fa 204 Returns item at position @a idx.
23324ae1 205 */
f016d3b4
VS
206 const value_type& operator[](size_type idx) const;
207
208 /**
09ad05fa 209 Returns item at position @a idx.
f016d3b4
VS
210 */
211 value_type& operator[](size_type idx);
23324ae1
FM
212
213 /**
214 Removes the last item.
215 */
216 void pop_back();
217
218 /**
219 Adds an item to the end of the vector.
220 */
221 void push_back(const value_type& v);
222
223 /**
f016d3b4
VS
224 Reserves memory for at least @a n items.
225
226 @see capacity()
23324ae1
FM
227 */
228 void reserve(size_type n);
09ad05fa 229
e068310a
VZ
230 /**
231 Makes the vector of size @a n.
232
233 If @a n is less than the current size(), the elements at the end of the
234 vector are erased. If it is greater, then the vector is completed with
235 either the copies of the given object @a v or @c value_type() objects
236 until it becomes of size @a n.
237 */
238 //@{
239 void resize(size_type n);
240 void resize(size_type n, const value_type& v);
241 //@}
242
09ad05fa
BP
243 /**
244 Returns the size of the vector.
245 */
246 size_type size() const;
888cb61e
VZ
247
248 /**
249 Efficiently exchanges contents of this vector with another one.
250
251 After the execution of this function the contents of this vector is
252 equal to the original contents of @a v and the contents of @a v becomes
253 the original contents of this vector without copying the data.
254
255 @since 2.9.1
256 */
257 void swap(wxVector& v);
23324ae1 258};
e54c96f1 259
38723be1
RD
260
261/**
262 Sort the contents of a @c wxVector<T>. In a STL build this function will
263 be defined as a thin wrapper around std::sort. To be sortable the
264 contained type must support the less-than operator.
265
266 @code
267 wxVector<SomeClass> v;
268 ... // items are added to the vector v...
269 wxVectorSort(v);
270 @endcode
888cb61e 271
38723be1
RD
272 @see wxVector<T>
273*/
274template<typename T>
275void wxVectorSort(wxVector<T>& v);