PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/toolbox/list.h

http://github.com/koanlogic/libu
C Header | 65 lines | 27 code | 12 blank | 26 comment | 2 complexity | 1716c258951dc481f49c154ea510563d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Copyright (c) 2005-2012 by KoanLogic s.r.l. - All rights reserved.
  3. */
  4. #ifndef _U_LIST_H_
  5. #define _U_LIST_H_
  6. #include <u/libu_conf.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /* forward decl */
  11. struct u_list_s;
  12. /**
  13. * \addtogroup list
  14. * \{
  15. */
  16. /** \brief Basic list object type */
  17. typedef struct u_list_s u_list_t;
  18. /** \brief List iterator
  19. *
  20. * \param list an ::u_list_t object
  21. * \param n a variable that will get the current value from \p list
  22. * \param it an opaque iterator with type \c void**
  23. */
  24. #define u_list_foreach(list, n, it) \
  25. for(n = u_list_first(list, &it); n; n = u_list_next(list, &it))
  26. /** \brief List iterator with iteration counter
  27. *
  28. * \param list an ::u_list_t object
  29. * \param n a variable that will get the current value from \p list
  30. * \param it an opaque iterator with type \c void**
  31. * \param i variable of type \c integer that will be get the iteration
  32. * counter (0..i)
  33. */
  34. #define u_list_iforeach(list, n, it, i) \
  35. for(i = 0, n = u_list_first(list, &it); n; n = u_list_next(list, &it), ++i)
  36. int u_list_create (u_list_t **plist);
  37. void u_list_free (u_list_t *list);
  38. int u_list_clear (u_list_t *list);
  39. int u_list_add (u_list_t *list, void *ptr);
  40. int u_list_insert (u_list_t *list, void *ptr, size_t n);
  41. int u_list_del (u_list_t *list, void *ptr);
  42. int u_list_del_n (u_list_t *list, size_t n, void **pptr);
  43. void *u_list_get_n (u_list_t *list, size_t n);
  44. size_t u_list_count (u_list_t *list);
  45. void *u_list_first (u_list_t *list, void **it);
  46. void *u_list_next (u_list_t *list, void **it);
  47. /**
  48. * \}
  49. */
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* !_U_LIST_H_ */