comparison th_datastruct.h @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 2ae1045f6c18
children ca837a4417f5
comparison
equal deleted inserted replaced
734:2ae1045f6c18 735:31bc1ed07cf5
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 bool is_allocated; ///< True if this structure has been allocated dynamically
59 void **data; ///< Array of pointers to the data 59 void **data; ///< Array of pointers to the data
60 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)
61 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)
62 void (*deallocator)(void *data); ///< De-allocator function that frees one element. 62 void (*deallocator)(void *data); ///< De-allocator function that frees one element.
63 } th_ringbuf_t; 63 } th_ringbuf_t;
75 #define TH_BUFGROW (32) 75 #define TH_BUFGROW (32)
76 76
77 77
78 /* Simple growing string buffer 78 /* Simple growing string buffer
79 */ 79 */
80 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);
81 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);
82 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);
83 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 84
85 85
86 /** @brief 86 /** @brief
87 * Simple growing buffer structure 87 * Simple growing buffer structure
88 */ 88 */
89 typedef struct 89 typedef struct
90 { 90 {
91 BOOL is_allocated; ///< True if this structure has been allocated dynamically 91 bool is_allocated; ///< True if this structure has been allocated dynamically
92 uint8_t *data; ///< Pointer to data 92 uint8_t *data; ///< Pointer to data
93 size_t size; ///< Current allocated size of data 93 size_t size; ///< Current allocated size of data
94 size_t len; ///< Actual used size of data (must be < size) 94 size_t len; ///< Actual used size of data (must be < size)
95 size_t mingrow; ///< Minimum amount of bytes to grow allocation by 95 size_t mingrow; ///< Minimum amount of bytes to grow allocation by
96 ///< If 0, grow by TH_BUFGROW 96 ///< If 0, grow by TH_BUFGROW
103 void th_growbuf_clear(th_growbuf_t *buf); 103 void th_growbuf_clear(th_growbuf_t *buf);
104 th_growbuf_t *th_growbuf_new(const size_t mingrow); 104 th_growbuf_t *th_growbuf_new(const size_t mingrow);
105 void th_growbuf_free(th_growbuf_t *buf); 105 void th_growbuf_free(th_growbuf_t *buf);
106 106
107 107
108 BOOL th_growbuf_grow(th_growbuf_t *buf, const size_t grow); 108 bool th_growbuf_grow(th_growbuf_t *buf, const size_t grow);
109 BOOL th_growbuf_puts(th_growbuf_t *buf, const char *str, BOOL eos); 109 bool th_growbuf_puts(th_growbuf_t *buf, const char *str, bool eos);
110 BOOL th_growbuf_putch(th_growbuf_t *buf, const char ch); 110 bool th_growbuf_putch(th_growbuf_t *buf, const char ch);
111 BOOL th_growbuf_put_str(th_growbuf_t *buf, const void *s, const size_t len); 111 bool th_growbuf_put_str(th_growbuf_t *buf, const void *s, const size_t len);
112 BOOL th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val); 112 bool th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val);
113 BOOL th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val); 113 bool th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val);
114 BOOL th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val); 114 bool th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val);
115 BOOL th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val); 115 bool th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val);
116 BOOL th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val); 116 bool th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val);
117 117
118 118
119 #ifdef __cplusplus 119 #ifdef __cplusplus
120 } 120 }
121 #endif 121 #endif