rev |
line source |
nuclear@0
|
1 #ifndef TREESTORE_H_
|
nuclear@0
|
2 #define TREESTORE_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 #include <stdarg.h>
|
nuclear@0
|
5
|
nuclear@0
|
6 #ifdef __cplusplus
|
nuclear@0
|
7 extern "C" {
|
nuclear@0
|
8 #endif
|
nuclear@0
|
9
|
nuclear@0
|
10 enum ts_value_type { TS_UNKNOWN, TS_NUMBER, TS_VECTOR, TS_ARRAY };
|
nuclear@0
|
11
|
nuclear@0
|
12 /** treestore node attribute value */
|
nuclear@0
|
13 struct ts_value {
|
nuclear@0
|
14 enum ts_value_type type;
|
nuclear@0
|
15
|
nuclear@0
|
16 char *str; /**< all values have a string representation */
|
nuclear@3
|
17 int inum; /**< numeric values TS_NUMBER will have this set */
|
nuclear@3
|
18 float fnum; /**< numeric values TS_NUMBER will have this set */
|
nuclear@0
|
19
|
nuclear@0
|
20 /** vector values (arrays containing ONLY numbers) will have this set */
|
nuclear@0
|
21 float *vec; /**< elements of the vector */
|
nuclear@0
|
22 int vec_size; /**< size of the vector (in elements), same as array_size */
|
nuclear@0
|
23
|
nuclear@0
|
24 /** array values (including vectors) will have this set */
|
nuclear@0
|
25 struct ts_value *array; /**< elements of the array */
|
nuclear@0
|
26 int array_size; /**< size of the array (in elements) */
|
nuclear@0
|
27 };
|
nuclear@0
|
28
|
nuclear@0
|
29 int ts_init_value(struct ts_value *tsv);
|
nuclear@0
|
30 void ts_destroy_value(struct ts_value *tsv);
|
nuclear@0
|
31
|
nuclear@0
|
32 struct ts_value *ts_alloc_value(void); /**< also calls ts_init_value */
|
nuclear@0
|
33 void ts_free_value(struct ts_value *tsv); /**< also calls ts_destroy_value */
|
nuclear@0
|
34
|
nuclear@0
|
35 /** perform a deep-copy of a ts_value */
|
nuclear@0
|
36 int ts_copy_value(struct ts_value *dest, struct ts_value *src);
|
nuclear@0
|
37
|
nuclear@0
|
38 /** ts_set_value will try to parse the string and initialize the value type fields */
|
nuclear@0
|
39 int ts_set_value(struct ts_value *tsv, const char *str);
|
nuclear@0
|
40
|
nuclear@0
|
41 /** set a ts_value from a list of integers */
|
nuclear@0
|
42 int ts_set_valueiv(struct ts_value *tsv, int count, ...);
|
nuclear@0
|
43 int ts_set_valueiv_va(struct ts_value *tsv, int count, va_list ap);
|
nuclear@0
|
44 int ts_set_valuei(struct ts_value *tsv, int inum); /**< equiv: ts_set_valueiv(val, 1, inum) */
|
nuclear@0
|
45
|
nuclear@0
|
46 /** set a ts_value from a list of floats */
|
nuclear@0
|
47 int ts_set_valuefv(struct ts_value *tsv, int count, ...);
|
nuclear@0
|
48 int ts_set_valuefv_va(struct ts_value *tsv, int count, va_list ap);
|
nuclear@0
|
49 int ts_set_valuef(struct ts_value *tsv, int fnum); /**< equiv: ts_set_valuefv(val, 1, fnum) */
|
nuclear@0
|
50
|
nuclear@0
|
51 /** set a ts_value from a list of ts_value pointers. they are deep-copied as per ts_copy_value */
|
nuclear@0
|
52 int ts_set_valuev(struct ts_value *tsv, int count, ...);
|
nuclear@0
|
53 int ts_set_valuev_va(struct ts_value *tsv, int count, va_list ap);
|
nuclear@0
|
54
|
nuclear@0
|
55
|
nuclear@0
|
56 /** treestore node attribute */
|
nuclear@0
|
57 struct ts_attr {
|
nuclear@0
|
58 char *name;
|
nuclear@0
|
59 struct ts_value val;
|
nuclear@0
|
60
|
nuclear@0
|
61 struct ts_attr *next;
|
nuclear@0
|
62 };
|
nuclear@0
|
63
|
nuclear@1
|
64 int ts_init_attr(struct ts_attr *attr);
|
nuclear@1
|
65 void ts_destroy_attr(struct ts_attr *attr);
|
nuclear@1
|
66
|
nuclear@1
|
67 struct ts_attr *ts_alloc_attr(void); /**< also calls ts_init_attr */
|
nuclear@1
|
68 void ts_free_attr(struct ts_attr *attr); /**< also calls ts_destroy_attr */
|
nuclear@1
|
69
|
nuclear@1
|
70 /** perform a deep-copy of a ts_attr */
|
nuclear@1
|
71 int ts_copy_attr(struct ts_attr *dest, struct ts_attr *src);
|
nuclear@1
|
72
|
nuclear@1
|
73 int ts_set_attr_name(struct ts_attr *attr, const char *name);
|
nuclear@1
|
74
|
nuclear@1
|
75
|
nuclear@0
|
76
|
nuclear@0
|
77 /** treestore node */
|
nuclear@0
|
78 struct ts_node {
|
nuclear@0
|
79 char *name;
|
nuclear@0
|
80
|
nuclear@0
|
81 int attr_count;
|
nuclear@0
|
82 struct ts_attr *attr_list, *attr_tail;
|
nuclear@0
|
83
|
nuclear@0
|
84 int child_count;
|
nuclear@0
|
85 struct ts_node *child_list, *child_tail;
|
nuclear@0
|
86 struct ts_node *parent;
|
nuclear@0
|
87
|
nuclear@0
|
88 struct ts_node *next; /* next sibling */
|
nuclear@0
|
89 };
|
nuclear@0
|
90
|
nuclear@1
|
91 int ts_init_node(struct ts_node *node);
|
nuclear@1
|
92 void ts_destroy_node(struct ts_node *node);
|
nuclear@1
|
93
|
nuclear@1
|
94 struct ts_node *ts_alloc_node(void); /**< also calls ts_init_node */
|
nuclear@1
|
95 void ts_free_node(struct ts_node *n); /**< also calls ts_destroy_node */
|
nuclear@1
|
96
|
nuclear@3
|
97 /** recursively destroy all the nodes of the tree */
|
nuclear@0
|
98 void ts_free_tree(struct ts_node *tree);
|
nuclear@0
|
99
|
nuclear@3
|
100 void ts_add_attr(struct ts_node *node, struct ts_attr *attr);
|
nuclear@3
|
101 struct ts_attr *ts_get_attr(struct ts_node *node, const char *name);
|
nuclear@3
|
102
|
nuclear@3
|
103 void ts_add_child(struct ts_node *node, struct ts_node *child);
|
nuclear@3
|
104 int ts_remove_child(struct ts_node *node, struct ts_node *child);
|
nuclear@3
|
105 struct ts_node *ts_get_child(struct ts_node *node, const char *name);
|
nuclear@3
|
106
|
nuclear@3
|
107 struct ts_node *ts_load(const char *fname);
|
nuclear@3
|
108 int ts_save(struct ts_node *tree, const char *fname);
|
nuclear@3
|
109
|
nuclear@0
|
110 #ifdef __cplusplus
|
nuclear@0
|
111 }
|
nuclear@0
|
112 #endif
|
nuclear@0
|
113
|
nuclear@0
|
114 #endif /* TREESTORE_H_ */
|