removed duplicate function + added some comments to 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 struct
11  * function: cstring_t->expand_arr to add a string to the struct
12  * function: cstring_t->reset to clear and reuse the struct
13  * function: cstring_t->delete to free the allocated memory
14  *
15  * Example:
16  *      cstring_t *p = cstring_init();
17  *      (p->expand)(p, 'X');
18  *      (p->delete)(p);
19  *
20  */
21
22 // The amount of memory allocated from heap when string expansion hits the
23 // allocated memory limit
24 #define REALLOC_ADD 10
25
26 typedef struct _cstring_t {
27     char *text;
28     size_t size;
29     size_t alloc;
30     void (*expand)(struct _cstring_t *self, char x);
31     void (*expand_arr)(struct _cstring_t *self, char *x);
32     void (*reset)(struct _cstring_t *self);
33     void (*delete)(struct _cstring_t *self);
34 } cstring_t;
35
36 cstring_t *cstring_init();
37 void cstring_expand(cstring_t *self, char x);
38 void cstring_expand_arr(cstring_t *self, char *x);
39 void cstring_reset(cstring_t *self);
40 void cstring_delete(cstring_t *self);
41
42 #endif // !defined( CSTRING_H )