libtreestore

view src/treestore.h @ 0:740fec9866b1

treestore initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 11 Apr 2014 08:56:46 +0300
parents
children a31eae25c0e6
line source
1 #ifndef TREESTORE_H_
2 #define TREESTORE_H_
4 #include <stdarg.h>
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 enum ts_value_type { TS_UNKNOWN, TS_NUMBER, TS_VECTOR, TS_ARRAY };
12 /** treestore node attribute value */
13 struct ts_value {
14 enum ts_value_type type;
16 char *str; /**< all values have a string representation */
17 int inum; /**< numeric values (TS_INT/TS_FLOAT) will have this set */
18 float fnum; /**< numeric values (TS_INT/TS_FLOAT) will have this set */
20 /** vector values (arrays containing ONLY numbers) will have this set */
21 float *vec; /**< elements of the vector */
22 int vec_size; /**< size of the vector (in elements), same as array_size */
24 /** array values (including vectors) will have this set */
25 struct ts_value *array; /**< elements of the array */
26 int array_size; /**< size of the array (in elements) */
27 };
29 int ts_init_value(struct ts_value *tsv);
30 void ts_destroy_value(struct ts_value *tsv);
32 struct ts_value *ts_alloc_value(void); /**< also calls ts_init_value */
33 void ts_free_value(struct ts_value *tsv); /**< also calls ts_destroy_value */
35 /** perform a deep-copy of a ts_value */
36 int ts_copy_value(struct ts_value *dest, struct ts_value *src);
38 /** ts_set_value will try to parse the string and initialize the value type fields */
39 int ts_set_value(struct ts_value *tsv, const char *str);
41 /** set a ts_value from a list of integers */
42 int ts_set_valueiv(struct ts_value *tsv, int count, ...);
43 int ts_set_valueiv_va(struct ts_value *tsv, int count, va_list ap);
44 int ts_set_valuei(struct ts_value *tsv, int inum); /**< equiv: ts_set_valueiv(val, 1, inum) */
46 /** set a ts_value from a list of floats */
47 int ts_set_valuefv(struct ts_value *tsv, int count, ...);
48 int ts_set_valuefv_va(struct ts_value *tsv, int count, va_list ap);
49 int ts_set_valuef(struct ts_value *tsv, int fnum); /**< equiv: ts_set_valuefv(val, 1, fnum) */
51 /** set a ts_value from a list of ts_value pointers. they are deep-copied as per ts_copy_value */
52 int ts_set_valuev(struct ts_value *tsv, int count, ...);
53 int ts_set_valuev_va(struct ts_value *tsv, int count, va_list ap);
56 /** treestore node attribute */
57 struct ts_attr {
58 char *name;
60 struct ts_value val;
62 struct ts_attr *next;
63 };
66 /** treestore node */
67 struct ts_node {
68 char *name;
70 int attr_count;
71 struct ts_attr *attr_list, *attr_tail;
73 int child_count;
74 struct ts_node *child_list, *child_tail;
75 struct ts_node *parent;
77 struct ts_node *next; /* next sibling */
78 };
80 struct ts_node *ts_create_node(void);
81 void ts_free_node(struct ts_node *n);
82 void ts_free_tree(struct ts_node *tree);
84 #ifdef __cplusplus
85 }
86 #endif
88 #endif /* TREESTORE_H_ */