1 #if !defined( CSTRING_H )
5 * An implementation of expandable c strings in heap memory.
6 * Copyright (C) 2014 Michael Goehler
8 * This file is part of mdp.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * struct: cstring_t which defines a expandable c string type in heap memory
26 * function: cstring_init to intialize struct of type cstring_t
27 * function: cstring_t->expand to add one character to the struct
28 * function: cstring_t->expand_arr to add a string to the struct
29 * function: cstring_t->reset to clear and reuse the struct
30 * function: cstring_t->delete to free the allocated memory
33 * cstring_t *p = cstring_init();
34 * (p->expand)(p, 'X');
39 // The amount of memory allocated from heap when string expansion hits the
40 // allocated memory limit
41 #define REALLOC_ADD 10
43 typedef struct _cstring_t {
47 void (*expand)(struct _cstring_t *self, char x);
48 void (*expand_arr)(struct _cstring_t *self, char *x);
49 void (*reset)(struct _cstring_t *self);
50 void (*delete)(struct _cstring_t *self);
53 cstring_t *cstring_init();
54 void cstring_expand(cstring_t *self, char x);
55 void cstring_expand_arr(cstring_t *self, char *x);
56 void cstring_reset(cstring_t *self);
57 void cstring_delete(cstring_t *self);
59 #endif // !defined( CSTRING_H )