Changes in uspace/lib/c/include/adt/list.h [07525cd:062d900] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/list.h
r07525cd r062d900 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 201 3Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 65 65 66 66 #define list_get_instance(link, type, member) \ 67 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 68 69 #define list_foreach(list, member, itype, iterator) \ 70 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 71 for (link_t *_link = (list).head.next; \ 72 iterator = list_get_instance(_link, itype, member), \ 73 _link != &(list).head; _link = _link->next) 67 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 68 69 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 74 72 75 73 /** Unlike list_foreach(), allows removing items while traversing a list. 76 * 74 * 77 75 * @code 78 76 * list_t mylist; … … 240 238 static inline link_t *list_last(list_t *list) 241 239 { 242 return (list->head.prev == &list->head) ? NULL : list->head.prev; 243 } 244 245 /** Get next item in list. 246 * 247 * @param link Current item link 248 * @param list List containing @a link 249 * 250 * @return Next item or NULL if @a link is the last item. 251 * 252 */ 253 static inline link_t *list_next(link_t *link, const list_t *list) 254 { 255 return (link->next == &list->head) ? NULL : link->next; 256 } 257 258 /** Get previous item in list. 259 * 260 * @param link Current item link 261 * @param list List containing @a link 262 * 263 * @return Previous item or NULL if @a link is the first item. 264 * 265 */ 266 static inline link_t *list_prev(link_t *link, const list_t *list) 267 { 268 return (link->prev == &list->head) ? NULL : link->prev; 240 return ((list->head.prev == &list->head) ? NULL : list->head.prev); 269 241 } 270 242 … … 336 308 unsigned int cnt = 0; 337 309 338 link_t *link = list_first(list); 339 while (link != NULL) { 310 list_foreach(*list, link) { 340 311 if (cnt == n) 341 312 return link; 342 313 343 314 cnt++; 344 link = list_next(link, list);345 315 } 346 316 347 317 return NULL; 348 }349 350 /** Verify that argument type is a pointer to link_t (at compile time).351 *352 * This can be used to check argument type in a macro.353 */354 static inline const void *list_link_to_void(const link_t *link)355 {356 return link;357 318 } 358 319
Note:
See TracChangeset
for help on using the changeset viewer.