1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Linked list API declarations
12 * Copyright (c) 2007 Michael Sevakis
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #ifndef MPEG_LINKEDLIST_H
24 #define MPEG_LINKEDLIST_H
28 struct list_item
*prev
; /* previous item in list */
29 struct list_item
*next
; /* next item in list */
32 /* Utility macros to help get the actual structure pointer back */
33 #define OFFSETOF(type, membername) ((off_t)&((type *)0)->membername)
34 #define TYPE_FROM_MEMBER(type, memberptr, membername) \
35 ((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername)))
37 /* Initialize a master list head */
38 void list_initialize(struct list_item
*master_list_head
);
40 /* Are there items after the head item? */
41 bool list_is_empty(struct list_item
*head_item
);
43 /* Does the item belong to a list? */
44 bool list_is_item_listed(struct list_item
*item
);
46 /* Is the item a member in a particular list? */
47 bool list_is_member(struct list_item
*master_list_head
,
48 struct list_item
*item
);
50 /* Remove an item from a list - no head item needed */
51 void list_remove_item(struct list_item
*item
);
53 /* Add a list item after the base item */
54 void list_add_item(struct list_item
*head_item
,
55 struct list_item
*item
);
57 /* Clear list items after the head item */
58 void list_clear_all(struct list_item
*head_item
);
60 /* Enumerate all items after the head item - passing each item in turn
61 * to the callback as well as the data value. The current item may be
62 * safely removed. Items added after the current position will be enumated
63 * but not ones added before it. The callback may return false to stop
65 typedef bool (*list_enum_callback_t
)(struct list_item
*item
, intptr_t data
);
67 void list_enum_items(struct list_item
*head_item
,
68 list_enum_callback_t callback
,
71 #endif /* MPEG_LINKEDLIST_H */