8#include "nilorea/n_stack.h"
36 Free((*stack)->stack_array);
74 if (position >= stack->
tail && position <= stack->head && position < stack->size && stack->
stack_array[position].
is_set) {
77 }
else if (stack->
tail > stack->
head) {
78 if (position >= stack->
head && position <= stack->tail && position < stack->size && stack->
stack_array[position].
is_set) {
99 size_t next_pos = (stack->
head + 1) % stack->
size;
102 if (next_pos == stack->
tail) {
139 next_pos = (stack->
tail + 1) % stack->
size;
144 prev_pos = stack->
tail;
146 stack->
tail = next_pos;
165 stack->
head = next_pos;
188 (*status) = pop_status;
209 stack->
head = next_pos;
232 (*status) = pop_status;
253 stack->
head = next_pos;
276 (*status) = pop_status;
297 stack->
head = next_pos;
320 (*status) = pop_status;
341 stack->
head = next_pos;
364 (*status) = pop_status;
385 stack->
head = next_pos;
408 (*status) = pop_status;
429 stack->
head = next_pos;
452 (*status) = pop_status;
473 stack->
head = next_pos;
496 (*status) = pop_status;
519 stack->
head = next_pos;
542 (*status) = pop_status;
555bool stack_push_ui64(
STACK* stack, uint64_t ui64) {
564 stack->
head = next_pos;
575uint64_t stack_pop_ui64(
STACK* stack, uint8_t* status) {
587 (*status) = pop_status;
599bool stack_push_i64(
STACK* stack, int64_t i64) {
608 stack->
head = next_pos;
619int64_t stack_pop_i64(
STACK* stack, uint8_t* status) {
631 (*status) = pop_status;
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
size_t tail
position of tail
bool is_empty
is item set ?
size_t head
position of head
size_t nb_items
number of item inside stack
STACK_ITEM * stack_array
STACK_ITEM array.
uint16_t p_type
if v_type is STACK_ITEM_PTR, user defined pointer type
union STACK_DATA data
union of different types
size_t size
Size of array.
uint8_t v_type
type of the item
bool is_set
is item empty ?
uint32_t ui32
unsigned int 32
uint8_t ui8
unsigned int 8
bool stack_push_f(STACK *stack, float f)
helper to push a float
#define STACK_ITEM_UINT64
v_type value for a uint64_t
bool stack_is_empty(STACK *stack)
test if the stack is empty
double stack_pop_d(STACK *stack, uint8_t *status)
helper to pop a double
bool stack_pop_b(STACK *stack, uint8_t *status)
helper to pop a bool
bool stack_push_d(STACK *stack, double d)
helper to push a double
bool stack_push_ui8(STACK *stack, uint8_t ui8)
helper to push an uint8_t
#define STACK_ITEM_UINT32
v_type value for a uint32_t
STACK_ITEM * stack_peek(STACK *stack, size_t position)
peek in the stack with un stacking the stack item
bool stack_is_full(STACK *stack)
test if the stack is full
bool stack_push_ui32(STACK *stack, uint32_t ui32)
helper to push an uint32_t
int8_t stack_pop_i8(STACK *stack, uint8_t *status)
helper to pop a int8_t
#define STACK_ITEM_INT8
v_type value for a int8_t
char stack_pop_c(STACK *stack, uint8_t *status)
helper to pop a char
float stack_pop_f(STACK *stack, uint8_t *status)
helper to pop a float
#define STACK_ITEM_PTR
v_type value for a void *pointer
uint8_t stack_pop_ui8(STACK *stack, uint8_t *status)
helper to pop a uint8_t
bool stack_push_c(STACK *stack, char c)
helper to push a char
#define STACK_IS_EMPTY
code for an empty stack state
#define STACK_ITEM_INT64
v_type value for a int64_t
#define STACK_ITEM_INT32
v_type value for a int32_t
#define STACK_IS_FULL
code for a full stack state
#define STACK_ITEM_CHAR
v_type value for a char
#define STACK_ITEM_OK
code for a successfully retrieved item
uint32_t stack_pop_ui32(STACK *stack, uint8_t *status)
helper to pop a uint32_t
bool stack_push_b(STACK *stack, bool b)
helper to push a bool
#define STACK_ITEM_BOOL
v_type value for a bool
#define STACK_IS_UNDEFINED
code for a NULL stack state
#define STACK_ITEM_UINT8
v_type value for a uint8_t
bool stack_push_i32(STACK *stack, int32_t i32)
helper to push an int32_t
int32_t stack_pop_i32(STACK *stack, uint8_t *status)
helper to pop a int32_t
#define STACK_ITEM_WRONG_TYPE
code for a bad item type
#define STACK_ITEM_DOUBLE
v_type value for a double
bool delete_stack(STACK **stack)
delete a STACK *stack
bool stack_push_i8(STACK *stack, int8_t i8)
helper to push an int8_t
#define STACK_ITEM_FLOAT
v_type value for a float
STACK * new_stack(size_t size)
allocate a new STACK
bool stack_push_p(STACK *stack, void *p, uint16_t p_type)
helper to push a pointer
void * stack_pop_p(STACK *stack, uint8_t *status)
helper to pop a pointer
structure of a STACK item
size_t __stack_push(STACK *stack, uint8_t *status)
helper for stack_push.
size_t __stack_pop(STACK *stack, uint8_t *status)
helper for stack_pop.