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)

Functions

bool delete_stack (STACK **stack)
 delete a stack and free its memory
STACK * new_stack (size_t nb_items)
 allocate a new stack
bool stack_is_empty (const STACK *stack)
 check if the stack is empty
bool stack_is_full (const STACK *stack)
 check if the stack is full
STACK_ITEM * stack_peek (STACK *stack, size_t position)
 peek at an item at given position without removing it
bool stack_pop_b (STACK *stack, uint8_t *status)
 pop a bool from the stack
char stack_pop_c (STACK *stack, uint8_t *status)
 pop a char from the stack
double stack_pop_d (STACK *stack, uint8_t *status)
 pop a double from the stack
float stack_pop_f (STACK *stack, uint8_t *status)
 pop a float from the stack
int32_t stack_pop_i32 (STACK *stack, uint8_t *status)
 pop an int32_t from the stack
int8_t stack_pop_i8 (STACK *stack, uint8_t *status)
 pop an int8_t from the stack
void * stack_pop_p (STACK *stack, uint8_t *status)
 pop a pointer from the stack
uint32_t stack_pop_ui32 (STACK *stack, uint8_t *status)
 pop a uint32_t from the stack
uint8_t stack_pop_ui8 (STACK *stack, uint8_t *status)
 pop a uint8_t from the stack
bool stack_push_b (STACK *stack, bool b)
 push a bool onto the stack
bool stack_push_c (STACK *stack, char c)
 push a char onto the stack
bool stack_push_d (STACK *stack, double d)
 push a double onto the stack
bool stack_push_f (STACK *stack, float f)
 push a float onto the stack
bool stack_push_i32 (STACK *stack, int32_t i32)
 push an int32_t onto the stack
bool stack_push_i8 (STACK *stack, int8_t i8)
 push an int8_t onto the stack
bool stack_push_p (STACK *stack, void *p, uint16_t p_type)
 push a pointer onto the stack with a custom type
bool stack_push_p_default (STACK *stack, void *p)
 push a pointer onto the stack with default type
bool stack_push_ui32 (STACK *stack, uint32_t ui32)
 push a uint32_t onto the stack
bool stack_push_ui8 (STACK *stack, uint8_t ui8)
 push a uint8_t onto the stack

Detailed Description


Data Structure Documentation

◆ STACK

struct STACK

STACK structure.

Examples
ex_stack.c.

Definition at line 118 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 76 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 104 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 empty ?
bool is_set is item set ?
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

◆ STACK_IS_FULL

#define STACK_IS_FULL   0

code for a full stack state

Definition at line 65 of file n_stack.h.

Referenced by __stack_push().

◆ STACK_IS_UNDEFINED

#define STACK_IS_UNDEFINED   2

◆ STACK_ITEM_BOOL

#define STACK_ITEM_BOOL   1

v_type value for a bool

Examples
ex_stack.c.

Definition at line 42 of file n_stack.h.

Referenced by main(), stack_pop_b(), and stack_push_b().

◆ STACK_ITEM_CHAR

#define STACK_ITEM_CHAR   2

v_type value for a char

Examples
ex_stack.c.

Definition at line 44 of file n_stack.h.

Referenced by main(), stack_pop_c(), and stack_push_c().

◆ STACK_ITEM_DOUBLE

#define STACK_ITEM_DOUBLE   10

v_type value for a double

Examples
ex_stack.c.

Definition at line 60 of file n_stack.h.

Referenced by main(), stack_pop_d(), and stack_push_d().

◆ STACK_ITEM_FLOAT

#define STACK_ITEM_FLOAT   9

v_type value for a float

Examples
ex_stack.c.

Definition at line 58 of file n_stack.h.

Referenced by main(), stack_pop_f(), and stack_push_f().

◆ STACK_ITEM_INT32

#define STACK_ITEM_INT32   6

v_type value for a int32_t

Examples
ex_stack.c.

Definition at line 52 of file n_stack.h.

Referenced by main(), stack_pop_i32(), and stack_push_i32().

◆ STACK_ITEM_INT64

#define STACK_ITEM_INT64   8

v_type value for a int64_t

Definition at line 56 of file n_stack.h.

◆ STACK_ITEM_INT8

#define STACK_ITEM_INT8   4

v_type value for a int8_t

Examples
ex_stack.c.

Definition at line 48 of file n_stack.h.

Referenced by main(), stack_pop_i8(), and stack_push_i8().

◆ STACK_ITEM_OK

◆ STACK_ITEM_PTR

#define STACK_ITEM_PTR   11

v_type value for a void *pointer

Examples
ex_stack.c.

Definition at line 62 of file n_stack.h.

