gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
gwion_text.h
Go to the documentation of this file.
1
4#pragma once
5
7typedef struct GwText_ {
9 size_t cap;
10 size_t len;
13
15ANN void text_add(GwText *, const char *);
16
17ANN static inline void text_init(GwText *text, MemPool mp) {
18 text->mp = mp;
19 text->str = (m_str)mp_malloc2(mp, 64);
20 text->len = 0;
21 text->cap = 64;
22}
23
25ANN static inline void text_release(GwText *text) {
26 if (text->str) {
27 mp_free2(text->mp, text->cap, text->str);
28 text->str = NULL;
29 text->cap = text->len = 0;
30 }
31}
32
33ANN static inline GwText *new_text(MemPool mp) {
34 GwText *text = (GwText *)mp_calloc(mp, GwText);
35 text_init(text, mp);
36 return text;
37}
38
39ANN static inline void free_text(GwText *text) {
40 text_release(text);
41 mp_free(text->mp, GwText, text);
42}
43
45ANN static inline void text_reset(GwText *text) {
46 if (text->str) {
47 *text->str = '\0';
48 text->len = 0;
49 }
50}
#define ANN
Definition defs.h:18
char * m_str
Definition gwcommon.h:15
static ANN void text_init(GwText *text, MemPool mp)
Definition gwion_text.h:17
static ANN void text_reset(GwText *text)
reset text
Definition gwion_text.h:45
static ANN void free_text(GwText *text)
Definition gwion_text.h:39
static ANN void text_release(GwText *text)
release text memory
Definition gwion_text.h:25
ANN void text_add(GwText *, const char *)
append to text
Definition text.c:12
struct GwText_ GwText
mp_allocted text
static ANN GwText * new_text(MemPool mp)
Definition gwion_text.h:33
#define mp_free2(p, sz, a)
Definition mpool.h:26
#define mp_calloc(p, name)
Definition mpool.h:24
#define mp_free(p, name, a)
Definition mpool.h:25
struct MemPool_ * MemPool
#define mp_malloc2(p, sz)
Definition mpool.h:28
mp_allocted text
Definition gwion_text.h:7
size_t len
Definition gwion_text.h:10
size_t cap
Definition gwion_text.h:9
m_str str
Definition gwion_text.h:8
MemPool mp
Definition gwion_text.h:11