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{
14#endif
15
21#include "nilorea/n_common.h"
22
24#define STACK_ITEM_BOOL 1
26#define STACK_ITEM_CHAR 2
28#define STACK_ITEM_UINT8 3
30#define STACK_ITEM_INT8 4
32#define STACK_ITEM_UINT32 5
34#define STACK_ITEM_INT32 6
36#define STACK_ITEM_UINT64 7
38#define STACK_ITEM_INT64 8
40#define STACK_ITEM_FLOAT 9
42#define STACK_ITEM_DOUBLE 10
44#define STACK_ITEM_PTR 11
45
47#define STACK_IS_FULL 0
49#define STACK_IS_EMPTY 1
51#define STACK_IS_UNDEFINED 2
53#define STACK_ITEM_WRONG_TYPE 3
55#define STACK_ITEM_OK 4
56
59 {
61 bool b ;
63 char c ;
65 uint8_t ui8 ;
67 int8_t i8 ;
69 uint32_t ui32 ;
71 int32_t i32 ;
72#ifdef ENV_64BITS
74 uint64_t ui64 ;
76 int64_t i64 ;
77#endif
79 float f ;
81 double d ;
83 void *p ;
84 };
85
87 typedef struct STACK_ITEM
88 {
90 bool is_set ;
92 bool is_empty ;
96 uint8_t v_type ;
98 uint16_t p_type ;
99 } STACK_ITEM ;
100
101
103 typedef struct STACK
104 {
108 size_t size ;
110 size_t head ;
112 size_t tail ;
114 size_t nb_items ;
115 } STACK ;
116
117#ifdef ENV_64BITS
119#define stack_push( __STACK , __VAL ) \
120 _Generic((__VAL), \
121 bool: stack_push_b, \
122 char: stack_push_c, \
123 uint8_t: stack_push_ui8, \
124 int8_t: stack_push_i8, \
125 uint32_t: stack_push_ui32, \
126 int32_t: stack_push_i32, \
127 uint64_t: stack_push_ui64, \
128 int64_t: stack_push_i64, \
129 float: stack_push_f, \
130 double: stack_push_d, \
131 void*: stack_push_p \
132 )( __STACK , __VAL )
133#else
135#define stack_push( __STACK, __VAL ) \
136 _Generic((__VAL), \
137 bool: stack_push_b, \
138 char: stack_push_c, \
139 uint8_t: stack_push_ui8, \
140 int8_t: stack_push_i8, \
141 uint32_t: stack_push_ui32, \
142 int32_t: stack_push_i32, \
143 float: stack_push_f, \
144 double: stack_push_d, \
145 void*: stack_push_p \
146 )( __STACK , __VAL )
147#endif
148
149 STACK *new_stack( size_t nb_items );
150 bool delete_stack( STACK **stack );
151 bool stack_is_full( STACK *stack );
152 bool stack_is_empty( STACK *stack );
153 STACK_ITEM *stack_peek( STACK *stack , size_t position );
154
155 bool stack_push_b( STACK *stack , bool b );
156 bool stack_push_c( STACK *stack , char c );
157 bool stack_push_ui8( STACK *stack , uint8_t ui8 );
158 bool stack_push_i8( STACK *stack , int8_t i8 );
159 bool stack_push_ui32( STACK *stack , uint32_t ui32 );
160 bool stack_push_i32( STACK *stack , int32_t i32 );
161 bool stack_push_f( STACK *stack , float f );
162 bool stack_push_d( STACK *stack , double d );
163 bool stack_push_p( STACK *stack , void *p , uint16_t p_type );
164
165 bool stack_pop_b( STACK *stack , uint8_t *status );
166 char stack_pop_c( STACK *stack , uint8_t *status );
167 uint8_t stack_pop_ui8( STACK *stack , uint8_t *status );
168 int8_t stack_pop_i8( STACK *stack , uint8_t *status );
169 uint32_t stack_pop_ui32( STACK *stack , uint8_t *status );
170 int32_t stack_pop_i32( STACK *stack , uint8_t *status );
171 float stack_pop_f( STACK *stack , uint8_t *status );
172 double stack_pop_d( STACK *stack , uint8_t *status );
173 void *stack_pop_p( STACK *stack , uint8_t *status );
174
175#ifdef ENV_64BITS
176 bool stack_push_ui64( STACK *stack , uint64_t ui64_t );
177 bool stack_push_i64( STACK *stack , int64_t i64 );
178 uint64_t stack_pop_ui64( STACK *stack , uint8_t *status );
179 int64_t stack_pop_i64( STACK *stack , uint8_t *status );
180#endif
181
186#ifdef __cplusplus
187}
188#endif
189
190#endif
size_t tail
position of tail
Definition n_stack.h:112
bool is_empty
is item set ?
Definition n_stack.h:92
size_t head
position of head
Definition n_stack.h:110
size_t nb_items
number of item inside stack
Definition n_stack.h:114
STACK_ITEM * stack_array
STACK_ITEM array.
Definition n_stack.h:106
int8_t i8
int 8
Definition n_stack.h:67
uint16_t p_type
if v_type is STACK_ITEM_PTR, user defined pointer type
Definition n_stack.h:98
union STACK_DATA data
union of different types
Definition n_stack.h:94
void * p
pointer
Definition n_stack.h:83
double d
double
Definition n_stack.h:81
size_t size
Size of array.
Definition n_stack.h:108
float f
float
Definition n_stack.h:79
char c
single character
Definition n_stack.h:63
int32_t i32
int 32
Definition n_stack.h:71
uint8_t v_type
type of the item
Definition n_stack.h:96
bool b
boolean
Definition n_stack.h:61
bool is_set
is item empty ?
Definition n_stack.h:90
uint32_t ui32
unsigned int 32
Definition n_stack.h:69
uint8_t ui8
unsigned int 8
Definition n_stack.h:65
bool stack_push_f(STACK *stack, float f)
helper to push a float
Definition n_stack.c:467
bool stack_is_empty(STACK *stack)
test if the stack is empty
Definition n_stack.c:61
double stack_pop_d(STACK *stack, uint8_t *status)
helper to pop a double
Definition n_stack.c:536
bool stack_pop_b(STACK *stack, uint8_t *status)
helper to pop a bool
Definition n_stack.c:197
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
STACK_ITEM * stack_peek(STACK *stack, size_t position)
peek in the stack with un stacking the stack item
Definition n_stack.c:72
bool stack_is_full(STACK *stack)
test if the stack is full
Definition n_stack.c:51
bool stack_push_ui32(STACK *stack, uint32_t ui32)
helper to push an uint32_t
Definition n_stack.c:371
int8_t stack_pop_i8(STACK *stack, uint8_t *status)
helper to pop a int8_t
Definition n_stack.c:344
char stack_pop_c(STACK *stack, uint8_t *status)
helper to pop a char
Definition n_stack.c:246
float stack_pop_f(STACK *stack, uint8_t *status)
helper to pop a float
Definition n_stack.c:488
uint8_t stack_pop_ui8(STACK *stack, uint8_t *status)
helper to pop a uint8_t
Definition n_stack.c:296
bool stack_push_c(STACK *stack, char c)
helper to push a char
Definition n_stack.c:225
uint32_t stack_pop_ui32(STACK *stack, uint8_t *status)
helper to pop a uint32_t
Definition n_stack.c:392
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
int32_t stack_pop_i32(STACK *stack, uint8_t *status)
helper to pop a int32_t
Definition n_stack.c:440
bool delete_stack(STACK **stack)
delete a STACK *stack
Definition n_stack.c:38
bool stack_push_i8(STACK *stack, int8_t i8)
helper to push an int8_t
Definition n_stack.c:323
STACK * new_stack(size_t nb_items)
allocate a new STACK
Definition n_stack.c:17
bool stack_push_p(STACK *stack, void *p, uint16_t p_type)
helper to push a pointer
Definition n_stack.c:565
void * stack_pop_p(STACK *stack, uint8_t *status)
helper to pop a pointer
Definition n_stack.c:588
STACK structure.
Definition n_stack.h:104
structure of a STACK item
Definition n_stack.h:88
structure of a STACK_ITEM data
Definition n_stack.h:59
Common headers and low-level hugly functions & define.