-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.h
44 lines (32 loc) · 1.12 KB
/
mem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef SMPL_MEM_H
#define SMPL_MEM_H
/*
*
* Vector operations
*
*/
#define spM_vector_push(v,t,i) ((v)[(t)++] = (i)) /* push an item 'i' into the vector 'v' with it's top index being 't' */
#define spM_vector_pop(v,t) ((v)[--(t)]) /* pop the top item from vector 'v' with it's top index being 't' */
/*
** Check if an vector 'v' with top 't' and capacity 'c' is admissible.
** If it is then push an item 'i' into it,
** otherwise PUSH an error on line 'ln' with error code 'ec'
*/
#define spM_check_push(S,v,t,c,ln,ec,i) \
if(spM_check_admissible((S), (t), (c), (ln), (ec))) \
spM_vector_push((v), (t), (i))
/*
** Check if an vector 't' with top 't' and capacity 'c' is admissible.
** If it is then push an item 'i' into it,
** otherwise THROW an error on line 'ln' with error code 'ec'
*/
#define spM_assert_push(S,v,t,c,ln,ec,i) \
(spM_check_admissible((S), (t), (c), (ln), (ec)), \
spM_vector_push((v), (t), (i)))
/*
*
* Allocation helpers
*
*/
#define spM_alloc_sizeof(S,e) (spM_alloc((S), sizeof (e))) /* allocate memory for the given element 'e' */
#endif // SMPL_MEM_H