removed duplicate function + added some comments to header files
[smdp.git] / include / cstack.h
1 #if !defined( CSTACK_H )
2 #define CSTACK_H
3
4 /*
5  * A implementation of a char stack in heap memory.
6  *
7  * struct: cstack_t which defines char stack type in heap memory
8  *
9  * function: cstack_init to intialize struct of type cstack_t
10  * function: cstack_t->push to add one char on top if the stack
11  * function: cstack_t->pop to remove the top char from the stack
12  * function: cstack_t->top to test if the top char is a given char
13  * function: cstack_t->empty to test if the stack is empty
14  * function: cstack_t->delete to free the allocated memory
15  *
16  * Example:
17  *      cstack_t *p = cstack_init();
18  *      (p->push)(p, 'X');
19  *      printf("%c\n", (p->pop)(p));
20  *      (p->delete)(p);
21  *
22  */
23
24 typedef struct _cstack_t {
25     char *content;
26     size_t alloc;
27     size_t size;
28     int head;
29     void (*push)(struct _cstack_t *self, char c);
30     char (*pop)(struct _cstack_t *self);
31     int (*top)(struct _cstack_t *self, char c);
32     int (*empty)(struct _cstack_t *self);
33     void (*delete)(struct _cstack_t *self);
34 } cstack_t;
35
36 cstack_t *cstack_init();
37 void cstack_push(cstack_t *self, char c);
38 char cstack_pop(cstack_t *self);
39 int cstack_top(cstack_t *self, char c);
40 int cstack_empty(cstack_t *self);
41 void cstack_delete(cstack_t *self);
42
43 #endif // !defined( CSTACK_H )