 |
Blender
V2.93
|
Go to the documentation of this file.
28 # define STACK_DECLARE(stack) unsigned int _##stack##_index, _##stack##_totalloc
29 # define STACK_INIT(stack, tot) \
30 ((void)stack, (void)((_##stack##_index) = 0), (void)((_##stack##_totalloc) = (tot)))
31 # define _STACK_SIZETEST(stack, off) \
32 (BLI_assert((_##stack##_index) + (off) <= _##stack##_totalloc))
33 # define _STACK_SWAP_TOTALLOC(stack_a, stack_b) \
34 SWAP(unsigned int, _##stack_a##_totalloc, _##stack_b##_totalloc)
36 # define STACK_DECLARE(stack) unsigned int _##stack##_index
37 # define STACK_INIT(stack, tot) \
38 ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? (tot) : 0))
39 # define _STACK_SIZETEST(stack, off) (void)(stack), (void)(off)
40 # define _STACK_SWAP_TOTALLOC(stack_a, stack_b) (void)(stack_a), (void)(stack_b)
42 #define _STACK_BOUNDSTEST(stack, index) \
43 ((void)stack, BLI_assert((unsigned int)(index) < _##stack##_index))
45 #define STACK_SIZE(stack) ((void)stack, (_##stack##_index))
46 #define STACK_CLEAR(stack) \
49 _##stack##_index = 0; \
53 #define STACK_PUSH(stack, val) \
54 ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++] = (val)))
55 #define STACK_PUSH_RET(stack) \
56 ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++]))
57 #define STACK_PUSH_RET_PTR(stack) \
58 ((void)stack, _STACK_SIZETEST(stack, 1), &((stack)[(_##stack##_index)++]))
60 #define STACK_POP(stack) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : NULL)
61 #define STACK_POP_PTR(stack) ((_##stack##_index) ? &((stack)[--(_##stack##_index)]) : NULL)
62 #define STACK_POP_DEFAULT(stack, r) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : (r))
64 #define STACK_PEEK(stack) (BLI_assert(_##stack##_index), ((stack)[_##stack##_index - 1]))
65 #define STACK_PEEK_PTR(stack) (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1]))
67 #define STACK_REMOVE(stack, i) \
69 const unsigned int _i = i; \
70 _STACK_BOUNDSTEST(stack, _i); \
71 if (--_##stack##_index != _i) { \
72 stack[_i] = stack[_##stack##_index]; \
76 #define STACK_DISCARD(stack, n) \
78 const unsigned int _n = n; \
79 BLI_assert(_##stack##_index >= _n); \
81 _##stack##_index -= _n; \
85 # define STACK_SWAP(stack_a, stack_b) \
87 SWAP(typeof(stack_a), stack_a, stack_b); \
88 SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \
89 _STACK_SWAP_TOTALLOC(stack_a, stack_b); \
93 # define STACK_SWAP(stack_a, stack_b) \
95 SWAP(void *, stack_a, stack_b); \
96 SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \
97 _STACK_SWAP_TOTALLOC(stack_a, stack_b); \