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