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 <babeltrace2-ctf-writer/types.h>
29 #include "common/macros.h"
32 struct bt_ctf_private_value
;
37 enum bt_ctf_value_status
{
38 /// Operation canceled.
39 BT_CTF_VALUE_STATUS_CANCELED
= 125,
41 /// Cannot allocate memory.
42 BT_CTF_VALUE_STATUS_NOMEM
= -12,
45 BT_CTF_VALUE_STATUS_OK
= 0,
49 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
);
52 # define bt_ctf_value_freeze _bt_ctf_value_freeze
54 # define bt_ctf_value_freeze(_value)
55 #endif /* BT_DEV_MODE */
57 extern struct bt_ctf_value
*const bt_ctf_value_null
;
59 enum bt_ctf_value_type
{
60 /// Null value object.
61 BT_CTF_VALUE_TYPE_NULL
= 0,
63 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
64 BT_CTF_VALUE_TYPE_BOOL
= 1,
66 /// Integer value object (holds a signed 64-bit integer raw value).
67 BT_CTF_VALUE_TYPE_INTEGER
= 2,
69 /// Floating point number value object (holds a \c double raw value).
70 BT_CTF_VALUE_TYPE_REAL
= 3,
72 /// String value object.
73 BT_CTF_VALUE_TYPE_STRING
= 4,
75 /// Array value object.
76 BT_CTF_VALUE_TYPE_ARRAY
= 5,
79 BT_CTF_VALUE_TYPE_MAP
= 6,
83 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
);
86 bt_ctf_bool
bt_ctf_value_is_null(const struct bt_ctf_value
*object
)
88 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_NULL
;
92 bt_ctf_bool
bt_ctf_value_is_bool(const struct bt_ctf_value
*object
)
94 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_BOOL
;
98 bt_ctf_bool
bt_ctf_value_is_integer(const struct bt_ctf_value
*object
)
100 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_INTEGER
;
104 bt_ctf_bool
bt_ctf_value_is_real(const struct bt_ctf_value
*object
)
106 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_REAL
;
110 bt_ctf_bool
bt_ctf_value_is_string(const struct bt_ctf_value
*object
)
112 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_STRING
;
116 bt_ctf_bool
bt_ctf_value_is_array(const struct bt_ctf_value
*object
)
118 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_ARRAY
;
122 bt_ctf_bool
bt_ctf_value_is_map(const struct bt_ctf_value
*object
)
124 return bt_ctf_value_get_type(object
) == BT_CTF_VALUE_TYPE_MAP
;
128 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy
,
129 const struct bt_ctf_value
*object
);
132 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
133 const struct bt_ctf_value
*object_b
);
136 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
);
139 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
);
142 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
);
145 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
);
148 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
);
151 bt_ctf_bool
bt_ctf_value_array_is_empty(const struct bt_ctf_value
*array_obj
)
153 return bt_ctf_value_array_get_length(array_obj
) == 0;
157 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
158 const struct bt_ctf_value
*array_obj
, uint64_t index
);
161 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
);
164 bt_ctf_bool
bt_ctf_value_map_is_empty(const struct bt_ctf_value
*map_obj
)
166 return bt_ctf_value_map_get_size(map_obj
) == 0;
170 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(
171 const struct bt_ctf_value
*map_obj
, const char *key
);
173 typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb
)(const char *key
,
174 struct bt_ctf_value
*object
, void *data
);
177 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(
178 const struct bt_ctf_value
*map_obj
,
179 bt_ctf_value_map_foreach_entry_cb cb
, void *data
);
182 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
,
186 enum bt_ctf_value_status
bt_ctf_value_map_extend(
187 struct bt_ctf_private_value
**extended_map_obj
,
188 const struct bt_ctf_value
*base_map_obj
,
189 const struct bt_ctf_value
*extension_map_obj
);
193 struct bt_ctf_private_value
;
195 extern struct bt_ctf_private_value
*const bt_ctf_private_value_null
;
198 struct bt_ctf_value
*bt_ctf_private_value_as_value(
199 struct bt_ctf_private_value
*priv_value
)
201 return (void *) priv_value
;
205 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void);
208 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
);
211 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
,
215 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void);
218 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(
222 void bt_ctf_private_value_integer_set(
223 struct bt_ctf_private_value
*integer_obj
, int64_t val
);
226 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void);
229 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
);
232 void bt_ctf_private_value_real_set(
233 struct bt_ctf_private_value
*real_obj
, double val
);
236 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void);
239 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(
243 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
244 struct bt_ctf_private_value
*string_obj
,
248 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void);
251 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
252 const struct bt_ctf_private_value
*array_obj
, uint64_t index
);
255 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
256 struct bt_ctf_private_value
*array_obj
,
257 struct bt_ctf_value
*element_obj
);
260 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
261 struct bt_ctf_private_value
*array_obj
,
265 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
266 struct bt_ctf_private_value
*array_obj
,
270 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
271 struct bt_ctf_private_value
*array_obj
,
275 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
276 struct bt_ctf_private_value
*array_obj
, const char *val
);
279 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
280 struct bt_ctf_private_value
*array_obj
);
283 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
284 struct bt_ctf_private_value
*array_obj
);
287 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
288 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
289 struct bt_ctf_value
*element_obj
);
292 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void);
295 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
296 const struct bt_ctf_private_value
*map_obj
, const char *key
);
298 typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb
)(const char *key
,
299 struct bt_ctf_private_value
*object
, void *data
);
302 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
303 const struct bt_ctf_private_value
*map_obj
,
304 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
);
307 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
308 struct bt_ctf_private_value
*map_obj
, const char *key
,
309 struct bt_ctf_value
*element_obj
);
312 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
313 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
);
316 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
317 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
);
320 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
321 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
);
324 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
325 struct bt_ctf_private_value
*map_obj
, const char *key
,
329 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
330 struct bt_ctf_private_value
*map_obj
, const char *key
);
333 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
334 struct bt_ctf_private_value
*map_obj
, const char *key
);
337 const char *bt_ctf_value_type_string(enum bt_ctf_value_type type
)
340 case BT_CTF_VALUE_TYPE_NULL
:
341 return "BT_CTF_VALUE_TYPE_NULL";
342 case BT_CTF_VALUE_TYPE_BOOL
:
343 return "BT_CTF_VALUE_TYPE_BOOL";
344 case BT_CTF_VALUE_TYPE_INTEGER
:
345 return "BT_CTF_VALUE_TYPE_INTEGER";
346 case BT_CTF_VALUE_TYPE_REAL
:
347 return "BT_CTF_VALUE_TYPE_REAL";
348 case BT_CTF_VALUE_TYPE_STRING
:
349 return "BT_CTF_VALUE_TYPE_STRING";
350 case BT_CTF_VALUE_TYPE_ARRAY
:
351 return "BT_CTF_VALUE_TYPE_ARRAY";
352 case BT_CTF_VALUE_TYPE_MAP
:
353 return "BT_CTF_VALUE_TYPE_MAP";
359 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */