]> git.xonotic.org Git - xonotic/darkplaces.git/blob - com_list.h
Add qdefs.h and qstats.h to split up quakedef.h. Make a lot of headers standalone...
[xonotic/darkplaces.git] / com_list.h
1 /*
2 Copyright (C) 2020 David "Cloudwalk" Knapp
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 // com_list.c - generic doubly linked list interface, inspired by Linux list.h
22
23 #ifndef LIST_H
24 #define LIST_H
25
26 #include <stddef.h>
27 #include "qtypes.h"
28
29 typedef struct llist_s
30 {
31         struct llist_s *prev;
32         struct llist_s *next;
33 } llist_t;
34
35 #define List_Head_Reset(name) { &(name), &(name) }
36
37 #define List_Container(ptr, type, member) ContainerOf(ptr, type, member)
38
39 #define List_ForEach(pos, head) \
40         for (pos = (head)->next; pos != (head); pos = pos->next)
41
42 #define List_ForEach_Prev(pos, head) \
43         for (pos = (head)->prev; pos != (head); pos = pos->prev)
44
45 void List_Add(llist_t *node, llist_t *start);
46 void List_Add_Tail(llist_t *node, llist_t *start);
47 void List_Delete(llist_t *node);
48 void List_Delete_Init(llist_t *node);
49 void List_Replace(llist_t *old, llist_t *_new);
50 void List_Swap(llist_t *node1, llist_t *node2);
51 void List_Move(llist_t *list, llist_t *start);
52 void List_Move_Tail(llist_t *list, llist_t *start);
53 void List_Bulk_Move_Tail(llist_t *start, llist_t *first, llist_t *last);
54 void List_Rotate_Left(llist_t *head);
55 void List_Rotate_To_Front(llist_t *list, llist_t *head);
56 void List_Splice(const llist_t *list, llist_t *head);
57 void List_Splice_Tail(const llist_t *list, llist_t *head);
58 qbool List_IsFirst(llist_t *list, llist_t *start);
59 qbool List_IsLast(llist_t *list, llist_t *start);
60 qbool List_IsEmpty(const llist_t *list);
61
62 #endif