Changeset 5f679702 in mainline for uspace/app/bithenge/tree.h
 Timestamp:
 20120607T04:03:16Z (9 years ago)
 Branches:
 lfn, master
 Children:
 5c925ce
 Parents:
 520acaf
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

uspace/app/bithenge/tree.h
r520acaf r5f679702 62 62 typedef struct bithenge_node_t { 63 63 bithenge_node_type_t type; 64 union { 65 struct bithenge_internal_node_ops_t *internal_ops; 66 bool boolean_value; 67 bithenge_int_t integer_value; 68 struct { 69 const char *ptr; 70 bool needs_free; 71 } string_value; 72 }; 64 73 } bithenge_node_t; 65 74 … … 71 80 typedef int (*bithenge_for_each_func_t)(bithenge_node_t *key, bithenge_node_t *value, void *data); 72 81 73 typedef struct {74 bithenge_node_t base;75 const struct bithenge_internal_node_ops_t *ops;76 } bithenge_internal_node_t;77 78 82 typedef struct bithenge_internal_node_ops_t { 79 int (*for_each)(bithenge_ internal_node_t *node, bithenge_for_each_func_t func, void *data);83 int (*for_each)(bithenge_node_t *node, bithenge_for_each_func_t func, void *data); 80 84 } bithenge_internal_node_ops_t; 81 85 82 typedef struct { 83 bithenge_node_t base; 84 bool value; 85 } bithenge_boolean_node_t; 86 87 typedef struct { 88 bithenge_node_t base; 89 bithenge_int_t value; 90 } bithenge_integer_node_t; 91 92 typedef struct { 93 bithenge_node_t base; 94 const char *value; 95 bool needs_free; 96 } bithenge_string_node_t; 97 98 static inline bithenge_node_t *bithenge_internal_as_node(bithenge_internal_node_t *node) 86 static inline int bithenge_node_for_each(bithenge_node_t *node, bithenge_for_each_func_t func, void *data) 99 87 { 100 return &node>base;88 return node>internal_ops>for_each(node, func, data); 101 89 } 102 90 103 static inline b ithenge_internal_node_t *bithenge_as_internal_node(bithenge_node_t *node)91 static inline bool bithenge_boolean_node_value(bithenge_node_t *node) 104 92 { 105 assert(node>type == BITHENGE_NODE_INTERNAL); 106 return (bithenge_internal_node_t *)node; 93 return node>boolean_value; 107 94 } 108 95 109 static inline int bithenge_node_for_each(bithenge_internal_node_t *node, bithenge_for_each_func_t func, void *data)96 static inline bithenge_int_t bithenge_integer_node_value(bithenge_node_t *node) 110 97 { 111 return node> ops>for_each(node, func, data);98 return node>integer_value; 112 99 } 113 100 114 static inline bithenge_node_t *bithenge_boolean_as_node(bithenge_boolean_node_t *node)101 static inline const char *bithenge_string_node_value(bithenge_node_t *node) 115 102 { 116 return &node>base; 117 } 118 119 static inline bithenge_boolean_node_t *bithenge_as_boolean_node(bithenge_node_t *node) 120 { 121 assert(node>type == BITHENGE_NODE_BOOLEAN); 122 return (bithenge_boolean_node_t *)node; 123 } 124 125 static inline bool bithenge_boolean_node_value(bithenge_boolean_node_t *node) 126 { 127 return node>value; 128 } 129 130 static inline bithenge_node_t *bithenge_integer_as_node(bithenge_integer_node_t *node) 131 { 132 return &node>base; 133 } 134 135 static inline bithenge_integer_node_t *bithenge_as_integer_node(bithenge_node_t *node) 136 { 137 assert(node>type == BITHENGE_NODE_INTEGER); 138 return (bithenge_integer_node_t *)node; 139 } 140 141 static inline bithenge_int_t bithenge_integer_node_value(bithenge_integer_node_t *node) 142 { 143 return node>value; 144 } 145 146 static inline bithenge_node_t *bithenge_string_as_node(bithenge_string_node_t *node) 147 { 148 return &node>base; 149 } 150 151 static inline bithenge_string_node_t *bithenge_as_string_node(bithenge_node_t *node) 152 { 153 assert(node>type == BITHENGE_NODE_STRING); 154 return (bithenge_string_node_t *)node; 155 } 156 157 static inline const char *bithenge_string_node_value(bithenge_string_node_t *node) 158 { 159 return node>value; 103 return node>string_value.ptr; 160 104 } 161 105
Note: See TracChangeset
for help on using the changeset viewer.