Blender  V3.3
Macros
BLI_utildefines_stack.h File Reference

Go to the source code of this file.

Macros

#define STACK_DECLARE(stack)   unsigned int _##stack##_index
 
#define STACK_INIT(stack, stack_num)    ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? (stack_num) : 0))
 
#define _STACK_SIZETEST(stack, off)   (void)(stack), (void)(off)
 
#define _STACK_SWAP_TOTALLOC(stack_a, stack_b)   (void)(stack_a), (void)(stack_b)
 
#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 28 of file BLI_utildefines_stack.h.

◆ _STACK_SIZETEST

#define _STACK_SIZETEST (   stack,
  off 
)    (void)(stack), (void)(off)

Definition at line 25 of file BLI_utildefines_stack.h.

◆ _STACK_SWAP_TOTALLOC

#define _STACK_SWAP_TOTALLOC (   stack_a,
  stack_b 
)    (void)(stack_a), (void)(stack_b)

Definition at line 26 of file BLI_utildefines_stack.h.

◆ STACK_CLEAR

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

Definition at line 32 of file BLI_utildefines_stack.h.

◆ STACK_DECLARE

#define STACK_DECLARE (   stack)    unsigned int _##stack##_index

Definition at line 22 of file BLI_utildefines_stack.h.

◆ STACK_DISCARD

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

Definition at line 62 of file BLI_utildefines_stack.h.

◆ STACK_INIT

#define STACK_INIT (   stack,
  stack_num 
)     ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? (stack_num) : 0))

Definition at line 23 of file BLI_utildefines_stack.h.

◆ 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 50 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 51 of file BLI_utildefines_stack.h.

◆ STACK_POP

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

take last item from stack

Definition at line 46 of file BLI_utildefines_stack.h.

◆ STACK_POP_DEFAULT

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

Definition at line 48 of file BLI_utildefines_stack.h.

◆ STACK_POP_PTR

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

Definition at line 47 of file BLI_utildefines_stack.h.

◆ STACK_PUSH

#define STACK_PUSH (   stack,
  val 
)     ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++] = (val)))

add item to stack

Definition at line 39 of file BLI_utildefines_stack.h.

◆ STACK_PUSH_RET

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

Definition at line 41 of file BLI_utildefines_stack.h.

◆ STACK_PUSH_RET_PTR

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

Definition at line 43 of file BLI_utildefines_stack.h.

◆ STACK_REMOVE

#define STACK_REMOVE (   stack,
 
)
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 53 of file BLI_utildefines_stack.h.

◆ STACK_SIZE

#define STACK_SIZE (   stack)    ((void)stack, (_##stack##_index))

Definition at line 31 of file BLI_utildefines_stack.h.

◆ STACK_SWAP

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

Definition at line 79 of file BLI_utildefines_stack.h.