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