Haka: include/haka/container/list.h Source File

Haka

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

list.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #ifndef HAKA_CONTAINER_LIST_H
6 #define HAKA_CONTAINER_LIST_H
7
8 #include <haka/compiler.h>
9 #include <stddef.h>
10
11
12 struct list {
13 struct list *prev;
14 struct list *next;
15 };
16
17 #define LIST_INIT {NULL, NULL}
18
19 #define list_getuserptr(l, offset) ((l) ? (void*)((char*)(l)-(offset)) : NULL)
20
21 #define list_init(a) { _list_init(&(a)->list); }
22 #define list_next(a) ((typeof(a))(list_getuserptr((a)->list.next, offsetof(typeof(*a), list))))
23 #define list_prev(a) ((typeof(a))(list_getuserptr((a)->list.prev, offsetof(typeof(*a), list))))
24 #define list_remove(a, h, t) _list_remove(&(a)->list, offsetof(typeof(*a), list), (void**)(h), (void**)(t))
25 #define list_insert_after(a, i, h, t) _list_insert_after(&(a)->list, (i) ? &(((typeof(a))(i))->list) : NULL, offsetof(typeof(*a), list), (void**)(h), (void**)(t))
26 #define list_insert_before(a, i, h, t) _list_insert_before(&(a)->list, (i) ? &(((typeof(a))(i))->list) : NULL, offsetof(typeof(*a), list), (void**)(h), (void**)(t))
27
28 void _list_init(struct list *l);
29 void _list_remove(struct list *l, int offset, void **head, void **tail);
30 void _list_insert_after(struct list *elem, struct list *l, int offset,
31 void **head, void **tail);
32 void _list_insert_before(struct list *elem, struct list *l, int offset,
33 void **head, void **tail);
34
35 #endif /* HAKA_CONTAINER_LIST_H */