Mercurial > hg > th-libs
comparison th_datastruct.h @ 734:2ae1045f6c18
Improve documentation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 11:58:54 +0200 |
parents | 79d06eb6d39f |
children | 31bc1ed07cf5 |
comparison
equal
deleted
inserted
replaced
733:79d06eb6d39f | 734:2ae1045f6c18 |
---|---|
53 /** @brief | 53 /** @brief |
54 * Ringbuffer data structure | 54 * Ringbuffer data structure |
55 */ | 55 */ |
56 typedef struct | 56 typedef struct |
57 { | 57 { |
58 BOOL is_allocated; ///< True if this structure has been allocated dynamically | |
58 void **data; ///< Array of pointers to the data | 59 void **data; ///< Array of pointers to the data |
59 size_t size; ///< Size of this ringbuffer in elements (aka pointers to data) | 60 size_t size; ///< Size of this ringbuffer in elements (aka pointers to data) |
60 size_t n; ///< Number of elements currently in the ringbuffer (@p n <= @p size) | 61 size_t n; ///< Number of elements currently in the ringbuffer (@p n <= @p size) |
61 void (*deallocator)(void *data); ///< De-allocator function that frees one element. | 62 void (*deallocator)(void *data); ///< De-allocator function that frees one element. |
62 BOOL is_allocated; | |
63 } th_ringbuf_t; | 63 } th_ringbuf_t; |
64 | 64 |
65 | 65 |
66 int th_ringbuf_init(th_ringbuf_t *buf, const size_t size, void (*mdeallocator)(void *data)); | 66 int th_ringbuf_init(th_ringbuf_t *buf, const size_t size, void (*mdeallocator)(void *data)); |
67 int th_ringbuf_new(th_ringbuf_t **buf, const size_t size, void (*mdeallocator)(void *data)); | 67 int th_ringbuf_new(th_ringbuf_t **buf, const size_t size, void (*mdeallocator)(void *data)); |
73 /* Growing buffers | 73 /* Growing buffers |
74 */ | 74 */ |
75 #define TH_BUFGROW (32) | 75 #define TH_BUFGROW (32) |
76 | 76 |
77 | 77 |
78 typedef struct | |
79 { | |
80 BOOL is_allocated; | |
81 uint8_t *data; | |
82 size_t size, len, mingrow; | |
83 } th_growbuf_t; | |
84 | |
85 | |
86 /* Simple growing string buffer | 78 /* Simple growing string buffer |
87 */ | 79 */ |
88 BOOL th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, const size_t grow); | 80 BOOL th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, const size_t grow); |
89 BOOL th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const uint8_t ch); | 81 BOOL th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const uint8_t ch); |
90 BOOL th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen); | 82 BOOL th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen); |
91 BOOL th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str); | 83 BOOL th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str); |
84 | |
85 | |
86 /** @brief | |
87 * Simple growing buffer structure | |
88 */ | |
89 typedef struct | |
90 { | |
91 BOOL is_allocated; ///< True if this structure has been allocated dynamically | |
92 uint8_t *data; ///< Pointer to data | |
93 size_t size; ///< Current allocated size of data | |
94 size_t len; ///< Actual used size of data (must be < size) | |
95 size_t mingrow; ///< Minimum amount of bytes to grow allocation by | |
96 ///< If 0, grow by TH_BUFGROW | |
97 } th_growbuf_t; | |
92 | 98 |
93 | 99 |
94 /* Growing byte buffer | 100 /* Growing byte buffer |
95 */ | 101 */ |
96 void th_growbuf_init(th_growbuf_t *buf, const size_t mingrow); | 102 void th_growbuf_init(th_growbuf_t *buf, const size_t mingrow); |