removed clang-format and clang_complete files from the repo
[dosdemo] / src / darray.h
1 #ifndef DYNAMIC_ARRAY_H_
2 #define DYNAMIC_ARRAY_H_
3
4 void *darr_alloc(int elem, int szelem);
5 void darr_free(void *da);
6 void *darr_resize_impl(void *da, int elem);
7 #define darr_resize(da, elem)   do { (da) = darr_resize_impl(da, elem); } while(0)
8
9 int darr_empty(void *da);
10 int darr_size(void *da);
11
12 void *darr_clear_impl(void *da);
13 #define darr_clear(da)                  do { (da) = darr_clear_impl(da); } while(0)
14
15 /* stack semantics */
16 void *darr_push_impl(void *da, void *item);
17 #define darr_push(da, item)             do { (da) = darr_push_impl(da, item); } while(0)
18 void *darr_pop_impl(void *da);
19 #define darr_pop(da)                    do { (da) = darr_pop_impl(da); } while(0)
20
21 /* Finalize the array. No more resizing is possible after this call.
22  * Use free() instead of dynarr_free() to deallocate a finalized array.
23  * Returns pointer to the finalized array.
24  * Complexity: O(n)
25  */
26 void *darr_finalize(void *da);
27
28 /* utility macros to push characters to a string. assumes and maintains
29  * the invariant that the last element is always a zero
30  */
31 #define darr_strpush(da, c) \
32         do { \
33                 char cnull = 0, ch = (char)(c); \
34                 (da) = dynarr_pop_impl(da); \
35                 (da) = dynarr_push_impl((da), &ch); \
36                 (da) = dynarr_push_impl((da), &cnull); \
37         } while(0)
38
39 #define darr_strpop(da) \
40         do { \
41                 char cnull = 0; \
42                 (da) = dynarr_pop_impl(da); \
43                 (da) = dynarr_pop_impl(da); \
44                 (da) = dynarr_push_impl((da), &cnull); \
45         } while(0)
46
47
48 #endif  /* DYNAMIC_ARRAY_H_ */