diff options
Diffstat (limited to 'libcnary/include')
| -rw-r--r-- | libcnary/include/iterator.h | 33 | ||||
| -rw-r--r-- | libcnary/include/list.h | 24 | ||||
| -rw-r--r-- | libcnary/include/node.h | 59 | ||||
| -rw-r--r-- | libcnary/include/node_iterator.h | 39 | ||||
| -rw-r--r-- | libcnary/include/node_list.h | 31 | ||||
| -rw-r--r-- | libcnary/include/object.h | 25 |
6 files changed, 211 insertions, 0 deletions
diff --git a/libcnary/include/iterator.h b/libcnary/include/iterator.h new file mode 100644 index 0000000..debc1c5 --- /dev/null +++ b/libcnary/include/iterator.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* | ||
| 2 | * iterator.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef ITERATOR_H_ | ||
| 9 | #define ITERATOR_H_ | ||
| 10 | |||
| 11 | struct list_t; | ||
| 12 | struct object_t; | ||
| 13 | |||
| 14 | typedef struct iterator_t { | ||
| 15 | struct object_t*(*next)(struct iterator_t* iterator); | ||
| 16 | int(*bind)(struct iterator_t* iterator, struct list_t* list); | ||
| 17 | |||
| 18 | unsigned int count; | ||
| 19 | unsigned int position; | ||
| 20 | |||
| 21 | struct list_t* list; | ||
| 22 | struct object_t* end; | ||
| 23 | struct object_t* begin; | ||
| 24 | struct object_t* value; | ||
| 25 | } iterator_t; | ||
| 26 | |||
| 27 | void iterator_destroy(struct iterator_t* iterator); | ||
| 28 | struct iterator_t* iterator_create(struct list_t* list); | ||
| 29 | |||
| 30 | struct object_t* iterator_next(struct iterator_t* iterator); | ||
| 31 | int iterator_bind(struct iterator_t* iterator, struct list_t* list); | ||
| 32 | |||
| 33 | #endif /* ITERATOR_H_ */ | ||
diff --git a/libcnary/include/list.h b/libcnary/include/list.h new file mode 100644 index 0000000..237aba0 --- /dev/null +++ b/libcnary/include/list.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * list.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef LIST_H_ | ||
| 9 | #define LIST_H_ | ||
| 10 | |||
| 11 | #include "object.h" | ||
| 12 | |||
| 13 | typedef struct list_t { | ||
| 14 | void* next; | ||
| 15 | void* prev; | ||
| 16 | } list_t; | ||
| 17 | |||
| 18 | void list_init(struct list_t* list); | ||
| 19 | void list_destroy(struct list_t* list); | ||
| 20 | |||
| 21 | int list_add(struct list_t* list, struct object_t* object); | ||
| 22 | int list_remove(struct list_t* list, struct object_t* object); | ||
| 23 | |||
| 24 | #endif /* LIST_H_ */ | ||
diff --git a/libcnary/include/node.h b/libcnary/include/node.h new file mode 100644 index 0000000..35f6333 --- /dev/null +++ b/libcnary/include/node.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* | ||
| 2 | * node.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 7, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef NODE_H_ | ||
| 9 | #define NODE_H_ | ||
| 10 | |||
| 11 | #include "object.h" | ||
| 12 | |||
| 13 | #define NODE_TYPE 1; | ||
| 14 | |||
| 15 | struct node_list_t; | ||
| 16 | |||
| 17 | // This class implements the abstract iterator class | ||
| 18 | typedef struct node_t { | ||
| 19 | // Super class | ||
| 20 | struct node_t* next; | ||
| 21 | struct node_t* prev; | ||
| 22 | unsigned int count; | ||
| 23 | |||
| 24 | // Local Properties | ||
| 25 | int isRoot; | ||
| 26 | int isLeaf; | ||
| 27 | |||
| 28 | // Local Members | ||
| 29 | void *data; | ||
| 30 | unsigned int depth; | ||
| 31 | struct node_t* parent; | ||
| 32 | struct node_list_t* children; | ||
| 33 | |||
| 34 | // Virtual Functions | ||
| 35 | int(*attach)(struct node_t* parent, struct node_t* child); | ||
| 36 | int(*detach)(struct node_t* parent, struct node_t* child); | ||
| 37 | |||
| 38 | } node_t; | ||
| 39 | |||
| 40 | void node_destroy(struct node_t* node); | ||
| 41 | struct node_t* node_create(struct node_t* parent, void* data); | ||
| 42 | |||
| 43 | int node_attach(struct node_t* parent, struct node_t* child); | ||
| 44 | int node_detach(struct node_t* parent, struct node_t* child); | ||
| 45 | int node_insert(struct node_t* parent, unsigned int index, struct node_t* child); | ||
| 46 | |||
| 47 | unsigned int node_n_children(struct node_t* node); | ||
| 48 | node_t* node_nth_child(struct node_t* node, unsigned int n); | ||
| 49 | node_t* node_first_child(struct node_t* node); | ||
| 50 | node_t* node_prev_sibling(struct node_t* node); | ||
| 51 | node_t* node_next_sibling(struct node_t* node); | ||
| 52 | int node_child_position(struct node_t* parent, node_t* child); | ||
| 53 | |||
| 54 | typedef void* (*copy_func_t)(const void *src); | ||
| 55 | node_t* node_copy_deep(node_t* node, copy_func_t copy_func); | ||
| 56 | |||
| 57 | void node_debug(struct node_t* node); | ||
| 58 | |||
| 59 | #endif /* NODE_H_ */ | ||
diff --git a/libcnary/include/node_iterator.h b/libcnary/include/node_iterator.h new file mode 100644 index 0000000..8f39ceb --- /dev/null +++ b/libcnary/include/node_iterator.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /* | ||
| 2 | * node_iterator.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef NODE_ITERATOR_H_ | ||
| 9 | #define NODE_ITERATOR_H_ | ||
| 10 | |||
| 11 | #include "iterator.h" | ||
| 12 | #include "node_list.h" | ||
| 13 | |||
| 14 | // This class implements the abstract iterator class | ||
| 15 | typedef struct node_iterator_t { | ||
| 16 | // Super class | ||
| 17 | struct iterator_t super; | ||
| 18 | |||
| 19 | // Local members | ||
| 20 | struct node_t*(*next)(struct node_iterator_t* iterator); | ||
| 21 | int(*bind)(struct node_iterator_t* iterator, struct node_list_t* list); | ||
| 22 | |||
| 23 | unsigned int count; | ||
| 24 | unsigned int position; | ||
| 25 | |||
| 26 | struct node_list_t* list; | ||
| 27 | struct node_t* end; | ||
| 28 | struct node_t* begin; | ||
| 29 | struct node_t* value; | ||
| 30 | |||
| 31 | } node_iterator_t; | ||
| 32 | |||
| 33 | void node_iterator_destroy(node_iterator_t* iterator); | ||
| 34 | node_iterator_t* node_iterator_create(node_list_t* list); | ||
| 35 | |||
| 36 | struct node_t* node_iterator_next(struct node_iterator_t* iterator); | ||
| 37 | int node_iterator_bind(struct node_iterator_t* iterator, struct node_list_t* list); | ||
| 38 | |||
| 39 | #endif /* NODE_ITERATOR_H_ */ | ||
diff --git a/libcnary/include/node_list.h b/libcnary/include/node_list.h new file mode 100644 index 0000000..bb9fcae --- /dev/null +++ b/libcnary/include/node_list.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* | ||
| 2 | * node_list.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef NODE_LIST_H_ | ||
| 9 | #define NODE_LIST_H_ | ||
| 10 | |||
| 11 | struct node_t; | ||
| 12 | |||
| 13 | // This class implements the list_t abstract class | ||
| 14 | typedef struct node_list_t { | ||
| 15 | // list_t members | ||
| 16 | struct node_t* begin; | ||
| 17 | struct node_t* end; | ||
| 18 | |||
| 19 | // node_list_t members | ||
| 20 | unsigned int count; | ||
| 21 | |||
| 22 | } node_list_t; | ||
| 23 | |||
| 24 | void node_list_destroy(struct node_list_t* list); | ||
| 25 | struct node_list_t* node_list_create(struct node_t* node); | ||
| 26 | |||
| 27 | int node_list_add(node_list_t* list, node_t* node); | ||
| 28 | int node_list_insert(node_list_t* list, unsigned int index, node_t* node); | ||
| 29 | int node_list_remove(node_list_t* list, node_t* node); | ||
| 30 | |||
| 31 | #endif /* NODE_LIST_H_ */ | ||
diff --git a/libcnary/include/object.h b/libcnary/include/object.h new file mode 100644 index 0000000..adf1891 --- /dev/null +++ b/libcnary/include/object.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /* | ||
| 2 | * object.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef OBJECT_H_ | ||
| 9 | #define OBJECT_H_ | ||
| 10 | |||
| 11 | #ifndef TRUE | ||
| 12 | #define TRUE 1 | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #ifndef FALSE | ||
| 16 | #define FALSE 0 | ||
| 17 | #endif | ||
| 18 | |||
| 19 | typedef struct object_t { | ||
| 20 | void* value; | ||
| 21 | unsigned int type; | ||
| 22 | unsigned int size; | ||
| 23 | } object_t; | ||
| 24 | |||
| 25 | #endif /* OBJECT_H_ */ | ||
