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