Referenced by main(), stack_pop_p(), and stack_push_p().

◆ STACK_ITEM_UINT32

#define STACK_ITEM_UINT32   5

v_type value for a uint32_t

Examples
ex_stack.c.

Definition at line 50 of file n_stack.h.

Referenced by main(), stack_pop_ui32(), and stack_push_ui32().

◆ STACK_ITEM_UINT64

#define STACK_ITEM_UINT64   7

v_type value for a uint64_t

Definition at line 54 of file n_stack.h.

◆ STACK_ITEM_UINT8

#define STACK_ITEM_UINT8   3

v_type value for a uint8_t

Examples
ex_stack.c.

Definition at line 46 of file n_stack.h.

Referenced by main(), stack_pop_ui8(), and stack_push_ui8().

◆ STACK_ITEM_WRONG_TYPE

#define STACK_ITEM_WRONG_TYPE   3

code for a bad item type

Definition at line 71 of file n_stack.h.

Referenced by stack_pop_b(), stack_pop_c(), stack_pop_d(), stack_pop_f(), stack_pop_i32(), stack_pop_i8(), stack_pop_p(), stack_pop_ui32(), and stack_pop_ui8().

◆ 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_default)(__STACK, __VAL)
bool stack_push_f(STACK *stack, float f)
helper to push a float
Definition n_stack.c:478
bool stack_push_d(STACK *stack, double d)
helper to push a double
Definition n_stack.c:527
bool stack_push_ui8(STACK *stack, uint8_t ui8)
helper to push an uint8_t
Definition n_stack.c:282
bool stack_push_ui32(STACK *stack, uint32_t ui32)
helper to push an uint32_t
Definition n_stack.c:380
bool stack_push_c(STACK *stack, char c)
helper to push a char
Definition n_stack.c:233
bool stack_push_b(STACK *stack, bool b)
helper to push a bool
Definition n_stack.c:186
bool stack_push_i32(STACK *stack, int32_t i32)
helper to push an int32_t
Definition n_stack.c:429
bool stack_push_i8(STACK *stack, int8_t i8)
helper to push an int8_t
Definition n_stack.c:331
bool stack_push_p_default(STACK *stack, void *p)
helper to push a pointer with a default p_type of 0
Definition n_stack.c:627
Examples
ex_stack.c.

Definition at line 182 of file n_stack.h.

Referenced by main().

Function Documentation

◆ delete_stack()

bool delete_stack ( STACK ** stack)

delete a stack and free its memory

delete a stack and free its memory

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

Definition at line 59 of file n_stack.c.

References __n_assert, and Free.

Referenced by main().

Here is the caller graph for this function:

◆ new_stack()

STACK * new_stack ( size_t size)

allocate a new stack

allocate a new stack

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

Definition at line 35 of file n_stack.c.

References __n_assert, Free, STACK::head, LOG_ERR, Malloc, n_log, STACK::nb_items, STACK::size, STACK::stack_array, and STACK::tail.

Referenced by main().

Here is the caller graph for this function:

◆ stack_is_empty()

bool stack_is_empty ( const STACK * stack)

check if the stack is empty

check if the stack is empty

Parameters
stackthe STACK *stack to test
Returns
TRUE or FALSE

Definition at line 82 of file n_stack.c.

References STACK::nb_items.

Referenced by main(), and stack_peek().

Here is the caller graph for this function:

◆ stack_is_full()

bool stack_is_full ( const STACK * stack)

check if the stack is full

check if the stack is full

Parameters
stackthe STACK *stack to test
Returns
TRUE or FALSE

Definition at line 72 of file n_stack.c.

References STACK::head, STACK::size, and STACK::tail.

Referenced by __stack_push(), and main().

Here is the caller graph for this function:

◆ stack_peek()

STACK_ITEM * stack_peek ( STACK * stack,
size_t position )

peek at an item at given position without removing it

peek at an item at given position without removing it

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

Definition at line 93 of file n_stack.c.

References __n_assert, STACK::head, STACK_ITEM::is_set, STACK::stack_array, stack_is_empty(), and STACK::tail.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_b()

bool stack_pop_b ( STACK * stack,
uint8_t * status )

pop a bool from the stack

pop a bool from the stack

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 204 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_DATA::b, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_BOOL, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_c()

char stack_pop_c ( STACK * stack,
uint8_t * status )

pop a char from the stack

pop a char from the stack

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 253 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_DATA::c, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_CHAR, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_d()

double stack_pop_d ( STACK * stack,
uint8_t * status )

pop a double from the stack

pop a double from the stack

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 547 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_DATA::d, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_DOUBLE, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_f()

float stack_pop_f ( STACK * stack,
uint8_t * status )

pop a float from the stack

pop a float from the stack

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 498 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK_DATA::f, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_FLOAT, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_i32()

int32_t stack_pop_i32 ( STACK * stack,
uint8_t * status )

pop an int32_t from the stack

pop an int32_t from the stack

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 449 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK::head, STACK_DATA::i32, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_INT32, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_i8()

int8_t stack_pop_i8 ( STACK * stack,
uint8_t * status )

pop an int8_t from the stack

pop an int8_t from the stack

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 351 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK::head, STACK_DATA::i8, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_INT8, STACK_ITEM_OK, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_p()

void * stack_pop_p ( STACK * stack,
uint8_t * status )

pop a pointer from the stack

pop a pointer from the stack

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 598 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK::head, STACK_DATA::p, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_PTR, STACK_ITEM_WRONG_TYPE, STACK::tail, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_ui32()

uint32_t stack_pop_ui32 ( STACK * stack,
uint8_t * status )

pop a uint32_t from the stack

pop a uint32_t from the stack

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 400 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_UINT32, STACK_ITEM_WRONG_TYPE, STACK::tail, STACK_DATA::ui32, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_pop_ui8()

uint8_t stack_pop_ui8 ( STACK * stack,
uint8_t * status )

pop a uint8_t from the stack

pop a uint8_t from the stack

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 302 of file n_stack.c.

References __n_assert, __stack_pop(), STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_IS_EMPTY, STACK_IS_UNDEFINED, STACK_ITEM_OK, STACK_ITEM_UINT8, STACK_ITEM_WRONG_TYPE, STACK::tail, STACK_DATA::ui8, and STACK_ITEM::v_type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_push_b()

bool stack_push_b ( STACK * stack,
bool b )

push a bool onto the stack

push a bool onto the stack

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

Definition at line 186 of file n_stack.c.

References __stack_push(), STACK_DATA::b, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_ITEM_BOOL, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_c()

bool stack_push_c ( STACK * stack,
char c )

push a char onto the stack

push a char onto the stack

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

Definition at line 233 of file n_stack.c.

References __stack_push(), STACK_DATA::c, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_ITEM_CHAR, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_d()

bool stack_push_d ( STACK * stack,
double d )

push a double onto the stack

push a double onto the stack

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

Definition at line 527 of file n_stack.c.

References __stack_push(), STACK_DATA::d, STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_ITEM_DOUBLE, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_f()

bool stack_push_f ( STACK * stack,
float f )

push a float onto the stack

push a float onto the stack

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

Definition at line 478 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK_DATA::f, STACK::head, STACK::stack_array, STACK_ITEM_FLOAT, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_i32()

bool stack_push_i32 ( STACK * stack,
int32_t i32 )

push an int32_t onto the stack

push an int32_t onto the stack

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

Definition at line 429 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK::head, STACK_DATA::i32, STACK::stack_array, STACK_ITEM_INT32, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_i8()

bool stack_push_i8 ( STACK * stack,
int8_t i8 )

push an int8_t onto the stack

push an int8_t onto the stack

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

Definition at line 331 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK::head, STACK_DATA::i8, STACK::stack_array, STACK_ITEM_INT8, STACK_ITEM_OK, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_p()

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

push a pointer onto the stack with a custom type

push a pointer onto the stack with a custom type

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

Definition at line 577 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK::head, STACK_DATA::p, STACK_ITEM::p_type, STACK::stack_array, STACK_ITEM_OK, STACK_ITEM_PTR, and STACK_ITEM::v_type.

Referenced by stack_push_p_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_push_p_default()

bool stack_push_p_default ( STACK * stack,
void * p )

push a pointer onto the stack with default type

push a pointer onto the stack with default type

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

Definition at line 627 of file n_stack.c.

References stack_push_p().

Here is the call graph for this function:

◆ stack_push_ui32()

bool stack_push_ui32 ( STACK * stack,
uint32_t ui32 )

push a uint32_t onto the stack

push a uint32_t onto the stack

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

Definition at line 380 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_ITEM_OK, STACK_ITEM_UINT32, STACK_DATA::ui32, and STACK_ITEM::v_type.

Here is the call graph for this function:

◆ stack_push_ui8()

bool stack_push_ui8 ( STACK * stack,
uint8_t ui8 )

push a uint8_t onto the stack

push a uint8_t onto the stack

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

Definition at line 282 of file n_stack.c.

References __stack_push(), STACK_ITEM::data, STACK::head, STACK::stack_array, STACK_ITEM_OK, STACK_ITEM_UINT8, STACK_DATA::ui8, and STACK_ITEM::v_type.

Here is the call graph for this function: