7 #define TS_DEFVAL(x) =(x)
13 enum ts_value_type { TS_STRING, TS_NUMBER, TS_VECTOR, TS_ARRAY };
15 /** treestore node attribute value */
17 enum ts_value_type type;
19 char *str; /**< string values will have this set */
20 int inum; /**< numeric values will have this set */
21 float fnum; /**< numeric values will have this set */
23 /** vector values (arrays containing ONLY numbers) will have this set */
24 float *vec; /**< elements of the vector */
25 int vec_size; /**< size of the vector (in elements), same as array_size */
27 /** array values (including vectors) will have this set */
28 struct ts_value *array; /**< elements of the array */
29 int array_size; /**< size of the array (in elements) */
32 int ts_init_value(struct ts_value *tsv);
33 void ts_destroy_value(struct ts_value *tsv);
35 struct ts_value *ts_alloc_value(void); /**< also calls ts_init_value */
36 void ts_free_value(struct ts_value *tsv); /**< also calls ts_destroy_value */
38 /** perform a deep-copy of a ts_value */
39 int ts_copy_value(struct ts_value *dest, struct ts_value *src);
41 /** set a ts_value as a string */
42 int ts_set_value_str(struct ts_value *tsv, const char *str);
44 /** set a ts_value from a list of integers */
45 int ts_set_valuei_arr(struct ts_value *tsv, int count, const int *arr);
46 int ts_set_valueiv(struct ts_value *tsv, int count, ...);
47 int ts_set_valueiv_va(struct ts_value *tsv, int count, va_list ap);
48 int ts_set_valuei(struct ts_value *tsv, int inum); /**< equiv: ts_set_valueiv(val, 1, inum) */
50 /** set a ts_value from a list of floats */
51 int ts_set_valuef_arr(struct ts_value *tsv, int count, const float *arr);
52 int ts_set_valuefv(struct ts_value *tsv, int count, ...);
53 int ts_set_valuefv_va(struct ts_value *tsv, int count, va_list ap);
54 int ts_set_valuef(struct ts_value *tsv, float fnum); /**< equiv: ts_set_valuefv(val, 1, fnum) */
56 /** set a ts_value from a list of ts_value pointers. they are deep-copied as per ts_copy_value */
57 int ts_set_value_arr(struct ts_value *tsv, int count, const struct ts_value *arr);
58 int ts_set_valuev(struct ts_value *tsv, int count, ...);
59 int ts_set_valuev_va(struct ts_value *tsv, int count, va_list ap);
62 /** treestore node attribute */
70 int ts_init_attr(struct ts_attr *attr);
71 void ts_destroy_attr(struct ts_attr *attr);
73 struct ts_attr *ts_alloc_attr(void); /**< also calls ts_init_attr */
74 void ts_free_attr(struct ts_attr *attr); /**< also calls ts_destroy_attr */
76 /** perform a deep-copy of a ts_attr */
77 int ts_copy_attr(struct ts_attr *dest, struct ts_attr *src);
79 int ts_set_attr_name(struct ts_attr *attr, const char *name);
88 struct ts_attr *attr_list, *attr_tail;
91 struct ts_node *child_list, *child_tail;
92 struct ts_node *parent;
94 struct ts_node *next; /* next sibling */
97 int ts_init_node(struct ts_node *node);
98 void ts_destroy_node(struct ts_node *node);
100 struct ts_node *ts_alloc_node(void); /**< also calls ts_init_node */
101 void ts_free_node(struct ts_node *n); /**< also calls ts_destroy_node */
103 /** recursively destroy all the nodes of the tree */
104 void ts_free_tree(struct ts_node *tree);
106 void ts_add_attr(struct ts_node *node, struct ts_attr *attr);
107 struct ts_attr *ts_get_attr(struct ts_node *node, const char *name);
109 const char *ts_get_attr_str(struct ts_node *node, const char *aname,
110 const char *def_val TS_DEFVAL(0));
111 float ts_get_attr_num(struct ts_node *node, const char *aname,
112 float def_val TS_DEFVAL(0.0f));
113 int ts_get_attr_int(struct ts_node *node, const char *aname,
114 int def_val TS_DEFVAL(0.0f));
115 float *ts_get_attr_vec(struct ts_node *node, const char *aname,
116 float *def_val TS_DEFVAL(0));
117 struct ts_value *ts_get_attr_array(struct ts_node *node, const char *aname,
118 struct ts_value *def_val TS_DEFVAL(0));
121 void ts_add_child(struct ts_node *node, struct ts_node *child);
122 int ts_remove_child(struct ts_node *node, struct ts_node *child);
123 struct ts_node *ts_get_child(struct ts_node *node, const char *name);
125 struct ts_node *ts_load(const char *fname);
126 int ts_save(struct ts_node *tree, const char *fname);
128 struct ts_attr *ts_lookup(struct ts_node *root, const char *path);
129 const char *ts_lookup_str(struct ts_node *root, const char *path,
130 const char *def_val TS_DEFVAL(0));
131 float ts_lookup_num(struct ts_node *root, const char *path,
132 float def_val TS_DEFVAL(0.0f));
133 int ts_lookup_int(struct ts_node *root, const char *path,
134 int def_val TS_DEFVAL(0));
135 float *ts_lookup_vec(struct ts_node *root, const char *path,
136 float *def_val TS_DEFVAL(0));
137 struct ts_value *ts_lookup_array(struct ts_node *root, const char *path,
138 struct ts_value *def_val TS_DEFVAL(0));
145 #endif /* TREESTORE_H_ */