1 #ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
2 #define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
5 * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation
6 * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "common/babeltrace.h"
30 struct bt_ctf_private_value
;
35 enum bt_ctf_value_status
{
36 /// Operation canceled.
37 BT_CTF_VALUE_STATUS_CANCELED
= 125,
39 /// Cannot allocate memory.
40 BT_CTF_VALUE_STATUS_NOMEM
= -12,
43 BT_CTF_VALUE_STATUS_OK
= 0,
47 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
);
50 # define bt_ctf_value_freeze _bt_ctf_value_freeze
52 # define bt_ctf_value_freeze(_value)
53 #endif /* BT_DEV_MODE */
55 extern struct bt_ctf_value
*const bt_ctf_value_null
;
57 enum bt_ctf_value_type
{
58 /// Null value object.
59 BT_CTF_VALUE_TYPE_NULL
= 0,
61 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
62 BT_CTF_VALUE_TYPE_BOOL
= 1,
64 /// Integer value object (holds a signed 64-bit integer raw value).
65 BT_CTF_VALUE_TYPE_INTEGER
= 2,
67 /// Floating point number value object (holds a \c double raw value).
68 BT_CTF_VALUE_TYPE_REAL
= 3,
70 /// String value object.
71 BT_CTF_VALUE_TYPE_STRING
= 4,
73 /// Array value object.
74 BT_CTF_VALUE_TYPE_ARRAY
= 5,
77 BT_CTF_VALUE_TYPE_MAP
= 6,
81 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
);
84 bt_bool
bt_ctf_value_is_null(const struct bt_ctf_value
*object
)
86 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_NULL
;
90 bt_bool
bt_ctf_value_is_bool(const struct bt_ctf_value
*object
)
92 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_BOOL
;
96 bt_bool
bt_ctf_value_is_integer(const struct bt_ctf_value
*object
)
98 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_INTEGER
;
102 bt_bool
bt_ctf_value_is_real(const struct bt_ctf_value
*object
)
104 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_REAL
;
108 bt_bool
bt_ctf_value_is_string(const struct bt_ctf_value
*object
)
110 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_STRING
;
114 bt_bool
bt_ctf_value_is_array(const struct bt_ctf_value
*object
)
116 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_ARRAY
;
120 bt_bool
bt_ctf_value_is_map(const struct bt_ctf_value
*object
)
122 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_MAP
;
126 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy
,
127 const struct bt_ctf_value
*object
);
130 bt_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
131 const struct bt_ctf_value
*object_b
);
134 bt_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
);
137 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
);
140 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
);
143 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
);
146 uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value
*array_obj
);
149 bt_bool
bt_ctf_value_array_is_empty(const struct bt_ctf_value
*array_obj
)
151 return bt_ctf_value_array_get_size(array_obj
) == 0;
155 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
156 const struct bt_ctf_value
*array_obj
, uint64_t index
);
159 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
);
162 bt_bool
bt_ctf_value_map_is_empty(const struct bt_ctf_value
*map_obj
)
164 return bt_ctf_value_map_get_size(map_obj
) == 0;
168 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(
169 const struct bt_ctf_value
*map_obj
, const char *key
);
171 typedef bt_bool (* bt_ctf_value_map_foreach_entry_cb
)(const char *key
,
172 struct bt_ctf_value
*object
, void *data
);
175 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(
176 const struct bt_ctf_value
*map_obj
,
177 bt_ctf_value_map_foreach_entry_cb cb
, void *data
);
180 bt_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
,
184 enum bt_ctf_value_status
bt_ctf_value_map_extend(
185 struct bt_ctf_private_value
**extended_map_obj
,
186 const struct bt_ctf_value
*base_map_obj
,
187 const struct bt_ctf_value
*extension_map_obj
);
191 struct bt_ctf_private_value
;
193 extern struct bt_ctf_private_value
*const bt_ctf_private_value_null
;
196 struct bt_ctf_value
*bt_ctf_private_value_as_value(
197 struct bt_ctf_private_value
*priv_value
)
199 return (void *) priv_value
;
203 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void);
206 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_bool val
);
209 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
,
213 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void);
216 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(
220 void bt_ctf_private_value_integer_set(
221 struct bt_ctf_private_value
*integer_obj
, int64_t val
);
224 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void);
227 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
);
230 void bt_ctf_private_value_real_set(
231 struct bt_ctf_private_value
*real_obj
, double val
);
234 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void);
237 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(
241 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
242 struct bt_ctf_private_value
*string_obj
,
246 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void);
249 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
250 const struct bt_ctf_private_value
*array_obj
, uint64_t index
);
253 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
254 struct bt_ctf_private_value
*array_obj
,
255 struct bt_ctf_value
*element_obj
);
258 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
259 struct bt_ctf_private_value
*array_obj
,
263 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
264 struct bt_ctf_private_value
*array_obj
,
268 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
269 struct bt_ctf_private_value
*array_obj
,
273 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
274 struct bt_ctf_private_value
*array_obj
, const char *val
);
277 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
278 struct bt_ctf_private_value
*array_obj
);
281 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
282 struct bt_ctf_private_value
*array_obj
);
285 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
286 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
287 struct bt_ctf_value
*element_obj
);
290 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void);
293 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
294 const struct bt_ctf_private_value
*map_obj
, const char *key
);
296 typedef bt_bool (* bt_ctf_private_value_map_foreach_entry_cb
)(const char *key
,
297 struct bt_ctf_private_value
*object
, void *data
);
300 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
301 const struct bt_ctf_private_value
*map_obj
,
302 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
);
305 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
306 struct bt_ctf_private_value
*map_obj
, const char *key
,
307 struct bt_ctf_value
*element_obj
);
310 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
311 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_bool val
);
314 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
315 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
);
318 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
319 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
);
322 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
323 struct bt_ctf_private_value
*map_obj
, const char *key
,
327 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
328 struct bt_ctf_private_value
*map_obj
, const char *key
);
331 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
332 struct bt_ctf_private_value
*map_obj
, const char *key
);
335 const char *bt_ctf_value_type_string(enum bt_ctf_value_type type
)
338 case BT_CTF_VALUE_TYPE_NULL
:
339 return "BT_CTF_VALUE_TYPE_NULL";
340 case BT_CTF_VALUE_TYPE_BOOL
:
341 return "BT_CTF_VALUE_TYPE_BOOL";
342 case BT_CTF_VALUE_TYPE_INTEGER
:
343 return "BT_CTF_VALUE_TYPE_INTEGER";
344 case BT_CTF_VALUE_TYPE_REAL
:
345 return "BT_CTF_VALUE_TYPE_REAL";
346 case BT_CTF_VALUE_TYPE_STRING
:
347 return "BT_CTF_VALUE_TYPE_STRING";
348 case BT_CTF_VALUE_TYPE_ARRAY
:
349 return "BT_CTF_VALUE_TYPE_ARRAY";
350 case BT_CTF_VALUE_TYPE_MAP
:
351 return "BT_CTF_VALUE_TYPE_MAP";
357 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */