Blender V4.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 98 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_DEL

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

Definition at line 133 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_DEL_EX

#define _BLI_SMALLSTACK_DEL_EX ( var_src,
var_dst )
Value:
(void)(_BLI_SMALLSTACK_FAKEUSER(var_src), \
_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))

Definition at line 125 of file BLI_linklist_stack.h.

◆ _BLI_SMALLSTACK_FAKEUSER

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

Definition at line 101 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_DECLARE

◆ BLI_LINKSTACK_FREE

◆ BLI_LINKSTACK_INIT

#define BLI_LINKSTACK_INIT ( var)

◆ BLI_LINKSTACK_POP

◆ BLI_LINKSTACK_POP_DEFAULT

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

Definition at line 59 of file BLI_linklist_stack.h.

◆ BLI_LINKSTACK_PUSH

◆ BLI_LINKSTACK_SIZE

◆ 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 62 of file BLI_linklist_stack.h.

Referenced by bm_face_region_pivot_edge_find(), bmesh_face_attribute_fill(), blender::ed::sculpt_paint::expand::delete_face_set_id(), blender::ed::sculpt_paint::geodesic::distances_create(), transform_convert_mesh_connectivity_distance(), and uv_set_connectivity_distance().

◆ 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++) \
{ \
*(void **)&(data)[i] = _##var##_iter->link; \
} \
} \
((void)0)
void * link

Definition at line 153 of file BLI_linklist_stack.h.

Referenced by bmesh_kernel_vert_separate().

◆ BLI_SMALLSTACK_DECLARE

◆ BLI_SMALLSTACK_IS_EMPTY

◆ 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 166 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_ITER_END

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

Definition at line 172 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 147 of file BLI_linklist_stack.h.

◆ BLI_SMALLSTACK_POP

◆ 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 141 of file BLI_linklist_stack.h.

Referenced by bm_face_split_by_edges(), and bm_face_split_edgenet_find_loop_walk().

◆ 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 107 of file BLI_linklist_stack.h.

Referenced by bm_face_split_by_edges(), bm_face_split_edge_find(), BM_face_split_edgenet_connect_islands(), bm_face_split_edgenet_find_connection(), bm_face_split_edgenet_find_loop_pair(), bm_face_split_edgenet_find_loop_walk(), bm_face_split_edgenet_partial_connect(), bm_mesh_loops_assign_normal_data(), bm_mesh_loops_calc_normals_for_loop(), bmesh_kernel_join_edge_kill_vert(), bmesh_kernel_join_vert_kill_edge(), bmesh_kernel_vert_separate(), edbm_average_normals_exec(), edbm_face_split_by_edges_exec(), normals_merge(), normals_split(), and uv_rip_pairs_from_loop().

◆ 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 177 of file BLI_linklist_stack.h.

Referenced by bm_face_split_by_edges(), bm_face_split_edgenet_find_loop_pair(), and bm_face_split_edgenet_find_loop_walk().