src/cx/list.h

changeset 494
6ce8cfa10a96
parent 490
e66551b47466
child 495
2856c74e18ba
equal deleted inserted replaced
493:e3469b497eff 494:6ce8cfa10a96
37 #ifndef UCX_LIST_H 37 #ifndef UCX_LIST_H
38 #define UCX_LIST_H 38 #define UCX_LIST_H
39 39
40 #include "common.h" 40 #include "common.h"
41 #include "allocator.h" 41 #include "allocator.h"
42 #include "iterator.h"
42 43
43 #ifdef __cplusplus 44 #ifdef __cplusplus
44 extern "C" { 45 extern "C" {
45 #endif 46 #endif
46 47
117 118
118 /** 119 /**
119 * Member function for reversing the order of the items. 120 * Member function for reversing the order of the items.
120 */ 121 */
121 void (*reverse)(cx_list_s *list); 122 void (*reverse)(cx_list_s *list);
123
124 /**
125 * Returns an iterator pointing to the specified index.
126 */
127 CxIterator (*iterator)(
128 cx_list_s const *list,
129 size_t index
130 );
122 } cx_list_class; 131 } cx_list_class;
123 132
124 /** 133 /**
125 * Structure for holding the base data of a list. 134 * Structure for holding the base data of a list.
126 */ 135 */
225 ) { 234 ) {
226 return list->cl->at(list, index); 235 return list->cl->at(list, index);
227 } 236 }
228 237
229 /** 238 /**
239 * Returns an iterator pointing to the item at the specified index.
240 *
241 * The returned iterator is position-aware.
242 *
243 * If the index is out of range, a past-the-end iterator will be returned.
244 *
245 * @param list the list
246 * @param index the index where the iterator shall point at
247 * @return a new iterator
248 */
249 static inline CxIterator cxListIterator(
250 CxList list,
251 size_t index
252 ) {
253 return list->cl->iterator(list, index);
254 }
255
256 /**
257 * Returns an iterator pointing to the first item of the list.
258 *
259 * The returned iterator is position-aware.
260 *
261 * If the list is empty, a past-the-end iterator will be returned.
262 *
263 * @param list the list
264 * @return a new iterator
265 */
266 static inline CxIterator cxListBegin(CxList list) {
267 return list->cl->iterator(list, 0);
268 }
269
270 /**
230 * Returns the index of the first element that equals \p elem. 271 * Returns the index of the first element that equals \p elem.
231 * 272 *
232 * Determining equality is performed by the list's comparator function. 273 * Determining equality is performed by the list's comparator function.
233 * 274 *
234 * @param list the list 275 * @param list the list

mercurial