| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
Ü |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#ifndef _USUAL_STATLIST_H_ |
| 29 |
#define _USUAL_STATLIST_H_ |
| 30 |
|
| 31 |
#include <usual/list.h> |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
struct StatList { |
| 37 |
|
| 38 |
struct List head; |
| 39 |
|
| 40 |
int cur_count; |
| 41 |
#ifdef LIST_DEBUG |
| 42 |
|
| 43 |
const char *name; |
| 44 |
#endif |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
#ifdef LIST_DEBUG |
| 49 |
#define STATLIST(var) struct StatList var = { {&var.head, &var.head}, 0, #var } |
| 50 |
#else |
| 51 |
#define STATLIST(var) struct StatList var = { {&var.head, &var.head}, 0 } |
| 52 |
#endif |
| 53 |
|
| 54 |
|
| 55 |
static inline void statlist_prepend(struct StatList *list, struct List *item) |
| 56 |
{ |
| 57 |
list_prepend(&list->head, item); |
| 58 |
list->cur_count++; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
static inline void statlist_append(struct StatList *list, struct List *item) |
| 63 |
{ |
| 64 |
list_append(&list->head, item); |
| 65 |
list->cur_count++; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
static inline void statlist_remove(struct StatList *list, struct List *item) |
| 70 |
{ |
| 71 |
list_del(item); |
| 72 |
list->cur_count--; |
| 73 |
|
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
static inline void statlist_init(struct StatList *list, const char *name) |
| 79 |
{ |
| 80 |
list_init(&list->head); |
| 81 |
list->cur_count = 0; |
| 82 |
#ifdef LIST_DEBUG |
| 83 |
list->name = name; |
| 84 |
#endif |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
static inline int statlist_count(const struct StatList *list) |
| 89 |
{ |
| 90 |
|
| 91 |
return list->cur_count; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
static inline struct List *statlist_pop(struct StatList *list) |
| 96 |
{ |
| 97 |
struct List *item = list_pop(&list->head); |
| 98 |
|
| 99 |
if (item) |
| 100 |
list->cur_count--; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
return item; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
static inline struct List *statlist_first(const struct StatList *list) |
| 109 |
{ |
| 110 |
return list_first(&list->head); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
static inline struct List *statlist_last(const struct StatList *list) |
| 115 |
{ |
| 116 |
return list_last(&list->head); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
static inline bool statlist_empty(const struct StatList *list) |
| 121 |
{ |
| 122 |
return list_empty(&list->head); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
#define statlist_for_each(item, list) list_for_each(item, &((list)->head)) |
| 127 |
|
| 128 |
|
| 129 |
#define statlist_for_each_reverse(item, list) list_for_each_reverse(item, &((list)->head)) |
| 130 |
|
| 131 |
|
| 132 |
#define statlist_for_each_safe(item, list, tmp) list_for_each_safe(item, &((list)->head), tmp) |
| 133 |
|
| 134 |
|
| 135 |
#define statlist_for_each_reverse_safe(item, list, tmp) list_for_each_reverse_safe(item, &((list)->head), tmp) |
| 136 |
|
| 137 |
|
| 138 |
static inline void statlist_put_before(struct StatList *list, struct List *item, struct List *pos) |
| 139 |
{ |
| 140 |
list_append(pos, item); |
| 141 |
list->cur_count++; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
static inline void statlist_put_after(struct StatList *list, struct List *item, struct List *pos) |
| 146 |
{ |
| 147 |
list_prepend(pos, item); |
| 148 |
list->cur_count++; |
| 149 |
} |
| 150 |
|
| 151 |
#endif |