2 * The MIT License (MIT)
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 /* From value-const.h */
27 typedef enum bt_value_status {
28 /// Operation canceled.
29 BT_VALUE_STATUS_CANCELED = 125,
31 /// Cannot allocate memory.
32 BT_VALUE_STATUS_NOMEM = -12,
35 BT_VALUE_STATUS_OK = 0,
38 typedef enum bt_value_type {
39 /// Null value object.
40 BT_VALUE_TYPE_NULL = 0,
42 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
43 BT_VALUE_TYPE_BOOL = 1,
45 /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
46 BT_VALUE_TYPE_UNSIGNED_INTEGER = 2,
48 /// Signed integer value object (holds a signed 64-bit integer raw value).
49 BT_VALUE_TYPE_SIGNED_INTEGER = 3,
51 /// Floating point number value object (holds a \c double raw value).
52 BT_VALUE_TYPE_REAL = 4,
54 /// String value object.
55 BT_VALUE_TYPE_STRING = 5,
57 /// Array value object.
58 BT_VALUE_TYPE_ARRAY = 6,
61 BT_VALUE_TYPE_MAP = 7,
64 extern bt_value_type bt_value_get_type(const bt_value *object);
66 extern bt_value_status bt_value_copy(const bt_value *object,
69 extern bt_bool bt_value_compare(const bt_value *object_a,
70 const bt_value *object_b);
72 extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
74 extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
76 extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
78 extern double bt_value_real_get(const bt_value *real_obj);
80 extern const char *bt_value_string_get(const bt_value *string_obj);
82 extern uint64_t bt_value_array_get_size(const bt_value *array_obj);
84 extern const bt_value *bt_value_array_borrow_element_by_index_const(
85 const bt_value *array_obj, uint64_t index);
87 extern uint64_t bt_value_map_get_size(const bt_value *map_obj);
89 extern const bt_value *bt_value_map_borrow_entry_value_const(
90 const bt_value *map_obj, const char *key);
92 typedef bt_bool (* bt_value_map_foreach_entry_const_func)(const char *key,
93 const bt_value *object, void *data);
95 extern bt_value_status bt_value_map_foreach_entry_const(
96 const bt_value *map_obj,
97 bt_value_map_foreach_entry_const_func func, void *data);
99 extern bt_bool bt_value_map_has_entry(const bt_value *map_obj,
102 extern bt_value_status bt_value_map_extend(
103 const bt_value *base_map_obj,
104 const bt_value *extension_map_obj,
105 bt_value **extended_map_obj);
107 extern void bt_value_get_ref(const bt_value *value);
109 extern void bt_value_put_ref(const bt_value *value);
113 extern bt_value *const bt_value_null;
115 extern bt_value *bt_value_bool_create(void);
117 extern bt_value *bt_value_bool_create_init(bt_bool val);
119 extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
121 extern bt_value *bt_value_unsigned_integer_create(void);
123 extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
125 extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
127 extern bt_value *bt_value_signed_integer_create(void);
129 extern bt_value *bt_value_signed_integer_create_init(int64_t val);
131 extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
133 extern bt_value *bt_value_real_create(void);
135 extern bt_value *bt_value_real_create_init(double val);
137 extern void bt_value_real_set(bt_value *real_obj, double val);
139 extern bt_value *bt_value_string_create(void);
141 extern bt_value *bt_value_string_create_init(const char *val);
143 extern bt_value_status bt_value_string_set(bt_value *string_obj,
146 extern bt_value *bt_value_array_create(void);
148 extern bt_value *bt_value_array_borrow_element_by_index(
149 bt_value *array_obj, uint64_t index);
151 extern bt_value_status bt_value_array_append_element(
153 bt_value *element_obj);
155 extern bt_value_status bt_value_array_append_bool_element(
156 bt_value *array_obj, bt_bool val);
158 extern bt_value_status bt_value_array_append_unsigned_integer_element(
159 bt_value *array_obj, uint64_t val);
161 extern bt_value_status bt_value_array_append_signed_integer_element(
162 bt_value *array_obj, int64_t val);
164 extern bt_value_status bt_value_array_append_real_element(
165 bt_value *array_obj, double val);
167 extern bt_value_status bt_value_array_append_string_element(
168 bt_value *array_obj, const char *val);
170 extern bt_value_status bt_value_array_append_empty_array_element(
171 bt_value *array_obj);
173 extern bt_value_status bt_value_array_append_empty_map_element(
174 bt_value *array_obj);
176 extern bt_value_status bt_value_array_set_element_by_index(
177 bt_value *array_obj, uint64_t index,
178 bt_value *element_obj);
180 extern bt_value *bt_value_map_create(void);
182 extern bt_value *bt_value_map_borrow_entry_value(
183 bt_value *map_obj, const char *key);
185 typedef bt_bool (* bt_value_map_foreach_entry_func)(const char *key,
186 bt_value *object, void *data);
188 extern bt_value_status bt_value_map_foreach_entry(
190 bt_value_map_foreach_entry_func func, void *data);
192 extern bt_value_status bt_value_map_insert_entry(
193 bt_value *map_obj, const char *key,
194 bt_value *element_obj);
196 extern bt_value_status bt_value_map_insert_bool_entry(
197 bt_value *map_obj, const char *key, bt_bool val);
199 extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
200 bt_value *map_obj, const char *key, uint64_t val);
202 extern bt_value_status bt_value_map_insert_signed_integer_entry(
203 bt_value *map_obj, const char *key, int64_t val);
205 extern bt_value_status bt_value_map_insert_real_entry(
206 bt_value *map_obj, const char *key, double val);
208 extern bt_value_status bt_value_map_insert_string_entry(
209 bt_value *map_obj, const char *key,
212 extern bt_value_status bt_value_map_insert_empty_array_entry(
213 bt_value *map_obj, const char *key);
215 extern bt_value_status bt_value_map_insert_empty_map_entry(
216 bt_value *map_obj, const char *key);
219 struct bt_value_map_get_keys_data {
220 struct bt_value *keys;
223 static int bt_value_map_get_keys_cb(const char *key, const struct bt_value *object, void *data)
225 enum bt_value_status status;
226 struct bt_value_map_get_keys_data *priv_data = data;
228 status = bt_value_array_append_string_element(priv_data->keys, key);
229 if (status != BT_VALUE_STATUS_OK) {
236 static struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj)
238 enum bt_value_status status;
239 struct bt_value_map_get_keys_data data;
241 data.keys = bt_value_array_create();
246 status = bt_value_map_foreach_entry_const(map_obj, bt_value_map_get_keys_cb,
248 if (status != BT_VALUE_STATUS_OK) {
256 BT_VALUE_PUT_REF_AND_RESET(data.keys);
264 struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj);