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,
32 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
);
35 # define bt_ctf_value_freeze _bt_ctf_value_freeze
37 # define bt_ctf_value_freeze(_value)
38 #endif /* BT_DEV_MODE */
40 extern struct bt_ctf_value
*const bt_ctf_value_null
;
42 enum bt_ctf_value_type
{
43 /// Null value object.
44 BT_CTF_VALUE_TYPE_NULL
= 0,
46 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
47 BT_CTF_VALUE_TYPE_BOOL
= 1,
49 /// Integer value object (holds a signed 64-bit integer raw value).
50 BT_CTF_VALUE_TYPE_INTEGER
= 2,
52 /// Floating point number value object (holds a \c double raw value).
53 BT_CTF_VALUE_TYPE_REAL
= 3,
55 /// String value object.
56 BT_CTF_VALUE_TYPE_STRING
= 4,
58 /// Array value object.
59 BT_CTF_VALUE_TYPE_ARRAY
= 5,
62 BT_CTF_VALUE_TYPE_MAP
= 6,
65 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
);
68 bt_ctf_bool
bt_ctf_value_is_null(const struct bt_ctf_value
*object
)
70 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_NULL
;
74 bt_ctf_bool
bt_ctf_value_is_bool(const struct bt_ctf_value
*object
)
76 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_BOOL
;
80 bt_ctf_bool
bt_ctf_value_is_integer(const struct bt_ctf_value
*object
)
82 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_INTEGER
;
86 bt_ctf_bool
bt_ctf_value_is_real(const struct bt_ctf_value
*object
)
88 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_REAL
;
92 bt_ctf_bool
bt_ctf_value_is_string(const struct bt_ctf_value
*object
)
94 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_STRING
;
98 bt_ctf_bool
bt_ctf_value_is_array(const struct bt_ctf_value
*object
)
100 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_ARRAY
;
104 bt_ctf_bool
bt_ctf_value_is_map(const struct bt_ctf_value
*object
)
106 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_MAP
;
109 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy
,
110 const struct bt_ctf_value
*object
);
112 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
113 const struct bt_ctf_value
*object_b
);
115 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
);
117 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
);
119 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
);
121 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
);
123 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
);
126 bt_ctf_bool
bt_ctf_value_array_is_empty(const struct bt_ctf_value
*array_obj
)
128 return bt_ctf_value_array_get_length(array_obj
) == 0;
131 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
132 const struct bt_ctf_value
*array_obj
, uint64_t index
);
134 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
);
137 bt_ctf_bool
bt_ctf_value_map_is_empty(const struct bt_ctf_value
*map_obj
)
139 return bt_ctf_value_map_get_size(map_obj
) == 0;
142 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(
143 const struct bt_ctf_value
*map_obj
, const char *key
);
145 typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb
)(const char *key
,
146 struct bt_ctf_value
*object
, void *data
);
148 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(
149 const struct bt_ctf_value
*map_obj
,
150 bt_ctf_value_map_foreach_entry_cb cb
, void *data
);
152 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
,
155 enum bt_ctf_value_status
bt_ctf_value_map_extend(
156 struct bt_ctf_private_value
**extended_map_obj
,
157 const struct bt_ctf_value
*base_map_obj
,
158 const struct bt_ctf_value
*extension_map_obj
);
162 struct bt_ctf_private_value
;
164 extern struct bt_ctf_private_value
*const bt_ctf_private_value_null
;
167 struct bt_ctf_value
*bt_ctf_private_value_as_value(
168 struct bt_ctf_private_value
*priv_value
)
170 return (void *) priv_value
;
173 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void);
175 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
);
177 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
,
180 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void);
182 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(
185 void bt_ctf_private_value_integer_set(
186 struct bt_ctf_private_value
*integer_obj
, int64_t val
);
188 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void);
190 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
);
192 void bt_ctf_private_value_real_set(
193 struct bt_ctf_private_value
*real_obj
, double val
);
195 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void);
197 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(
200 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
201 struct bt_ctf_private_value
*string_obj
,
204 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void);
206 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
207 const struct bt_ctf_private_value
*array_obj
, uint64_t index
);
209 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
210 struct bt_ctf_private_value
*array_obj
,
211 struct bt_ctf_value
*element_obj
);
213 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
214 struct bt_ctf_private_value
*array_obj
,
217 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
218 struct bt_ctf_private_value
*array_obj
,
221 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
222 struct bt_ctf_private_value
*array_obj
,
225 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
226 struct bt_ctf_private_value
*array_obj
, const char *val
);
228 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
229 struct bt_ctf_private_value
*array_obj
);
231 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
232 struct bt_ctf_private_value
*array_obj
);
234 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
235 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
236 struct bt_ctf_value
*element_obj
);
238 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void);
240 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
241 const struct bt_ctf_private_value
*map_obj
, const char *key
);
243 typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb
)(const char *key
,
244 struct bt_ctf_private_value
*object
, void *data
);
246 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
247 const struct bt_ctf_private_value
*map_obj
,
248 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
);
250 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
251 struct bt_ctf_private_value
*map_obj
, const char *key
,
252 struct bt_ctf_value
*element_obj
);
254 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
255 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
);
257 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
258 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
);
260 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
261 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
);
263 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
264 struct bt_ctf_private_value
*map_obj
, const char *key
,
267 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
268 struct bt_ctf_private_value
*map_obj
, const char *key
);
270 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
271 struct bt_ctf_private_value
*map_obj
, const char *key
);
274 const char *bt_ctf_value_type_string(enum bt_ctf_value_type type
)
277 case BT_CTF_VALUE_TYPE_NULL
:
278 return "BT_CTF_VALUE_TYPE_NULL";
279 case BT_CTF_VALUE_TYPE_BOOL
:
280 return "BT_CTF_VALUE_TYPE_BOOL";
281 case BT_CTF_VALUE_TYPE_INTEGER
:
282 return "BT_CTF_VALUE_TYPE_INTEGER";
283 case BT_CTF_VALUE_TYPE_REAL
:
284 return "BT_CTF_VALUE_TYPE_REAL";
285 case BT_CTF_VALUE_TYPE_STRING
:
286 return "BT_CTF_VALUE_TYPE_STRING";
287 case BT_CTF_VALUE_TYPE_ARRAY
:
288 return "BT_CTF_VALUE_TYPE_ARRAY";
289 case BT_CTF_VALUE_TYPE_MAP
:
290 return "BT_CTF_VALUE_TYPE_MAP";
296 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */