Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
STACKS: generic type stack

Data Structures

struct  STACK
 STACK structure. More...
 
union  STACK_DATA
 structure of a STACK_ITEM data More...
 
struct  STACK_ITEM
 structure of a STACK item More...
 

Macros

#define STACK_IS_EMPTY   1
 code for an empty stack state
 
#define STACK_IS_FULL   0
 code for a full stack state
 
#define STACK_IS_UNDEFINED   2
 code for a NULL stack state
 
#define STACK_ITEM_BOOL   1
 v_type value for a bool
 
#define STACK_ITEM_CHAR   2
 v_type value for a char
 
#define STACK_ITEM_DOUBLE   10
 v_type value for a double
 
#define STACK_ITEM_FLOAT   9
 v_type value for a float
 
#define STACK_ITEM_INT32   6
 v_type value for a int32_t
 
#define STACK_ITEM_INT64   8
 v_type value for a int64_t
 
#define STACK_ITEM_INT8   4
 v_type value for a int8_t
 
#define STACK_ITEM_OK   4
 code for a successfully retrieved item
 
#define STACK_ITEM_PTR   11
 v_type value for a void *pointer
 
#define STACK_ITEM_UINT32   5
 v_type value for a uint32_t
 
#define STACK_ITEM_UINT64   7
 v_type value for a uint64_t
 
#define STACK_ITEM_UINT8   3
 v_type value for a uint8_t
 
#define STACK_ITEM_WRONG_TYPE   3
 code for a bad item type
 
#define stack_push(__STACK, __VAL)
 stack push helper with automatic value selection
 

Functions

bool delete_stack (STACK **stack)
 delete a STACK *stack
 
STACKnew_stack (size_t nb_items)
 allocate a new STACK
 
bool stack_is_empty (STACK *stack)
 test if the stack is empty
 
bool stack_is_full (STACK *stack)
 test if the stack is full
 
STACK_ITEMstack_peek (STACK *stack, size_t position)
 peek in the stack with un stacking the stack item
 
bool stack_pop_b (STACK *stack, uint8_t *status)
 helper to pop a bool
 
char stack_pop_c (STACK *stack, uint8_t *status)
 helper to pop a char
 
double stack_pop_d (STACK *stack, uint8_t *status)
 helper to pop a double
 
float stack_pop_f (STACK *stack, uint8_t *status)
 helper to pop a float
 
int32_t stack_pop_i32 (STACK *stack, uint8_t *status)
 helper to pop a int32_t
 
int8_t stack_pop_i8 (STACK *stack, uint8_t *status)
 helper to pop a int8_t
 
void * stack_pop_p (STACK *stack, uint8_t *status)
 helper to pop a pointer
 
uint32_t stack_pop_ui32 (STACK *stack, uint8_t *status)
 helper to pop a uint32_t
 
uint8_t stack_pop_ui8 (STACK *stack, uint8_t *status)
 helper to pop a uint8_t
 
bool stack_push_b (STACK *stack, bool b)
 helper to push a bool
 
bool stack_push_c (STACK *stack, char c)
 helper to push a char
 
bool stack_push_d (STACK *stack, double d)
 helper to push a double
 
bool stack_push_f (STACK *stack, float f)
 helper to push a float
 
bool stack_push_i32 (STACK *stack, int32_t i32)
 helper to push an int32_t
 
bool stack_push_i8 (STACK *stack, int8_t i8)
 helper to push an int8_t
 
bool stack_push_p (STACK *stack, void *p, uint16_t p_type)
 helper to push a pointer
 
bool stack_push_ui32 (STACK *stack, uint32_t ui32)
 helper to push an uint32_t
 
bool stack_push_ui8 (STACK *stack, uint8_t ui8)
 helper to push an uint8_t
 

Detailed Description


Data Structure Documentation

◆ STACK

struct STACK

STACK structure.

Examples
ex_stack.c.

Definition at line 103 of file n_stack.h.

+ Collaboration diagram for STACK:
Data Fields
size_t head position of head
size_t nb_items number of item inside stack
size_t size Size of array.
STACK_ITEM * stack_array STACK_ITEM array.
size_t tail position of tail

◆ STACK_DATA

union STACK_DATA

structure of a STACK_ITEM data

Definition at line 58 of file n_stack.h.

+ Collaboration diagram for STACK_DATA:
Data Fields
bool b boolean
char c single character
double d double
float f float
int32_t i32 int 32
int8_t i8 int 8
void * p pointer
uint32_t ui32 unsigned int 32
uint8_t ui8 unsigned int 8

◆ STACK_ITEM

struct STACK_ITEM

structure of a STACK item

Examples
ex_stack.c.

Definition at line 87 of file n_stack.h.

+ Collaboration diagram for STACK_ITEM:
Data Fields
union STACK_DATA data union of different types
bool is_empty is item set ?
bool is_set is item empty ?
uint16_t p_type if v_type is STACK_ITEM_PTR, user defined pointer type
uint8_t v_type type of the item

Macro Definition Documentation

◆ STACK_IS_EMPTY

#define STACK_IS_EMPTY   1

code for an empty stack state

Definition at line 49 of file n_stack.h.

◆ STACK_IS_FULL

#define STACK_IS_FULL   0

code for a full stack state

Definition at line 47 of file n_stack.h.

◆ STACK_IS_UNDEFINED

#define STACK_IS_UNDEFINED   2

code for a NULL stack state

Examples
ex_stack.c.

Definition at line 51 of file n_stack.h.

◆ STACK_ITEM_BOOL

#define STACK_ITEM_BOOL   1

v_type value for a bool

Examples
ex_stack.c.

Definition at line 24 of file n_stack.h.

◆ STACK_ITEM_CHAR

#define STACK_ITEM_CHAR   2

v_type value for a char

Definition at line 26 of file n_stack.h.

◆ STACK_ITEM_DOUBLE

#define STACK_ITEM_DOUBLE   10

v_type value for a double

Definition at line 42 of file n_stack.h.

◆ STACK_ITEM_FLOAT

#define STACK_ITEM_FLOAT   9

v_type value for a float

Definition at line 40 of file n_stack.h.

◆ STACK_ITEM_INT32

#define STACK_ITEM_INT32   6

v_type value for a int32_t

Examples
ex_stack.c.

Definition at line 34 of file n_stack.h.

◆ STACK_ITEM_INT64

#define STACK_ITEM_INT64   8

v_type value for a int64_t

Definition at line 38 of file n_stack.h.

◆ STACK_ITEM_INT8

#define STACK_ITEM_INT8   4

v_type value for a int8_t

Definition at line 30 of file n_stack.h.

◆ STACK_ITEM_OK

#define STACK_ITEM_OK   4

code for a successfully retrieved item

Examples
ex_stack.c.

Definition at line 55 of file n_stack.h.

◆ STACK_ITEM_PTR

#define STACK_ITEM_PTR   11

v_type value for a void *pointer

Definition at line 44 of file n_stack.h.

◆ STACK_ITEM_UINT32

#define STACK_ITEM_UINT32   5

v_type value for a uint32_t

Definition at line 32 of file n_stack.h.

◆ STACK_ITEM_UINT64

#define STACK_ITEM_UINT64   7

v_type value for a uint64_t

Definition at line 36 of file n_stack.h.

◆ STACK_ITEM_UINT8

#define STACK_ITEM_UINT8   3

v_type value for a uint8_t

Definition at line 28 of file n_stack.h.

◆ STACK_ITEM_WRONG_TYPE

#define STACK_ITEM_WRONG_TYPE   3

code for a bad item type

Definition at line 53 of file n_stack.h.

◆ stack_push

#define stack_push (   __STACK,
  __VAL 
)
Value:
_Generic((__VAL), \
bool: stack_push_b, \
char: stack_push_c, \
uint8_t: stack_push_ui8, \
int8_t: stack_push_i8, \
uint32_t: stack_push_ui32, \
int32_t: stack_push_i32, \
float: stack_push_f, \
double: stack_push_d, \
void*: stack_push_p \
)( __STACK , __VAL )
bool stack_push_f(STACK *stack, float f)
helper to push a float
Definition n_stack.c:467
bool stack_push_d(STACK *stack, double d)
helper to push a double
Definition n_stack.c:515
bool stack_push_ui8(STACK *stack, uint8_t ui8)
helper to push an uint8_t
Definition n_stack.c:275
bool stack_push_ui32(STACK *stack, uint32_t ui32)
helper to push an uint32_t
Definition n_stack.c:371
bool stack_push_c(STACK *stack, char c)
helper to push a char
Definition n_stack.c:225
bool stack_push_b(STACK *stack, bool b)
helper to push a bool
Definition n_stack.c:178
bool stack_push_i32(STACK *stack, int32_t i32)
helper to push an int32_t
Definition n_stack.c:419
bool stack_push_i8(STACK *stack, int8_t i8)
helper to push an int8_t
Definition n_stack.c:323
bool stack_push_p(STACK *stack, void *p, uint16_t p_type)
helper to push a pointer
Definition n_stack.c:565

stack push helper with automatic value selection

Examples
ex_stack.c.

Definition at line 135 of file n_stack.h.

Function Documentation

◆ delete_stack()

bool delete_stack ( STACK **  stack)

delete a STACK *stack

Parameters
stackpointer to the STACK *stack to delete
Returns
TRUE or FALSE

Definition at line 38 of file n_stack.c.

References __n_assert, and Free.

◆ new_stack()

STACK * new_stack ( size_t  size)

allocate a new STACK

Parameters
sizesize of the new stack
Returns
the new STACK *stack or NULL

Definition at line 17 of file n_stack.c.

References __n_assert, Free, and Malloc.

◆ stack_is_empty()

bool stack_is_empty ( STACK stack)

test if the stack is empty

Parameters
stackthe STACK *stack to test
Returns
TRUE or FALSE

Definition at line 61 of file n_stack.c.

Referenced by stack_peek().

+ Here is the caller graph for this function:

◆ stack_is_full()

bool stack_is_full ( STACK stack)

test if the stack is full

Parameters
stackthe STACK *stack to test
Returns
TRUE or FALSE

Definition at line 51 of file n_stack.c.

Referenced by __stack_push().

+ Here is the caller graph for this function:

◆ stack_peek()

STACK_ITEM * stack_peek ( STACK stack,
size_t  position 
)

peek in the stack with un stacking the stack item

Parameters
stackthe STACK *stack to peek
positionthe position to peek
Returns
a pointer to a STACK_ITEM or NULL

Definition at line 72 of file n_stack.c.

References __n_assert, and stack_is_empty().

+ Here is the call graph for this function:

◆ stack_pop_b()

bool stack_pop_b ( STACK stack,
uint8_t *  status 
)

helper to pop a bool

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped bool

Definition at line 197 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_BOOL, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_c()

char stack_pop_c ( STACK stack,
uint8_t *  status 
)

helper to pop a char

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped char

Definition at line 246 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_CHAR, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_d()

double stack_pop_d ( STACK stack,
uint8_t *  status 
)

helper to pop a double

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped double

Definition at line 536 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_DOUBLE, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_f()

float stack_pop_f ( STACK stack,
uint8_t *  status 
)

helper to pop a float

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped float

Definition at line 488 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_FLOAT, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_i32()

int32_t stack_pop_i32 ( STACK stack,
uint8_t *  status 
)

helper to pop a int32_t

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped int32_t

Definition at line 440 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_INT32, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_i8()

int8_t stack_pop_i8 ( STACK stack,
uint8_t *  status 
)

helper to pop a int8_t

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped int8_t

Definition at line 344 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_INT8, STACK_ITEM_OK, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_p()

void * stack_pop_p ( STACK stack,
uint8_t *  status 
)

helper to pop a pointer

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped pointer

Definition at line 588 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_PTR, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_ui32()

uint32_t stack_pop_ui32 ( STACK stack,
uint8_t *  status 
)

helper to pop a uint32_t

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped uint32_t

Definition at line 392 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_UINT32, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_pop_ui8()

uint8_t stack_pop_ui8 ( STACK stack,
uint8_t *  status 
)

helper to pop a uint8_t

Parameters
stacktarget STACK *stack
statuspointer to uint8_t holding the result of the operation (STACK_IS_UNDEFINED,STACK_IS_EMPTY,STACK_ITEM_OK)
Returns
the popped uint8_t

Definition at line 296 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_UINT8, and STACK_ITEM_WRONG_TYPE.

+ Here is the call graph for this function:

◆ stack_push_b()

bool stack_push_b ( STACK stack,
bool  b 
)

helper to push a bool

Parameters
stacktarget STACK *stack
bthe bool to push
Returns
TRUE or FALSE

Definition at line 178 of file n_stack.c.

References __stack_push(), STACK_ITEM_BOOL, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_c()

bool stack_push_c ( STACK stack,
char  c 
)

helper to push a char

Parameters
stacktarget STACK *stack
cthe char to push
Returns
TRUE or FALSE

Definition at line 225 of file n_stack.c.

References __stack_push(), STACK_ITEM_CHAR, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_d()

bool stack_push_d ( STACK stack,
double  d 
)

helper to push a double

Parameters
stacktarget STACK *stack
dthe double to push
Returns
TRUE or FALSE

Definition at line 515 of file n_stack.c.

References __stack_push(), STACK_ITEM_DOUBLE, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_f()

bool stack_push_f ( STACK stack,
float  f 
)

helper to push a float

Parameters
stacktarget STACK *stack
fthe float to push
Returns
TRUE or FALSE

Definition at line 467 of file n_stack.c.

References __stack_push(), STACK_ITEM_FLOAT, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_i32()

bool stack_push_i32 ( STACK stack,
int32_t  i32 
)

helper to push an int32_t

Parameters
stacktarget STACK *stack
i32the int32 to push
Returns
TRUE or FALSE

Definition at line 419 of file n_stack.c.

References __stack_push(), STACK_ITEM_INT32, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_i8()

bool stack_push_i8 ( STACK stack,
int8_t  i8 
)

helper to push an int8_t

Parameters
stacktarget STACK *stack
i8the int8_t to push
Returns
TRUE or FALSE

Definition at line 323 of file n_stack.c.

References __stack_push(), STACK_ITEM_INT8, and STACK_ITEM_OK.

+ Here is the call graph for this function:

◆ stack_push_p()

bool stack_push_p ( STACK stack,
void *  p,
uint16_t  p_type 
)

helper to push a pointer

Parameters
stacktarget STACK *stack
pthe pointer to push
p_typethe pointer type
Returns
TRUE or FALSE

Definition at line 565 of file n_stack.c.

References __stack_push(), STACK_ITEM_OK, and STACK_ITEM_PTR.

+ Here is the call graph for this function:

◆ stack_push_ui32()

bool stack_push_ui32 ( STACK stack,
uint32_t  ui32 
)

helper to push an uint32_t

Parameters
stacktarget STACK *stack
ui32the uint32 to push
Returns
TRUE or FALSE

Definition at line 371 of file n_stack.c.

References __stack_push(), STACK_ITEM_OK, and STACK_ITEM_UINT32.

+ Here is the call graph for this function:

◆ stack_push_ui8()

bool stack_push_ui8 ( STACK stack,
uint8_t  ui8 
)

helper to push an uint8_t

Parameters
stacktarget STACK *stack
ui8the uint8_t to push
Returns
TRUE or FALSE

Definition at line 275 of file n_stack.c.

References __stack_push(), STACK_ITEM_OK, and STACK_ITEM_UINT8.

+ Here is the call graph for this function: