Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_stack.h
1
8#ifndef __N_STACK_HEADER
9#define __N_STACK_HEADER
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
20#include "nilorea/n_common.h"
21
23#define STACK_ITEM_BOOL 1
25#define STACK_ITEM_CHAR 2
27#define STACK_ITEM_UINT8 3
29#define STACK_ITEM_INT8 4
31#define STACK_ITEM_UINT32 5
33#define STACK_ITEM_INT32 6
35#define STACK_ITEM_UINT64 7
37#define STACK_ITEM_INT64 8
39#define STACK_ITEM_FLOAT 9
41#define STACK_ITEM_DOUBLE 10
43#define STACK_ITEM_PTR 11
44
46#define STACK_IS_FULL 0
48#define STACK_IS_EMPTY 1
50#define STACK_IS_UNDEFINED 2
52#define STACK_ITEM_WRONG_TYPE 3
54#define STACK_ITEM_OK 4
55
59 bool b;
61 char c;
63 uint8_t ui8;
65 int8_t i8;
67 uint32_t ui32;
69 int32_t i32;
70#ifdef ENV_64BITS
72 uint64_t ui64;
74 int64_t i64;
75#endif
77 float f;
79 double d;
81 void* p;
82};
83
85typedef struct STACK_ITEM {
87 bool is_set;
93 uint8_t v_type;
95 uint16_t p_type;
97
99typedef struct STACK {
103 size_t size;
105 size_t head;
107 size_t tail;
109 size_t nb_items;
110} STACK;
111
112#ifdef ENV_64BITS
114#define stack_push(__STACK, __VAL) \
115 _Generic((__VAL), \
116 bool: stack_push_b, \
117 char: stack_push_c, \
118 uint8_t: stack_push_ui8, \
119 int8_t: stack_push_i8, \
120 uint32_t: stack_push_ui32, \
121 int32_t: stack_push_i32, \
122 uint64_t: stack_push_ui64, \
123 int64_t: stack_push_i64, \
124 float: stack_push_f, \
125 double: stack_push_d, \
126 void*: stack_push_p)(__STACK, __VAL)
127#else
129#define stack_push(__STACK, __VAL) \
130 _Generic((__VAL), \
131 bool: stack_push_b, \
132 char: stack_push_c, \
133 uint8_t: stack_push_ui8, \
134 int8_t: stack_push_i8, \
135 uint32_t: stack_push_ui32, \
136 int32_t: stack_push_i32, \
137 float: stack_push_f, \
138 double: stack_push_d, \
139 void*: stack_push_p)(__STACK, __VAL)
140#endif
141
142STACK* new_stack(size_t nb_items);
143bool delete_stack(STACK** stack);
144bool stack_is_full(STACK* stack);
145bool stack_is_empty(STACK* stack);
146STACK_ITEM* stack_peek(STACK* stack, size_t position);
147
148bool stack_push_b(STACK* stack, bool b);
149bool stack_push_c(STACK* stack, char c);
150bool stack_push_ui8(STACK* stack, uint8_t ui8);
151bool stack_push_i8(STACK* stack, int8_t i8);
152bool stack_push_ui32(STACK* stack, uint32_t ui32);
153bool stack_push_i32(STACK* stack, int32_t i32);
154bool stack_push_f(STACK* stack, float f);
155bool stack_push_d(STACK* stack, double d);
156bool stack_push_p(STACK* stack, void* p, uint16_t p_type);
157
158bool stack_pop_b(STACK* stack, uint8_t* status);
159char stack_pop_c(STACK* stack, uint8_t* status);
160uint8_t stack_pop_ui8(STACK* stack, uint8_t* status);
161int8_t stack_pop_i8(STACK* stack, uint8_t* status);
162uint32_t stack_pop_ui32(STACK* stack, uint8_t* status);
163int32_t stack_pop_i32(STACK* stack, uint8_t* status);
164float stack_pop_f(STACK* stack, uint8_t* status);
165double stack_pop_d(STACK* stack, uint8_t* status);
166void* stack_pop_p(STACK* stack, uint8_t* status);
167
168#ifdef ENV_64BITS
169bool stack_push_ui64(STACK* stack, uint64_t ui64_t);
170bool stack_push_i64(STACK* stack, int64_t i64);
171uint64_t stack_pop_ui64(STACK* stack, uint8_t* status);
172int64_t stack_pop_i64(STACK* stack, uint8_t* status);
173#endif
174
179#ifdef __cplusplus
180}
181#endif
182
183#endif
size_t tail
position of tail
Definition n_stack.h:107
bool is_empty
is item set ?
Definition n_stack.h:89
size_t head
position of head
Definition n_stack.h:105
size_t nb_items
number of item inside stack
Definition n_stack.h:109
STACK_ITEM * stack_array
STACK_ITEM array.
Definition n_stack.h:101
int8_t i8
int 8
Definition n_stack.h:65
uint16_t p_type
if v_type is STACK_ITEM_PTR, user defined pointer type
Definition n_stack.h:95
union STACK_DATA data
union of different types
Definition n_stack.h:91
void * p
pointer
Definition n_stack.h:81
double d
double
Definition n_stack.h:79
size_t size
Size of array.
Definition n_stack.h:103
float f
float
Definition n_stack.h:77
char c
single character
Definition n_stack.h:61
int32_t i32
int 32
Definition n_stack.h:69
uint8_t v_type
type of the item
Definition n_stack.h:93
bool b
boolean
Definition n_stack.h:59
bool is_set
is item empty ?
Definition n_stack.h:87
uint32_t ui32
unsigned int 32
Definition n_stack.h:67
uint8_t ui8
unsigned int 8
Definition n_stack.h:63
bool stack_push_f(STACK *stack, float f)
helper to push a float
Definition n_stack.c:420
bool stack_is_empty(STACK *stack)
test if the stack is empty
Definition n_stack.c:55
double stack_pop_d(STACK *stack, uint8_t *status)
helper to pop a double
Definition n_stack.c:484
bool stack_pop_b(STACK *stack, uint8_t *status)
helper to pop a bool
Definition n_stack.c:176
bool stack_push_d(STACK *stack, double d)
helper to push a double
Definition n_stack.c:464
bool stack_push_ui8(STACK *stack, uint8_t ui8)
helper to push an uint8_t
Definition n_stack.c:244
STACK_ITEM * stack_peek(STACK *stack, size_t position)
peek in the stack with un stacking the stack item
Definition n_stack.c:65
bool stack_is_full(STACK *stack)
test if the stack is full
Definition n_stack.c:46
bool stack_push_ui32(STACK *stack, uint32_t ui32)
helper to push an uint32_t
Definition n_stack.c:332
int8_t stack_pop_i8(STACK *stack, uint8_t *status)
helper to pop a int8_t
Definition n_stack.c:308
char stack_pop_c(STACK *stack, uint8_t *status)
helper to pop a char
Definition n_stack.c:220
float stack_pop_f(STACK *stack, uint8_t *status)
helper to pop a float
Definition n_stack.c:440
uint8_t stack_pop_ui8(STACK *stack, uint8_t *status)
helper to pop a uint8_t
Definition n_stack.c:264
bool stack_push_c(STACK *stack, char c)
helper to push a char
Definition n_stack.c:200
uint32_t stack_pop_ui32(STACK *stack, uint8_t *status)
helper to pop a uint32_t
Definition n_stack.c:352
bool stack_push_b(STACK *stack, bool b)
helper to push a bool
Definition n_stack.c:158
bool stack_push_i32(STACK *stack, int32_t i32)
helper to push an int32_t
Definition n_stack.c:376
int32_t stack_pop_i32(STACK *stack, uint8_t *status)
helper to pop a int32_t
Definition n_stack.c:396
bool delete_stack(STACK **stack)
delete a STACK *stack
Definition n_stack.c:34
bool stack_push_i8(STACK *stack, int8_t i8)
helper to push an int8_t
Definition n_stack.c:288
STACK * new_stack(size_t nb_items)
allocate a new STACK
Definition n_stack.c:15
bool stack_push_p(STACK *stack, void *p, uint16_t p_type)
helper to push a pointer
Definition n_stack.c:509
void * stack_pop_p(STACK *stack, uint8_t *status)
helper to pop a pointer
Definition n_stack.c:530
STACK structure.
Definition n_stack.h:99
structure of a STACK item
Definition n_stack.h:85
structure of a STACK_ITEM data
Definition n_stack.h:57
Common headers and low-level functions & define.