list.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * File : list.h
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-10-16 Bernard first version
  23. */
  24. #ifndef __RTGUI_LIST_H__
  25. #define __RTGUI_LIST_H__
  26. #include <rtgui/rtgui.h>
  27. struct rtgui_list_node
  28. {
  29. struct rtgui_list_node *next;
  30. };
  31. typedef struct rtgui_list_node rtgui_list_t;
  32. rt_inline void rtgui_list_init(rtgui_list_t *l)
  33. {
  34. l->next = (struct rtgui_list_node *)0;
  35. }
  36. rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n)
  37. {
  38. struct rtgui_list_node *node;
  39. node = l;
  40. while (node->next) node = node->next;
  41. /* append the node to the tail */
  42. node->next = n;
  43. n->next = (struct rtgui_list_node *) 0;
  44. }
  45. rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n)
  46. {
  47. n->next = l->next;
  48. l->next = n;
  49. }
  50. rt_inline rtgui_list_t *rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n)
  51. {
  52. /* remove slist head */
  53. struct rtgui_list_node *node = l;
  54. while (node->next && node->next != n) node = node->next;
  55. /* remove node */
  56. if (node->next != (rtgui_list_t *)0) node->next = node->next->next;
  57. return l;
  58. }
  59. #define rtgui_list_entry(node, type, member) \
  60. ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member)))
  61. #define rtgui_list_foreach(node, list) \
  62. for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next)
  63. #endif