refactoring: only function prototypes belong in header files
[smdp.git] / include / cstring.h
1 #if !defined( CSTRING_H )
2 #define CSTRING_H
3
4 /*
5  * A implementation of expandable c strings in heap memory.
6  *
7  * struct: cstring_t which defines a expandable c string type in heap memory
8  *
9  * function: cstring_init to intialize struct of type cstring_t
10  * function: cstring_t->expand to add one character to the string
11  * function: cstring_t->delete to free the allocated memory
12  *
13  * Example:
14  *      cstring_t *p = cstring_init();
15  *      (p->expand)(p, 'X');
16  *      (p->delete)(p);
17  *
18  */
19
20 // The amount of memory allocated from heap when string expansion hits the
21 // allocated memory limit
22 #define REALLOC_ADD 10
23
24 typedef struct _cstring_t {
25     char *text;
26     size_t size;
27     size_t alloc;
28     void (*expand)(struct _cstring_t *self, char x);
29     void (*expand_arr)(struct _cstring_t *self, char *x);
30     void (*reset)(struct _cstring_t *self);
31     void (*delete)(struct _cstring_t *self);
32 } cstring_t;
33
34 cstring_t *cstring_init();
35 void cstring_expand(cstring_t *self, char x);
36 void cstring_expand_arr(cstring_t *self, char *x);
37 void cstring_reset(cstring_t *self);
38 void cstring_delete(cstring_t *self);
39
40 #endif // !defined( CSTRING_H )