byte_array.h
| 1 | #ifndef CUTILS_BYTE_ARRAY_H |
| 2 | #define CUTILS_BYTE_ARRAY_H |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | #include <cutils/common.h> |
| 7 | |
| 8 | #define BYTEARRAY_DEFAULT_SIZE 4 |
| 9 | |
| 10 | typedef struct Bytearray |
| 11 | { |
| 12 | byte* items; |
| 13 | size_t capacity; |
| 14 | size_t length; |
| 15 | size_t element_size; |
| 16 | } Bytearray; |
| 17 | |
| 18 | #define new_bytearray(element_size) bytearray_with_capacity(BYTEARRAY_DEFAULT_SIZE, element_size) |
| 19 | Bytearray* bytearray_with_capacity(size_t capacity, size_t element_size); |
| 20 | void delete_bytearray(Bytearray* bytearray, void(*rmv_el) (void*)); |
| 21 | |
| 22 | void* bytearray_at(const Bytearray* bytearray, size_t index); |
| 23 | #define bytearray_pop(bytearray, retptr) bytearray_pop_at(bytearray, bytearray->length-1, retptr) |
| 24 | void* bytearray_pop_at(Bytearray* bytearray, size_t index, void* retptr); |
| 25 | |
| 26 | #define bytearray_push(bytearray, item) bytearray_insert(bytearray, bytearray->length, item) |
| 27 | bool bytearray_insert(Bytearray* bytearray, size_t index, const void* item); |
| 28 | |
| 29 | void bytearray_remove(Bytearray* bytearray, size_t index, void (*rmv)(void*)); |
| 30 | |
| 31 | bool bytearray_adjust_size(Bytearray* bytearray, size_t size); |
| 32 | bool bytearray_shrink(Bytearray* bytearray); |
| 33 | HEDLEY_NON_NULL(3) |
| 34 | size_t* bytearray_find(const Bytearray* haystack, const void* needle, int (*cmp)(const void*, const void*)); |
| 35 | |
| 36 | |
| 37 | #endif /* CUTILS_BYTE_ARRAY_H */ |
| 38 | |
| 39 |