|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: list declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 3 % |
|
20 */ |
|
21 |
|
22 #ifndef WLANLIST_H |
|
23 #define WLANLIST_H |
|
24 |
|
25 #include "osalist_iterator.h" |
|
26 |
|
27 /** |
|
28 * double linked list with limited STL interface |
|
29 * |
|
30 * |
|
31 * @lib wlanosa.lib |
|
32 * @since S60 v3.2 |
|
33 */ |
|
34 template<class T> |
|
35 class list : public DBase |
|
36 { |
|
37 |
|
38 typedef list<T> Self; |
|
39 |
|
40 public: |
|
41 |
|
42 struct Node : public DBase |
|
43 { |
|
44 |
|
45 /** |
|
46 * Constructor. |
|
47 * |
|
48 * @since S60 v3.2 |
|
49 */ |
|
50 explicit Node( const T& aElem ) |
|
51 : iElem( aElem ), iNext( NULL ), iPrev( NULL ) {}; |
|
52 |
|
53 /** |
|
54 * Destructor. |
|
55 * |
|
56 * @since S60 v3.2 |
|
57 */ |
|
58 virtual ~Node() {}; |
|
59 |
|
60 // Prohibit copy constructor. |
|
61 Node( const Node& ); |
|
62 // Prohibit assigment operator. |
|
63 Node& operator= ( const Node& ); |
|
64 |
|
65 T iElem; |
|
66 |
|
67 Node* iNext; |
|
68 Node* iPrev; |
|
69 }; |
|
70 |
|
71 friend class list_iterator<Node, T>; |
|
72 |
|
73 // type definitions |
|
74 typedef T value_type; |
|
75 typedef list_iterator<Node, T> iterator; |
|
76 typedef const list_iterator<Node, T> const_iterator; |
|
77 typedef T& reference; |
|
78 typedef const T& const_reference; |
|
79 typedef TInt size_type; |
|
80 |
|
81 /** |
|
82 * creates an empty list without any elements |
|
83 * |
|
84 * @since S60 v3.2 |
|
85 */ |
|
86 inline list() : iFirst( NULL ), iLast( NULL ), iNumOfElems( 0 ) {}; |
|
87 |
|
88 /** |
|
89 * destroys all elements and frees the memory |
|
90 * |
|
91 * @since S60 v3.2 |
|
92 */ |
|
93 inline virtual ~list(); |
|
94 |
|
95 /** |
|
96 * returns a bidirectional iterator for the first element |
|
97 * for empty ranges equals to end() |
|
98 * |
|
99 * @since S60 v3.2 |
|
100 * @return bidirectional iterator for the first element |
|
101 */ |
|
102 inline iterator begin(); |
|
103 |
|
104 /** |
|
105 * returns a const bidirectional iterator for the first element |
|
106 * for empty ranges equals to end() |
|
107 * |
|
108 * @since S60 v3.2 |
|
109 * @return const bidirectional iterator for the first element |
|
110 */ |
|
111 inline const_iterator begin() const; |
|
112 |
|
113 /** |
|
114 * returns a bidirectional iterator for the position after the last element |
|
115 * |
|
116 * @since S60 v3.2 |
|
117 * @return bidirectional iterator for the position after the last element |
|
118 */ |
|
119 inline iterator end(); |
|
120 |
|
121 /** |
|
122 * returns a const bidirectional iterator for |
|
123 * the position after the last element |
|
124 * |
|
125 * @since S60 v3.2 |
|
126 * @return a const bidirectional iterator |
|
127 * for the position after the last element |
|
128 */ |
|
129 inline const_iterator end() const; |
|
130 |
|
131 /** |
|
132 * returns the actual number of elements |
|
133 * |
|
134 * @since S60 v3.2 |
|
135 * @return the actual number of elements |
|
136 */ |
|
137 inline size_type size() const; |
|
138 |
|
139 /** |
|
140 * returns whether the container is empty |
|
141 * |
|
142 * @since S60 v3.2 |
|
143 * @return ETrue if the container is empty |
|
144 */ |
|
145 inline TBool empty() const; |
|
146 |
|
147 /** |
|
148 * returns reference to the first element |
|
149 * (no check wether the 1st element exists) |
|
150 * NOTE: if the container is empty the end result is undefined |
|
151 * |
|
152 * @since S60 v3.2 |
|
153 * @return reference to the first element |
|
154 */ |
|
155 inline reference front(); |
|
156 |
|
157 /** |
|
158 * returns const reference to the first element |
|
159 * (no check wether the 1st element exists) |
|
160 * NOTE: if the container is empty the end result is undefined |
|
161 * |
|
162 * @since S60 v3.2 |
|
163 * @return const reference to the first element |
|
164 */ |
|
165 inline const_reference front() const; |
|
166 |
|
167 /** |
|
168 * returns reference to the last element |
|
169 * (no check wether the last element exists) |
|
170 * NOTE: if the container is empty the end result is undefined |
|
171 * |
|
172 * @since S60 v3.2 |
|
173 * @return reference to the last element |
|
174 */ |
|
175 inline reference back(); |
|
176 |
|
177 /** |
|
178 * returns const reference to the last element |
|
179 * (no check wether the last element exists) |
|
180 * NOTE: if the container is empty the end result is undefined |
|
181 * |
|
182 * @since S60 v3.2 |
|
183 * @return const reference to the last element |
|
184 */ |
|
185 inline const_reference back() const; |
|
186 |
|
187 /** |
|
188 * removes all elements (makes container empty) |
|
189 * |
|
190 * @since S60 v3.2 |
|
191 */ |
|
192 inline void clear(); |
|
193 |
|
194 /** |
|
195 * appends a copy of aElem at the end |
|
196 * NOTE: either succeeds or has no effect, user must verify operation |
|
197 * success by comparing size before and after call |
|
198 * |
|
199 * @since S60 v3.2 |
|
200 * @param aElem element to be added |
|
201 */ |
|
202 inline void push_back( const_reference aElem ); |
|
203 |
|
204 /** |
|
205 * removes the last element (does not return it) |
|
206 * NOTE: if the container is empty the end result is undefined |
|
207 * |
|
208 * @since S60 v3.2 |
|
209 */ |
|
210 inline void pop_back(); |
|
211 |
|
212 /** |
|
213 * inserts a copy of elem at the beginning |
|
214 * NOTE: either succeeds or has no effect, user must verify operation |
|
215 * success by comparing size before and after call |
|
216 * |
|
217 * @since S60 v3.2 |
|
218 * @param aElem element to be added |
|
219 */ |
|
220 inline void push_front( const_reference aElem ); |
|
221 |
|
222 /** |
|
223 * removes the first element (does not return it) |
|
224 * NOTE: if the container is empty the end result is undefined |
|
225 * |
|
226 * @since S60 v3.2 |
|
227 */ |
|
228 inline void pop_front(); |
|
229 |
|
230 /** |
|
231 * inserts aElem before aPos |
|
232 * NOTE: aPos must be valid and != end() otherwise |
|
233 * the end result is undefined |
|
234 * NOTE: either succeeds or has no effect, user must verify operation |
|
235 * success by comparing size before and after call |
|
236 * |
|
237 * @since S60 v3.2 |
|
238 * @param aPos positon after the insertion of aElem |
|
239 * @param aElem element to be inserted |
|
240 * @return the position of the inserted element |
|
241 */ |
|
242 inline iterator insert( iterator aPos, const T& aElem ); |
|
243 |
|
244 /** |
|
245 * removes the element at position aPos |
|
246 * NOTE: aPos must be valid and != end() otherwise |
|
247 * the end result is undefined |
|
248 * |
|
249 * @since S60 v3.2 |
|
250 * @param aPos positon where elemt to be removed |
|
251 * @return the position of the next element or the end() |
|
252 * for empty sequence |
|
253 */ |
|
254 inline iterator erase( iterator aPos ); |
|
255 |
|
256 private: |
|
257 |
|
258 // deny assignement |
|
259 Self& operator=( const Self& aElem ); |
|
260 |
|
261 // deny copy |
|
262 list( const Self& aElem ); |
|
263 |
|
264 private: // data |
|
265 |
|
266 /** |
|
267 * first node |
|
268 * Own. |
|
269 */ |
|
270 Node* iFirst; |
|
271 |
|
272 /** |
|
273 * last node |
|
274 * Own. |
|
275 */ |
|
276 Node* iLast; |
|
277 |
|
278 /** |
|
279 * number of elements (nodes) |
|
280 */ |
|
281 TInt iNumOfElems; |
|
282 |
|
283 }; |
|
284 |
|
285 #include "osalist.inl" |
|
286 |
|
287 #endif // WLANLIST_H |