]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/ul_list.h
New ORTE version 0.3.0 committed
[orte.git] / orte / include / ul_list.h
1 #ifndef _UL_LISTS_H
2 #define _UL_LISTS_H
3
4 #include "ul_utdefs.h"
5 #include "ul_listbase.h"
6 #include "ul_itbase.h"
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 typedef struct list_head ul_list_node_t;
13 typedef struct list_head ul_list_head_t;
14
15 #define UL_LIST_CUST_DEC(cust_prefix, cust_head_t, cust_item_t,\
16                 cust_head_field, cust_node_field) \
17 \
18 static inline cust_item_t * \
19 cust_prefix##_node2item(const cust_head_t *head, const ul_list_node_t *node) \
20   {return UL_CONTAINEROF(node, cust_item_t, cust_node_field);}\
21 \
22 static inline void \
23 cust_prefix##_init_head(cust_head_t *head)\
24 {\
25   INIT_LIST_HEAD(&head->cust_head_field);\
26 }\
27 static inline cust_item_t *\
28 cust_prefix##_first(const cust_head_t *head)\
29 {\
30   ul_list_node_t *n=head->cust_head_field.next;\
31   return (n!=&head->cust_head_field)?cust_prefix##_node2item(head,n):NULL;\
32 }\
33 static inline cust_item_t *\
34 cust_prefix##_last(const cust_head_t *head)\
35 {\
36   ul_list_node_t *n=head->cust_head_field.prev;\
37   return (n!=&head->cust_head_field)?cust_prefix##_node2item(head,n):NULL;\
38 }\
39 static inline cust_item_t *\
40 cust_prefix##_next(const cust_head_t *head, const cust_item_t *item)\
41 {\
42   ul_list_node_t *n=item->cust_node_field.next;\
43   return (n!=&head->cust_head_field)?cust_prefix##_node2item(head,n):NULL;\
44 }\
45 static inline cust_item_t *\
46 cust_prefix##_prev(const cust_head_t *head, const cust_item_t *item)\
47 {\
48   ul_list_node_t *n=item->cust_node_field.prev;\
49   return (n!=&head->cust_head_field)?cust_prefix##_node2item(head,n):NULL;\
50 }\
51 static inline int \
52 cust_prefix##_is_empty(const cust_head_t *head)\
53 {\
54   return head->cust_head_field.next==&head->cust_head_field;\
55 }\
56 static inline void \
57 cust_prefix##_ins_head(cust_head_t *head, cust_item_t *item)\
58 {\
59   list_add(&item->cust_node_field, &head->cust_head_field);\
60 }\
61 static inline void \
62 cust_prefix##_ins_tail(cust_head_t *head, cust_item_t *item)\
63 {\
64   list_add_tail(&item->cust_node_field, &head->cust_head_field);\
65 }\
66 static inline void \
67 cust_prefix##_insert(cust_head_t *head, cust_item_t *item)\
68 {\
69   cust_prefix##_ins_tail(head, item);\
70 }\
71 static inline void \
72 cust_prefix##_delete(cust_head_t *head, cust_item_t *item)\
73 {\
74   list_del(&item->cust_node_field);\
75 }\
76 static inline void \
77 cust_prefix##_del_item(cust_item_t *item)\
78 {\
79   list_del(&item->cust_node_field);\
80 }\
81 static inline cust_item_t *\
82 cust_prefix##_cut_first(cust_head_t *head)\
83 {\
84   ul_list_node_t *n=head->cust_head_field.next;\
85   if(n==&head->cust_head_field) return NULL;\
86   list_del(n);\
87   return cust_prefix##_node2item(head,n);\
88 }\
89 /*** Iterators ***/\
90 UL_ITBASE_UL_DEC(cust_prefix, cust_head_t, cust_item_t)
91
92
93 #define ul_list_for_each(cust_prefix, head, ptr) \
94         for(ptr=cust_prefix##_first(head);ptr;ptr=cust_prefix##_next((head),ptr))
95
96 #define ul_list_for_each_rev(cust_prefix, head, ptr) \
97         for(ptr=cust_prefix##_last(head);ptr;ptr=cust_prefix##_prev((head),ptr))
98
99 #define ul_list_for_each_cut(cust_prefix, head, ptr) \
100         for(;(ptr=cust_prefix##_cut_first(head));)
101
102 #ifdef __cplusplus
103 } /* extern "C"*/
104 #endif
105
106 #endif /* _UL_LISTS_H */