FreeWRL/FreeX3D  3.0.0
list.h
1 /*
2 
3  FreeWRL support library.
4  Linked lists.
5 
6 */
7 
8 /****************************************************************************
9  This file is part of the FreeWRL/FreeX3D Distribution.
10 
11  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12 
13  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14  it under the terms of the GNU Lesser Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25 ****************************************************************************/
26 
27 
28 #ifndef __LIBFREEWRL_LIST_H__
29 #define __LIBFREEWRL_LIST_H__
30 
31 
33 // LIST
35 /* singly linked */
36 
37 typedef struct _s_list_t {
38 
39  void *elem;
40  struct _s_list_t *next;
41 
42 } s_list_t;
43 
44 #define ml_elem(_item) (_item->elem)
45 #define ml_next(_item) (_item->next)
46 
47 typedef void f_free_t(void *ptr);
48 #if defined(DEBUG_MALLOC) && defined(DEBUG_MALLOC_LIST)
49 extern s_list_t* _ml_new(const void *elem, int line, char *fi);
50 #define ml_new(elem) _ml_new(elem,__LINE__,__FILE__)
51 #else
52 extern s_list_t* ml_new(const void *elem);
53 #endif
54 extern int ml_count(s_list_t *list);
55 extern s_list_t* ml_prev(s_list_t *list, s_list_t *item);
56 extern s_list_t* ml_last(s_list_t *list);
57 extern s_list_t* ml_find(s_list_t *list, s_list_t *item);
58 extern s_list_t* ml_find_elem(s_list_t *list, void *elem);
59 extern s_list_t* ml_insert(s_list_t *list, s_list_t *point, s_list_t *item);
60 extern s_list_t* ml_append(s_list_t *list, s_list_t *item);
61 extern void ml_delete(s_list_t *list, s_list_t *item);
62 extern s_list_t* ml_delete_self(s_list_t *list, s_list_t *item);
63 extern void ml_delete2(s_list_t *list, s_list_t *item, f_free_t f);
64 extern void ml_delete_all(s_list_t *list);
65 extern void ml_delete_all2(s_list_t *list, f_free_t f);
66 extern s_list_t* ml_get(s_list_t *list, int index);
67 extern void ml_enqueue(s_list_t **list, s_list_t *item);
68 extern s_list_t* ml_dequeue(s_list_t **list);
69 extern void ml_free(s_list_t *item);
70 
71 #define ml_foreach(_list,_action) {\
72  s_list_t *__l;\
73  s_list_t *next;\
74  for(__l=_list;__l!=NULL;) {\
75  next = ml_next(__l); /* we need to get next from __l before action deletes element */ \
76  _action;\
77  __l = next; \
78  }\
79  }
80 extern void ml_dump(s_list_t *list);
81 extern void ml_dump_char(s_list_t *list);
82 
83 
84 /* circlularly doubly linked */
85 typedef struct _cd_list_t {
86  void *elem;
87  struct _cd_list_t *next;
88  struct _cd_list_t *prev;
89 } cd_list_t;
90 
91 #define cdl_elem(_item) (_item->elem)
92 #define cdl_next(_item) (_item->next)
93 #define cdl_prev(_item) (_item->prev)
94 #define cdl_last(_head) (_head->prev)
95 
96 extern cd_list_t* cdl_new(const void *elem);
97 extern int cdl_count(cd_list_t *head);
98 extern cd_list_t* cdl_find(cd_list_t *head, cd_list_t *item);
99 extern cd_list_t* cdl_find_elem(cd_list_t *head, void *elem);
100 extern cd_list_t* cdl_insert(cd_list_t *head, cd_list_t *point, cd_list_t *item);
101 extern cd_list_t* cdl_append(cd_list_t *head, cd_list_t *item);
102 extern cd_list_t* cdl_delete(cd_list_t *head, cd_list_t *item);
103 extern cd_list_t* cdl_delete2(cd_list_t *head, cd_list_t *item, f_free_t f);
104 extern void cdl_delete_all(cd_list_t *head);
105 extern void cdl_delete_all2(cd_list_t *head, f_free_t f);
106 extern cd_list_t* cdl_get(cd_list_t *head, int index);
107 
108 #define cdl_foreach(_head,_action) {\
109  cd_list_t *__l;\
110  cd_list_t *next;\
111  __l=head;\
112  if(__l) do {\
113  next = cdl_next(__l); /* we need to get next from __l before action deletes element */ \
114  _action;\
115  __l = next; \
116  }while(__l != head);\
117  }
118 extern void cdl_dump(cd_list_t *list);
119 extern void cdl_dump_char(cd_list_t *list);
120 
121 
122 
123 #endif /* __LIBFREEWRL_LIST_H__ */
Definition: list.h:37