2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com>
8 #ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
9 #define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
11 #include <babeltrace2-ctf-writer/types.h>
13 #include "common/macros.h"
16 struct bt_ctf_private_value
;
21 enum bt_ctf_value_status
{
22 /// Operation canceled.
23 BT_CTF_VALUE_STATUS_CANCELED
= 125,
25 /// Cannot allocate memory.
26 BT_CTF_VALUE_STATUS_NOMEM
= -12,
29 BT_CTF_VALUE_STATUS_OK
= 0,
33 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
);
36 # define bt_ctf_value_freeze _bt_ctf_value_freeze
38 # define bt_ctf_value_freeze(_value)
39 #endif /* BT_DEV_MODE */
41 extern struct bt_ctf_value
*const bt_ctf_value_null
;
43 enum bt_ctf_value_type
{
44 /// Null value object.
45 BT_CTF_VALUE_TYPE_NULL
= 0,
47 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
48 BT_CTF_VALUE_TYPE_BOOL
= 1,
50 /// Integer value object (holds a signed 64-bit integer raw value).
51 BT_CTF_VALUE_TYPE_INTEGER
= 2,
53 /// Floating point number value object (holds a \c double raw value).
54 BT_CTF_VALUE_TYPE_REAL
= 3,
56 /// String value object.
57 BT_CTF_VALUE_TYPE_STRING
= 4,
59 /// Array value object.
60 BT_CTF_VALUE_TYPE_ARRAY
= 5,
63 BT_CTF_VALUE_TYPE_MAP
= 6,
67 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
);
70 bt_ctf_bool
bt_ctf_value_is_null(const struct bt_ctf_value
*object
)
72 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_NULL
;
76 bt_ctf_bool
bt_ctf_value_is_bool(const struct bt_ctf_value
*object
)
78 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_BOOL
;
82 bt_ctf_bool
bt_ctf_value_is_integer(const struct bt_ctf_value
*object
)
84 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_INTEGER
;
88 bt_ctf_bool
bt_ctf_value_is_real(const struct bt_ctf_value
*object
)
90 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_REAL
;
94 bt_ctf_bool
bt_ctf_value_is_string(const struct bt_ctf_value
*object
)
96 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_STRING
;
100 bt_ctf_bool
bt_ctf_value_is_array(const struct bt_ctf_value
*object
)
102 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_ARRAY
;
106 bt_ctf_bool
bt_ctf_value_is_map(const struct bt_ctf_value
*object
)
108 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_MAP
;
112 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy
,
113 const struct bt_ctf_value
*object
);
116 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
117 const struct bt_ctf_value
*object_b
);
120 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
);
123 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
);
126 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
);
129 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
);
132 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
);
135 bt_ctf_bool
bt_ctf_value_array_is_empty(const struct bt_ctf_value
*array_obj
)
137 return bt_ctf_value_array_get_length(array_obj
) == 0;
141 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
142 const struct bt_ctf_value
*array_obj
, uint64_t index
);
145 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
);
148 bt_ctf_bool
bt_ctf_value_map_is_empty(const struct bt_ctf_value
*map_obj
)
150 return bt_ctf_value_map_get_size(map_obj
) == 0;
154 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(
155 const struct bt_ctf_value
*map_obj
, const char *key
);
157 typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb
)(const char *key
,
158 struct bt_ctf_value
*object
, void *data
);
161 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(
162 const struct bt_ctf_value
*map_obj
,
163 bt_ctf_value_map_foreach_entry_cb cb
, void *data
);
166 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
,
170 enum bt_ctf_value_status
bt_ctf_value_map_extend(
171 struct bt_ctf_private_value
**extended_map_obj
,
172 const struct bt_ctf_value
*base_map_obj
,
173 const struct bt_ctf_value
*extension_map_obj
);
177 struct bt_ctf_private_value
;
179 extern struct bt_ctf_private_value
*const bt_ctf_private_value_null
;
182 struct bt_ctf_value
*bt_ctf_private_value_as_value(
183 struct bt_ctf_private_value
*priv_value
)
185 return (void *) priv_value
;
189 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void);
192 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
);
195 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
,
199 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void);
202 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(
206 void bt_ctf_private_value_integer_set(
207 struct bt_ctf_private_value
*integer_obj
, int64_t val
);
210 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void);
213 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
);
216 void bt_ctf_private_value_real_set(
217 struct bt_ctf_private_value
*real_obj
, double val
);
220 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void);
223 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(
227 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
228 struct bt_ctf_private_value
*string_obj
,
232 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void);
235 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
236 const struct bt_ctf_private_value
*array_obj
, uint64_t index
);
239 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
240 struct bt_ctf_private_value
*array_obj
,
241 struct bt_ctf_value
*element_obj
);
244 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
245 struct bt_ctf_private_value
*array_obj
,
249 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
250 struct bt_ctf_private_value
*array_obj
,
254 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
255 struct bt_ctf_private_value
*array_obj
,
259 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
260 struct bt_ctf_private_value
*array_obj
, const char *val
);
263 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
264 struct bt_ctf_private_value
*array_obj
);
267 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
268 struct bt_ctf_private_value
*array_obj
);
271 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
272 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
273 struct bt_ctf_value
*element_obj
);
276 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void);
279 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
280 const struct bt_ctf_private_value
*map_obj
, const char *key
);
282 typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb
)(const char *key
,
283 struct bt_ctf_private_value
*object
, void *data
);
286 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
287 const struct bt_ctf_private_value
*map_obj
,
288 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
);
291 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
292 struct bt_ctf_private_value
*map_obj
, const char *key
,
293 struct bt_ctf_value
*element_obj
);
296 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
297 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
);
300 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
301 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
);
304 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
305 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
);
308 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
309 struct bt_ctf_private_value
*map_obj
, const char *key
,
313 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
314 struct bt_ctf_private_value
*map_obj
, const char *key
);
317 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
318 struct bt_ctf_private_value
*map_obj
, const char *key
);
321 const char *bt_ctf_value_type_string(enum bt_ctf_value_type type
)
324 case BT_CTF_VALUE_TYPE_NULL
:
325 return "BT_CTF_VALUE_TYPE_NULL";
326 case BT_CTF_VALUE_TYPE_BOOL
:
327 return "BT_CTF_VALUE_TYPE_BOOL";
328 case BT_CTF_VALUE_TYPE_INTEGER
:
329 return "BT_CTF_VALUE_TYPE_INTEGER";
330 case BT_CTF_VALUE_TYPE_REAL
:
331 return "BT_CTF_VALUE_TYPE_REAL";
332 case BT_CTF_VALUE_TYPE_STRING
:
333 return "BT_CTF_VALUE_TYPE_STRING";
334 case BT_CTF_VALUE_TYPE_ARRAY
:
335 return "BT_CTF_VALUE_TYPE_ARRAY";
336 case BT_CTF_VALUE_TYPE_MAP
:
337 return "BT_CTF_VALUE_TYPE_MAP";
343 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */