]>
Commit | Line | Data |
---|---|---|
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 | 25 | template<typename T> |
7c913512 | 26 | class wxVector<T> |
23324ae1 FM |
27 | { |
28 | public: | |
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 | ||
946954d3 RR |
37 | /** |
38 | Reverse iterator interface | |
39 | */ | |
40 | class reverse_iterator | |
41 | { | |
42 | public: | |
43 | reverse_iterator(); | |
44 | explicit reverse_iterator(iterator it); | |
45 | reverse_iterator(const reverse_iterator& it); | |
46 | reference operator*() const; | |
47 | pointer operator->() const; | |
48 | iterator base() const; | |
49 | reverse_iterator& operator++(); | |
50 | reverse_iterator operator++(int); | |
51 | reverse_iterator& operator--(); | |
52 | reverse_iterator operator--(int); | |
53 | reverse_iterator operator+(difference_type n) const; | |
54 | reverse_iterator& operator+=(difference_type n); | |
55 | reverse_iterator operator-(difference_type n) const; | |
56 | reverse_iterator& operator-=(difference_type n); | |
57 | reference operator[](difference_type n) const; | |
58 | bool operator ==(const reverse_iterator& it) const; | |
59 | bool operator !=(const reverse_iterator& it) const; | |
60 | }; | |
61 | ||
23324ae1 FM |
62 | /** |
63 | Constructor. | |
64 | */ | |
f016d3b4 VS |
65 | wxVector(); |
66 | ||
664e5ff9 VZ |
67 | /** |
68 | Constructor initializing the vector with the given number of | |
69 | default-constructed objects. | |
70 | */ | |
71 | wxVector(size_type size); | |
72 | ||
73 | /** | |
74 | Constructor initializing the vector with the given number of | |
75 | copies of the given object. | |
76 | */ | |
77 | wxVector(size_type size, const value_type& value); | |
78 | ||
f016d3b4 | 79 | /** |
d13b34d3 | 80 | Copy constructor. |
f016d3b4 VS |
81 | */ |
82 | wxVector(const wxVector<T>& c); | |
23324ae1 FM |
83 | |
84 | /** | |
85 | Destructor. | |
86 | */ | |
f016d3b4 VS |
87 | ~wxVector(); |
88 | ||
89 | /** | |
09ad05fa | 90 | Returns item at position @a idx. |
f016d3b4 VS |
91 | */ |
92 | const value_type& at(size_type idx) const; | |
23324ae1 | 93 | |
23324ae1 | 94 | /** |
09ad05fa | 95 | Returns item at position @a idx. |
23324ae1 | 96 | */ |
f016d3b4 | 97 | value_type& at(size_type idx); |
23324ae1 | 98 | |
23324ae1 | 99 | /** |
f016d3b4 | 100 | Return the last item. |
23324ae1 | 101 | */ |
f016d3b4 VS |
102 | const value_type& back() const; |
103 | ||
104 | /** | |
105 | Return the last item. | |
106 | */ | |
107 | value_type& back(); | |
108 | ||
109 | /** | |
110 | Return iterator to beginning of the vector. | |
111 | */ | |
112 | const_iterator begin() const; | |
23324ae1 | 113 | |
23324ae1 FM |
114 | /** |
115 | Return iterator to beginning of the vector. | |
116 | */ | |
f016d3b4 | 117 | iterator begin(); |
23324ae1 | 118 | |
946954d3 RR |
119 | /** |
120 | Return reverse iterator to end of the vector. | |
121 | */ | |
122 | reverse_iterator rbegin(); | |
e068310a | 123 | |
946954d3 RR |
124 | /** |
125 | Return reverse iterator to beginning of the vector. | |
126 | */ | |
127 | reverse_iterator rend(); | |
128 | ||
129 | ||
23324ae1 | 130 | /** |
f016d3b4 | 131 | Returns vector's current capacity, i.e. how much memory is allocated. |
3c4f71cc | 132 | |
f016d3b4 | 133 | @see reserve() |
23324ae1 | 134 | */ |
328f5751 | 135 | size_type capacity() const; |
23324ae1 FM |
136 | |
137 | /** | |
138 | Clears the vector. | |
139 | */ | |
140 | void clear(); | |
141 | ||
142 | /** | |
143 | Returns @true if the vector is empty. | |
144 | */ | |
328f5751 | 145 | bool empty() const; |
23324ae1 | 146 | |
23324ae1 FM |
147 | /** |
148 | Returns iterator to the end of the vector. | |
149 | */ | |
f016d3b4 VS |
150 | const_iterator end() const; |
151 | ||
152 | /** | |
153 | Returns iterator to the end of the vector. | |
154 | */ | |
155 | iterator end(); | |
23324ae1 | 156 | |
23324ae1 | 157 | /** |
f016d3b4 VS |
158 | Erase item pointed to by iterator @a it. |
159 | ||
160 | @return Iterator pointing to the item immediately after the erased one. | |
23324ae1 FM |
161 | */ |
162 | iterator erase(iterator it); | |
f016d3b4 VS |
163 | |
164 | /** | |
165 | Erase items in the range @a first to @a last (@a last is not erased). | |
166 | ||
09ad05fa BP |
167 | @return Iterator pointing to the item immediately after the erased |
168 | range. | |
f016d3b4 | 169 | */ |
7c913512 | 170 | iterator erase(iterator first, iterator last); |
23324ae1 | 171 | |
23324ae1 | 172 | /** |
f016d3b4 | 173 | Returns the first item. |
23324ae1 | 174 | */ |
f016d3b4 | 175 | const value_type& front() const; |
23324ae1 FM |
176 | |
177 | /** | |
f016d3b4 | 178 | Returns the first item. |
23324ae1 | 179 | */ |
f016d3b4 VS |
180 | value_type& front(); |
181 | ||
182 | /** | |
183 | Insert item @a v at given position @a it. | |
184 | ||
185 | @return Iterator for the inserted item. | |
186 | */ | |
187 | iterator insert(iterator it, const value_type& v = value_type()); | |
23324ae1 FM |
188 | |
189 | /** | |
190 | Assignment operator. | |
191 | */ | |
09ad05fa | 192 | wxVector& operator=(const wxVector& vb); |
23324ae1 | 193 | |
23324ae1 | 194 | /** |
09ad05fa | 195 | Returns item at position @a idx. |
23324ae1 | 196 | */ |
f016d3b4 VS |
197 | const value_type& operator[](size_type idx) const; |
198 | ||
199 | /** | |
09ad05fa | 200 | Returns item at position @a idx. |
f016d3b4 VS |
201 | */ |
202 | value_type& operator[](size_type idx); | |
23324ae1 FM |
203 | |
204 | /** | |
205 | Removes the last item. | |
206 | */ | |
207 | void pop_back(); | |
208 | ||
209 | /** | |
210 | Adds an item to the end of the vector. | |
211 | */ | |
212 | void push_back(const value_type& v); | |
213 | ||
214 | /** | |
f016d3b4 VS |
215 | Reserves memory for at least @a n items. |
216 | ||
217 | @see capacity() | |
23324ae1 FM |
218 | */ |
219 | void reserve(size_type n); | |
09ad05fa | 220 | |
e068310a VZ |
221 | /** |
222 | Makes the vector of size @a n. | |
223 | ||
224 | If @a n is less than the current size(), the elements at the end of the | |
225 | vector are erased. If it is greater, then the vector is completed with | |
226 | either the copies of the given object @a v or @c value_type() objects | |
227 | until it becomes of size @a n. | |
228 | */ | |
229 | //@{ | |
230 | void resize(size_type n); | |
231 | void resize(size_type n, const value_type& v); | |
232 | //@} | |
233 | ||
09ad05fa BP |
234 | /** |
235 | Returns the size of the vector. | |
236 | */ | |
237 | size_type size() const; | |
888cb61e VZ |
238 | |
239 | /** | |
240 | Efficiently exchanges contents of this vector with another one. | |
241 | ||
242 | After the execution of this function the contents of this vector is | |
243 | equal to the original contents of @a v and the contents of @a v becomes | |
244 | the original contents of this vector without copying the data. | |
245 | ||
246 | @since 2.9.1 | |
247 | */ | |
248 | void swap(wxVector& v); | |
23324ae1 | 249 | }; |
e54c96f1 | 250 | |
38723be1 RD |
251 | |
252 | /** | |
253 | Sort the contents of a @c wxVector<T>. In a STL build this function will | |
254 | be defined as a thin wrapper around std::sort. To be sortable the | |
255 | contained type must support the less-than operator. | |
256 | ||
257 | @code | |
258 | wxVector<SomeClass> v; | |
259 | ... // items are added to the vector v... | |
260 | wxVectorSort(v); | |
261 | @endcode | |
888cb61e | 262 | |
38723be1 RD |
263 | @see wxVector<T> |
264 | */ | |
265 | template<typename T> | |
266 | void wxVectorSort(wxVector<T>& v); |