Blender  V3.3
BLI_linklist_stack.h File Reference

BLI_LINKSTACK_*** wrapper macros for using a LinkNode to store a stack of pointers, using a single linked list allocated from a mempool. More...

#include "BLI_linklist.h"
#include "BLI_mempool.h"

Go to the source code of this file.

Macros

Linked Stack (mempool)

Uses BLI_mempool for storage.

#define BLI_LINKSTACK_DECLARE(var, type)
 
#define BLI_LINKSTACK_INIT(var)
 
#define BLI_LINKSTACK_SIZE(var)   BLI_mempool_len(var##_pool_)
 
#define BLI_LINKSTACK_PUSH(var, ptr)   (BLI_linklist_prepend_pool(&(var), ptr, var##_pool_))
 
#define BLI_LINKSTACK_POP(var)   (var ? BLI_linklist_pop_pool(&(var), var##_pool_) : NULL)
 
#define BLI_LINKSTACK_POP_DEFAULT(var, r)   (var ? BLI_linklist_pop_pool(&(var), var##_pool_) : r)
 
#define BLI_LINKSTACK_SWAP(var_a, var_b)
 
#define BLI_LINKSTACK_FREE(var)
 
Linked Stack (alloca)

Linked Stack, using stack memory (alloca).

alloca never frees, pop'd items are stored in a free-list for reuse. only use for lists small enough to fit on the stack.

#define _BLI_SMALLSTACK_CAST(var)
 
#define _BLI_SMALLSTACK_FAKEUSER(var)   (void)(&(_##var##_type))
 
#define BLI_SMALLSTACK_DECLARE(var, type)
 
#define BLI_SMALLSTACK_PUSH(var, data)
 
#define _BLI_SMALLSTACK_DEL_EX(var_src, var_dst)
 
#define _BLI_SMALLSTACK_DEL(var)   _BLI_SMALLSTACK_DEL_EX(var, var)
 
#define BLI_SMALLSTACK_POP(var)
 
#define BLI_SMALLSTACK_POP_EX(var_src, var_dst)
 
#define BLI_SMALLSTACK_PEEK(var)    (_BLI_SMALLSTACK_CAST(var)((_##var##_stack) ? _##var##_stack->link : NULL))
 
#define BLI_SMALLSTACK_IS_EMPTY(var)   ((_BLI_SMALLSTACK_CAST(var) _##var##_stack) == NULL)
 
#define BLI_SMALLSTACK_AS_TABLE(var, data)
 
#define BLI_SMALLSTACK_ITER_BEGIN(var, item)
 
#define BLI_SMALLSTACK_ITER_END
 
#define BLI_SMALLSTACK_SWAP(var_a, var_b)
 

Detailed Description

BLI_LINKSTACK_*** wrapper macros for using a LinkNode to store a stack of pointers, using a single linked list allocated from a mempool.

Note
These macros follow STACK_* macros defined in 'BLI_utildefines.h' and should be kept (mostly) interchangeable.
_##var##_type is a dummy variable only used for type-checks.

Definition in file BLI_linklist_stack.h.

Macro Definition Documentation

◆ _BLI_SMALLSTACK_CAST

#define _BLI_SMALLSTACK_CAST (   var)

Definition at line 89 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_DEL

#define _BLI_SMALLSTACK_DEL (   var)    _BLI_SMALLSTACK_DEL_EX(var, var)

Definition at line 124 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_DEL_EX

#define _BLI_SMALLSTACK_DEL_EX (   var_src,
  var_dst 
)
Value:
_BLI_SMALLSTACK_FAKEUSER(var_dst), \
(_##var_src##_temp = _##var_src##_stack->next), \
(_##var_src##_stack->next = _##var_dst##_free), \
(_##var_dst##_free = _##var_src##_stack), \
(_##var_src##_stack = _##var_src##_temp))
SyclQueue void void size_t num_bytes void

Definition at line 116 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_FAKEUSER

#define _BLI_SMALLSTACK_FAKEUSER (   var)    (void)(&(_##var##_type))

Definition at line 92 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_DECLARE

#define BLI_LINKSTACK_DECLARE (   var,
  type 
)
Value:
LinkNode *var; \
BLI_mempool *var##_pool_; \
type var##_type_

Definition at line 24 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_FREE

#define BLI_LINKSTACK_FREE (   var)
Value:
{ \
BLI_mempool_destroy(var##_pool_); \
var##_pool_ = NULL; \
(void)var##_pool_; \
var = NULL; \
(void)var; \
(void)&(var##_type_); \
} \
(void)0

Definition at line 61 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_INIT

#define BLI_LINKSTACK_INIT (   var)
Value:
{ \
var = NULL; \
var##_pool_ = BLI_mempool_create(sizeof(LinkNode), 0, 64, BLI_MEMPOOL_NOP); \
} \
(void)0
@ BLI_MEMPOOL_NOP
Definition: BLI_mempool.h:99
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition: BLI_mempool.c:253

Definition at line 29 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_POP

#define BLI_LINKSTACK_POP (   var)    (var ? BLI_linklist_pop_pool(&(var), var##_pool_) : NULL)

Definition at line 49 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_POP_DEFAULT

#define BLI_LINKSTACK_POP_DEFAULT (   var,
  r 
)    (var ? BLI_linklist_pop_pool(&(var), var##_pool_) : r)

Definition at line 50 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_PUSH

#define BLI_LINKSTACK_PUSH (   var,
  ptr 
)    (BLI_linklist_prepend_pool(&(var), ptr, var##_pool_))

Definition at line 48 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_SIZE

#define BLI_LINKSTACK_SIZE (   var)    BLI_mempool_len(var##_pool_)

Definition at line 36 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_SWAP

#define BLI_LINKSTACK_SWAP (   var_a,
  var_b 
)
Value:
{ \
CHECK_TYPE_PAIR(var_a##_type_, var_b##_type_); \
SWAP(LinkNode *, var_a, var_b); \
SWAP(BLI_mempool *, var_a##_pool_, var_b##_pool_); \
} \
(void)0

Definition at line 53 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_AS_TABLE

#define BLI_SMALLSTACK_AS_TABLE (   var,
  data 
)
Value:
{ \
LinkNode *_##var##_iter; \
unsigned int i; \
for (_##var##_iter = _##var##_stack, i = 0; _##var##_iter; \
_##var##_iter = _##var##_iter->next, i++) { \
(data)[i] = _BLI_SMALLSTACK_CAST(var)(_##var##_iter->link); \
} \
} \
((void)0)

Definition at line 144 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_DECLARE

#define BLI_SMALLSTACK_DECLARE (   var,
  type 
)
Value:
LinkNode *_##var##_stack = NULL, *_##var##_free = NULL, *_##var##_temp = NULL; \
type _##var##_type

Definition at line 94 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_IS_EMPTY

#define BLI_SMALLSTACK_IS_EMPTY (   var)    ((_BLI_SMALLSTACK_CAST(var) _##var##_stack) == NULL)

Definition at line 141 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_ITER_BEGIN

#define BLI_SMALLSTACK_ITER_BEGIN (   var,
  item 
)
Value:
{ \
LinkNode *_##var##_iter; \
for (_##var##_iter = _##var##_stack; _##var##_iter; _##var##_iter = _##var##_iter->next) { \
item = _BLI_SMALLSTACK_CAST(var)(_##var##_iter->link);

Definition at line 156 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_ITER_END

#define BLI_SMALLSTACK_ITER_END
Value:
} \
} \
(void)0

Definition at line 162 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_PEEK

#define BLI_SMALLSTACK_PEEK (   var)     (_BLI_SMALLSTACK_CAST(var)((_##var##_stack) ? _##var##_stack->link : NULL))

Definition at line 138 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_POP

#define BLI_SMALLSTACK_POP (   var)
Value:
(_##var##_stack) ? (_BLI_SMALLSTACK_DEL(var), (_##var##_free->link)) : NULL))

Definition at line 127 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_POP_EX

#define BLI_SMALLSTACK_POP_EX (   var_src,
  var_dst 
)
Value:
(_BLI_SMALLSTACK_CAST(var_src)( \
(_##var_src##_stack) ? \
(_BLI_SMALLSTACK_DEL_EX(var_src, var_dst), (_##var_dst##_free->link)) : \
NULL))

Definition at line 132 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_PUSH

#define BLI_SMALLSTACK_PUSH (   var,
  data 
)
Value:
{ \
CHECK_TYPE_PAIR(data, _##var##_type); \
if (_##var##_free) { \
_##var##_temp = _##var##_free; \
_##var##_free = _##var##_free->next; \
} \
else { \
_##var##_temp = (LinkNode *)alloca(sizeof(LinkNode)); \
} \
_##var##_temp->next = _##var##_stack; \
_##var##_temp->link = data; \
_##var##_stack = _##var##_temp; \
_BLI_SMALLSTACK_FAKEUSER(var); \
} \
(void)0

Definition at line 98 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_SWAP

#define BLI_SMALLSTACK_SWAP (   var_a,
  var_b 
)
Value:
{ \
CHECK_TYPE_PAIR(_##var_a##_type, _##var_b##_type); \
SWAP(LinkNode *, _##var_a##_stack, _##var_b##_stack); \
SWAP(LinkNode *, _##var_a##_free, _##var_b##_free); \
} \
(void)0

Definition at line 167 of file BLI_linklist_stack.h.