list.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * File : list.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #ifndef __RTGUI_LIST_H__
  15. #define __RTGUI_LIST_H__
  16. #include <rtgui/rtgui.h>
  17. struct rtgui_list_node
  18. {
  19. struct rtgui_list_node *next;
  20. };
  21. typedef struct rtgui_list_node rtgui_list_t;
  22. rt_inline void rtgui_list_init(rtgui_list_t *l)
  23. {
  24. l->next = (struct rtgui_list_node *)0;
  25. }
  26. rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n)
  27. {
  28. struct rtgui_list_node *node;
  29. node = l;
  30. while (node->next) node = node->next;
  31. /* append the node to the tail */
  32. node->next = n;
  33. n->next = (struct rtgui_list_node *) 0;
  34. }
  35. rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n)
  36. {
  37. n->next = l->next;
  38. l->next = n;
  39. }
  40. rt_inline rtgui_list_t *rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n)
  41. {
  42. /* remove slist head */
  43. struct rtgui_list_node *node = l;
  44. while (node->next && node->next != n) node = node->next;
  45. /* remove node */
  46. if (node->next != (rtgui_list_t *)0) node->next = node->next->next;
  47. return l;
  48. }
  49. #define rtgui_list_entry(node, type, member) \
  50. ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member)))
  51. #define rtgui_list_foreach(node, list) \
  52. for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next)
  53. #endif