Blender V4.3
BLI_link_utils.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
15#define BLI_LINKS_PREPEND(list, link) \
16 { \
17 CHECK_TYPE_PAIR(list, link); \
18 (link)->next = list; \
19 list = link; \
20 } \
21 (void)0
22
23/* Use for append (single linked list, storing the last element). */
24#define BLI_LINKS_APPEND(list, link) \
25 { \
26 (link)->next = NULL; \
27 if ((list)->first) { \
28 (list)->last->next = link; \
29 } \
30 else { \
31 (list)->first = link; \
32 } \
33 (list)->last = link; \
34 } \
35 (void)0
36
37/* Use for inserting after a certain element. */
38#define BLI_LINKS_INSERT_AFTER(list, node, link) \
39 { \
40 if ((node)->next == NULL) { \
41 (list)->last = link; \
42 } \
43 (link)->next = (node)->next; \
44 (node)->next = link; \
45 } \
46 (void)0
47
48#define BLI_LINKS_FREE(list) \
49 { \
50 while (list) { \
51 void *next = (list)->next; \
52 MEM_freeN(list); \
53 list = next; \
54 } \
55 } \
56 (void)0