Blender V4.3
BLI_utildefines_stack.h File Reference

Go to the source code of this file.

Macros

#define STACK_DECLARE(stack)   unsigned int _##stack##_index, _##stack##_num_alloc
 
#define STACK_INIT(stack, stack_num)
 
#define _STACK_SIZETEST(stack, off)    (BLI_assert((_##stack##_index) + (off) <= _##stack##_num_alloc))
 
#define _STACK_SWAP_TOTALLOC(stack_a, stack_b)    SWAP(unsigned int, _##stack_a##_num_alloc, _##stack_b##_num_alloc)
 
#define _STACK_BOUNDSTEST(stack, index)    ((void)stack, BLI_assert((unsigned int)(index) < _##stack##_index))
 
#define STACK_SIZE(stack)   ((void)stack, (_##stack##_index))
 
#define STACK_CLEAR(stack)
 
#define STACK_PUSH(stack, val)    ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++] = (val)))
 
#define STACK_PUSH_RET(stack)    ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++]))
 
#define STACK_PUSH_RET_PTR(stack)    ((void)stack, _STACK_SIZETEST(stack, 1), &((stack)[(_##stack##_index)++]))
 
#define STACK_POP(stack)   ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : NULL)
 
#define STACK_POP_PTR(stack)   ((_##stack##_index) ? &((stack)[--(_##stack##_index)]) : NULL)
 
#define STACK_POP_DEFAULT(stack, r)   ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : (r))
 
#define STACK_PEEK(stack)   (BLI_assert(_##stack##_index), ((stack)[_##stack##_index - 1]))
 
#define STACK_PEEK_PTR(stack)   (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1]))
 
#define STACK_REMOVE(stack, i)
 
#define STACK_DISCARD(stack, n)
 
#define STACK_SWAP(stack_a, stack_b)
 

Detailed Description

Macro's for a simple array based stack

Note
Caller handles alloc & free.

Definition in file BLI_utildefines_stack.h.

Macro Definition Documentation

◆ _STACK_BOUNDSTEST

#define _STACK_BOUNDSTEST ( stack,
index )    ((void)stack, BLI_assert((unsigned int)(index) < _##stack##_index))

Definition at line 32 of file BLI_utildefines_stack.h.

◆ _STACK_SIZETEST

#define _STACK_SIZETEST ( stack,
off )    (BLI_assert((_##stack##_index) + (off) <= _##stack##_num_alloc))

Definition at line 21 of file BLI_utildefines_stack.h.

◆ _STACK_SWAP_TOTALLOC

#define _STACK_SWAP_TOTALLOC ( stack_a,
stack_b )    SWAP(unsigned int, _##stack_a##_num_alloc, _##stack_b##_num_alloc)

Definition at line 23 of file BLI_utildefines_stack.h.

◆ STACK_CLEAR

#define STACK_CLEAR ( stack)
Value:
{ \
(void)stack; \
_##stack##_index = 0; \
} \
((void)0)

Definition at line 36 of file BLI_utildefines_stack.h.

Referenced by bm_face_connect_verts(), EDBM_select_interior_faces(), mesh_calc_path_region_elem(), mesh_calc_path_region_elem(), and remdoubles_createface().

◆ STACK_DECLARE

◆ STACK_DISCARD

#define STACK_DISCARD ( stack,
n )
Value:
{ \
const unsigned int _n = n; \
BLI_assert(_##stack##_index >= _n); \
(void)stack; \
_##stack##_index -= _n; \
} \
((void)0)

Definition at line 66 of file BLI_utildefines_stack.h.

◆ STACK_INIT

◆ STACK_PEEK

#define STACK_PEEK ( stack)    (BLI_assert(_##stack##_index), ((stack)[_##stack##_index - 1]))

look at last item (assumes non-empty stack)

Definition at line 54 of file BLI_utildefines_stack.h.

◆ STACK_PEEK_PTR

#define STACK_PEEK_PTR ( stack)    (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1]))

Definition at line 55 of file BLI_utildefines_stack.h.

◆ STACK_POP

◆ STACK_POP_DEFAULT

#define STACK_POP_DEFAULT ( stack,
r )   ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : (r))

Definition at line 52 of file BLI_utildefines_stack.h.

◆ STACK_POP_PTR

#define STACK_POP_PTR ( stack)    ((_##stack##_index) ? &((stack)[--(_##stack##_index)]) : NULL)

Definition at line 51 of file BLI_utildefines_stack.h.

Referenced by bm_face_split_edgenet_find_loop_walk().

◆ STACK_PUSH

◆ STACK_PUSH_RET

#define STACK_PUSH_RET ( stack)     ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++]))

◆ STACK_PUSH_RET_PTR

#define STACK_PUSH_RET_PTR ( stack)     ((void)stack, _STACK_SIZETEST(stack, 1), &((stack)[(_##stack##_index)++]))

Definition at line 47 of file BLI_utildefines_stack.h.

Referenced by bm_face_split_edgenet_find_loop_walk().

◆ STACK_REMOVE

#define STACK_REMOVE ( stack,
i )
Value:
{ \
const unsigned int _i = i; \
_STACK_BOUNDSTEST(stack, _i); \
if (--_##stack##_index != _i) { \
stack[_i] = stack[_##stack##_index]; \
} \
} \
((void)0)

remove any item from the stack, take care, re-orders

Definition at line 57 of file BLI_utildefines_stack.h.

Referenced by bm_edge_info_average_length_fallback(), and bmo_offset_edgeloops_exec().

◆ STACK_SIZE

◆ STACK_SWAP

#define STACK_SWAP ( stack_a,
stack_b )
Value:
{ \
SWAP(void *, *(void **)&stack_a, *(void **)&stack_b); \
SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \
_STACK_SWAP_TOTALLOC(stack_a, stack_b); \
} \
((void)0)

Definition at line 83 of file BLI_utildefines_stack.h.

Referenced by mesh_calc_path_region_elem(), and mesh_calc_path_region_elem().