Babeltrace 2 C API  2.1.0
Open-source trace manipulation framework
value.h
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
5  */
6 
7 #ifndef BABELTRACE2_VALUE_H
8 #define BABELTRACE2_VALUE_H
9 
10 /* IWYU pragma: private, include <babeltrace2/babeltrace.h> */
11 
12 #ifndef __BT_IN_BABELTRACE_H
13 # error "Please include <babeltrace2/babeltrace.h> instead."
14 #endif
15 
16 #include <stdint.h>
17 #include <stddef.h>
18 
19 #include <babeltrace2/types.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
234 typedef enum bt_value_type {
240 
246 
254 
262 
270 
276 
282 
288 
294 } bt_value_type;
295 
328 extern bt_value_type bt_value_get_type(const bt_value *value) __BT_NOEXCEPT;
329 
371 static inline
373  const bt_value_type other_type) __BT_NOEXCEPT
374 {
375  return (type & other_type) == other_type;
376 }
377 
403 static inline
404 bt_bool bt_value_is_null(const bt_value *value) __BT_NOEXCEPT
405 {
406  return bt_value_get_type(value) == BT_VALUE_TYPE_NULL;
407 }
408 
427 static inline
428 bt_bool bt_value_is_bool(const bt_value *value) __BT_NOEXCEPT
429 {
430  return bt_value_get_type(value) == BT_VALUE_TYPE_BOOL;
431 }
432 
452 static inline
453 bt_bool bt_value_is_unsigned_integer(const bt_value *value) __BT_NOEXCEPT
454 {
456 }
457 
477 static inline
478 bt_bool bt_value_is_signed_integer(const bt_value *value) __BT_NOEXCEPT
479 {
481 }
482 
501 static inline
502 bt_bool bt_value_is_real(const bt_value *value) __BT_NOEXCEPT
503 {
504  return bt_value_get_type(value) == BT_VALUE_TYPE_REAL;
505 }
506 
525 static inline
526 bt_bool bt_value_is_string(const bt_value *value) __BT_NOEXCEPT
527 {
528  return bt_value_get_type(value) == BT_VALUE_TYPE_STRING;
529 }
530 
549 static inline
550 bt_bool bt_value_is_array(const bt_value *value) __BT_NOEXCEPT
551 {
552  return bt_value_get_type(value) == BT_VALUE_TYPE_ARRAY;
553 }
554 
573 static inline
574 bt_bool bt_value_is_map(const bt_value *value) __BT_NOEXCEPT
575 {
576  return bt_value_get_type(value) == BT_VALUE_TYPE_MAP;
577 }
578 
615 extern bt_value *const bt_value_null;
616 
636 extern bt_value *bt_value_bool_create(void) __BT_NOEXCEPT;
637 
653 extern bt_value *bt_value_bool_create_init(bt_bool raw_value) __BT_NOEXCEPT;
654 
672 extern void bt_value_bool_set(bt_value *value, bt_bool raw_value) __BT_NOEXCEPT;
673 
690 extern bt_bool bt_value_bool_get(const bt_value *value) __BT_NOEXCEPT;
691 
711 extern bt_value *bt_value_integer_unsigned_create(void) __BT_NOEXCEPT;
712 
729 extern bt_value *bt_value_integer_unsigned_create_init(uint64_t raw_value) __BT_NOEXCEPT;
730 
749 extern void bt_value_integer_unsigned_set(bt_value *value,
750  uint64_t raw_value) __BT_NOEXCEPT;
751 
768 extern uint64_t bt_value_integer_unsigned_get(const bt_value *value) __BT_NOEXCEPT;
769 
789 extern bt_value *bt_value_integer_signed_create(void) __BT_NOEXCEPT;
790 
807 extern bt_value *bt_value_integer_signed_create_init(int64_t raw_value) __BT_NOEXCEPT;
808 
827 extern void bt_value_integer_signed_set(bt_value *value, int64_t raw_value) __BT_NOEXCEPT;
828 
845 extern int64_t bt_value_integer_signed_get(const bt_value *value) __BT_NOEXCEPT;
846 
866 extern bt_value *bt_value_real_create(void) __BT_NOEXCEPT;
867 
883 extern bt_value *bt_value_real_create_init(double raw_value) __BT_NOEXCEPT;
884 
902 extern void bt_value_real_set(bt_value *value, double raw_value) __BT_NOEXCEPT;
903 
920 extern double bt_value_real_get(const bt_value *value) __BT_NOEXCEPT;
921 
941 extern bt_value *bt_value_string_create(void) __BT_NOEXCEPT;
942 
961 extern bt_value *bt_value_string_create_init(const char *raw_value) __BT_NOEXCEPT;
962 
972  BT_VALUE_STRING_SET_STATUS_OK = __BT_FUNC_STATUS_OK,
973 
978  BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
980 
1006  const char *raw_value) __BT_NOEXCEPT;
1007 
1028 extern const char *bt_value_string_get(const bt_value *value) __BT_NOEXCEPT;
1029 
1046 extern bt_value *bt_value_array_create(void) __BT_NOEXCEPT;
1047 
1059 
1064  BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1066 
1110  bt_value *value, bt_value *element_value) __BT_NOEXCEPT;
1111 
1139 bt_value_array_append_bool_element(bt_value *value, bt_bool raw_value) __BT_NOEXCEPT;
1140 
1170  uint64_t raw_value) __BT_NOEXCEPT;
1171 
1201  int64_t raw_value) __BT_NOEXCEPT;
1202 
1230 bt_value_array_append_real_element(bt_value *value, double raw_value) __BT_NOEXCEPT;
1231 
1260 bt_value_array_append_string_element(bt_value *value, const char *raw_value) __BT_NOEXCEPT;
1261 
1295  bt_value **element_value) __BT_NOEXCEPT;
1296 
1330  bt_value **element_value) __BT_NOEXCEPT;
1331 
1342 
1349 
1388 bt_value_array_set_element_by_index(bt_value *value, uint64_t index,
1389  bt_value *element_value) __BT_NOEXCEPT;
1390 
1419  uint64_t index) __BT_NOEXCEPT;
1420 
1429  const bt_value *value, uint64_t index) __BT_NOEXCEPT;
1430 
1447 extern uint64_t bt_value_array_get_length(const bt_value *value) __BT_NOEXCEPT;
1448 
1465 static inline
1466 bt_bool bt_value_array_is_empty(const bt_value *value) __BT_NOEXCEPT
1467 {
1468  return bt_value_array_get_length(value) == 0;
1469 }
1470 
1487 extern bt_value *bt_value_map_create(void) __BT_NOEXCEPT;
1488 
1499 
1504  BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1506 
1561  bt_value *value, const char *key,
1562  bt_value *entry_value) __BT_NOEXCEPT;
1563 
1596  bt_value *value, const char *key, bt_bool raw_value)
1597  __BT_NOEXCEPT;
1598 
1632  uint64_t raw_value) __BT_NOEXCEPT;
1633 
1666 bt_value_map_insert_signed_integer_entry(bt_value *value, const char *key,
1667  int64_t raw_value) __BT_NOEXCEPT;
1668 
1701  bt_value *value, const char *key, double raw_value)
1702  __BT_NOEXCEPT;
1703 
1736 bt_value_map_insert_string_entry(bt_value *value, const char *key,
1737  const char *raw_value) __BT_NOEXCEPT;
1738 
1775 bt_value_map_insert_empty_array_entry(bt_value *value, const char *key,
1776  bt_value **entry_value) __BT_NOEXCEPT;
1777 
1814 bt_value_map_insert_empty_map_entry(bt_value *value, const char *key,
1815  bt_value **entry_value) __BT_NOEXCEPT;
1816 
1849  bt_value *value, const char *key) __BT_NOEXCEPT;
1850 
1859  const bt_value *value, const char *key) __BT_NOEXCEPT;
1860 
1871 
1877 
1883 
1890 
1922  (* bt_value_map_foreach_entry_func)(const char *key,
1923  bt_value *value, void *user_data);
1924 
1935 
1940  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED,
1941 
1946  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR = __BT_FUNC_STATUS_USER_ERROR,
1947 
1952  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1953 
1960 
2013  bt_value *value, bt_value_map_foreach_entry_func user_func,
2014  void *user_data) __BT_NOEXCEPT;
2015 
2026 
2032 
2038 
2045 
2078  const bt_value *value, void *user_data);
2079 
2090 
2096 
2102 
2108 
2115 
2127  const bt_value *value,
2129  void *user_data) __BT_NOEXCEPT;
2130 
2147 extern uint64_t bt_value_map_get_size(const bt_value *value) __BT_NOEXCEPT;
2148 
2165 static inline
2166 bt_bool bt_value_map_is_empty(const bt_value *value) __BT_NOEXCEPT
2167 {
2168  return bt_value_map_get_size(value) == 0;
2169 }
2170 
2191 extern bt_bool bt_value_map_has_entry(const bt_value *value,
2192  const char *key) __BT_NOEXCEPT;
2193 
2203  BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK,
2204 
2209  BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
2211 
2278  bt_value *value, const bt_value *extension_value) __BT_NOEXCEPT;
2279 
2291 typedef enum bt_value_copy_status {
2296  BT_VALUE_COPY_STATUS_OK = __BT_FUNC_STATUS_OK,
2297 
2302  BT_VALUE_COPY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
2304 
2330 extern bt_value_copy_status bt_value_copy(const bt_value *value,
2331  bt_value **copy_value) __BT_NOEXCEPT;
2332 
2353 extern bt_bool bt_value_is_equal(const bt_value *a_value,
2354  const bt_value *b_value) __BT_NOEXCEPT;
2355 
2378 extern void bt_value_get_ref(const bt_value *value) __BT_NOEXCEPT;
2379 
2395 extern void bt_value_put_ref(const bt_value *value) __BT_NOEXCEPT;
2396 
2411 #define BT_VALUE_PUT_REF_AND_RESET(_value) \
2412  do { \
2413  bt_value_put_ref(_value); \
2414  (_value) = NULL; \
2415  } while (0)
2416 
2442 #define BT_VALUE_MOVE_REF(_dst, _src) \
2443  do { \
2444  bt_value_put_ref(_dst); \
2445  (_dst) = (_src); \
2446  (_src) = NULL; \
2447  } while (0)
2448 
2453 #ifdef __cplusplus
2454 }
2455 #endif
2456 
2457 #endif /* BABELTRACE2_VALUE_H */
const bt_value * bt_value_map_borrow_entry_value_const(const bt_value *value, const char *key)
Borrows the value of the entry with the key key in the map value value (const version).
Out of memory.
Definition: value.h:1952
bt_value_map_foreach_entry_const_func_status
Status codes for bt_value_map_foreach_entry_const_func.
Definition: value.h:2020
bt_value_array_append_element_status bt_value_array_append_empty_map_element(bt_value *value, bt_value **element_value)
Creates an empty map value and appends it to the array value value.
Out of memory.
Definition: value.h:2209
bt_value_copy_status bt_value_copy(const bt_value *value, bt_value **copy_value)
Deep-copies a value object.
Boolean value.
Definition: value.h:245
Null value.
Definition: value.h:239
Integer value.
Definition: value.h:253
uint64_t bt_value_integer_unsigned_get(const bt_value *value)
Returns the raw value of the unsigned integer value value.
static bt_bool bt_value_is_real(const bt_value *value)
Returns whether or not the value value is a real value.
Definition: value.h:502
bt_value_map_insert_entry_status bt_value_map_insert_entry(bt_value *value, const char *key, bt_value *entry_value)
Inserts or replaces an entry with the key key and the value entry_value in the map value value...
bt_value_array_append_element_status bt_value_array_append_bool_element(bt_value *value, bt_bool raw_value)
Creates a boolean value initialized to raw_value and appends it to the array value value...
bt_value * bt_value_string_create(void)
Creates and returns an empty string value.
int64_t bt_value_integer_signed_get(const bt_value *value)
Returns the raw value of the signed integer value value.
bt_bool bt_value_map_has_entry(const bt_value *value, const char *key)
Returns whether or not the map value value has an entry with the key key.
Out of memory.
Definition: value.h:978
Array value.
Definition: value.h:287
static bt_bool bt_value_is_bool(const bt_value *value)
Returns whether or not the value value is a boolean value.
Definition: value.h:428
Success.
Definition: value.h:2203
bt_value_map_insert_entry_status bt_value_map_insert_unsigned_integer_entry(bt_value *value, const char *key, uint64_t raw_value)
Creates an unsigned integer value initialized to raw_value and inserts or replaces an entry with the ...
bt_value_array_append_element_status bt_value_array_append_element(bt_value *value, bt_value *element_value)
Appends the value element_value to the array value value.
static bt_bool bt_value_array_is_empty(const bt_value *value)
Returns whether or not the array value value is empty.
Definition: value.h:1466
uint64_t bt_value_map_get_size(const bt_value *value)
Returns the size of the map value value.
void bt_value_integer_unsigned_set(bt_value *value, uint64_t raw_value)
Sets the raw value of the unsigned integer value value to raw_value.
bt_bool bt_value_bool_get(const bt_value *value)
Returns the raw value of the boolean value value.
User function interrupted the iteration process.
Definition: value.h:2095
bt_value * bt_value_bool_create_init(bt_bool raw_value)
Creates and returns a boolean value initialized to raw_value.
User function interrupted the iteration process.
Definition: value.h:1940
bt_value * bt_value_integer_signed_create(void)
Creates and returns a signed integer value initialized to 0.
bt_value * bt_value_integer_unsigned_create_init(uint64_t raw_value)
Creates and returns an unsigned integer value initialized to raw_value.
bt_value * bt_value_real_create(void)
Creates and returns a real value initialized to 0.
const char * bt_value_string_get(const bt_value *value)
Returns the raw value of the string value value.
Interrupt the iteration process.
Definition: value.h:1876
bt_value_type
Value type enumerators.
Definition: value.h:234
bt_value * bt_value_real_create_init(double raw_value)
Creates and returns a real value initialized to raw_value.
bt_value_array_append_element_status bt_value_array_append_real_element(bt_value *value, double raw_value)
Creates a real value initialized to raw_value and appends it to the array value value.
Interrupt the iteration process.
Definition: value.h:2031
Unsigned integer value.
Definition: value.h:261
void bt_value_bool_set(bt_value *value, bt_bool raw_value)
Sets the raw value of the boolean value value to raw_value.
bt_value_map_extend_status bt_value_map_extend(bt_value *value, const bt_value *extension_value)
Extends the map value value with the map value extension_value.
bt_value_string_set_status
Status codes for bt_value_string_set().
Definition: value.h:967
bt_value * bt_value_map_borrow_entry_value(bt_value *value, const char *key)
Borrows the value of the entry with the key key in the map value value.
Out of memory.
Definition: value.h:2037
double bt_value_real_get(const bt_value *value)
Returns the raw value of the real value value.
void bt_value_put_ref(const bt_value *value)
Decrements the reference count of the value value.
bt_value_type bt_value_get_type(const bt_value *value)
Returns the type enumerator of the value value.
void bt_value_real_set(bt_value *value, double raw_value)
Sets the raw value of the real value value to raw_value.
Out of memory.
Definition: value.h:1504
bt_value_map_foreach_entry_const_status bt_value_map_foreach_entry_const(const bt_value *value, bt_value_map_foreach_entry_const_func user_func, void *user_data)
Iterates the entries of the map value value, calling user_func for each entry (const version)...
bt_value_array_append_element_status
Status codes for the bt_value_array_append_*() functions.
Definition: value.h:1053
static bt_bool bt_value_is_null(const bt_value *value)
Returns whether or not the value value is a null value.
Definition: value.h:404
Out of memory.
Definition: value.h:1064
Success.
Definition: value.h:1058
bt_value_array_append_element_status bt_value_array_append_signed_integer_element(bt_value *value, int64_t raw_value)
Creates a signed integer value initialized to raw_value and appends it to the array value value...
Out of memory.
Definition: value.h:1347
bt_value_map_insert_entry_status
Status codes for the bt_value_map_insert_*() functions.
Definition: value.h:1493
bt_value_map_foreach_entry_func_status(* bt_value_map_foreach_entry_func)(const char *key, bt_value *value, void *user_data)
User function for bt_value_map_foreach_entry().
Definition: value.h:1922
Other error.
Definition: value.h:2113
Success.
Definition: value.h:1934
bt_value_map_extend_status
Status codes for bt_value_map_extend().
Definition: value.h:2198
uint64_t bt_value_array_get_length(const bt_value *value)
Returns the length of the array value value.
Success.
Definition: value.h:972
bt_value_map_insert_entry_status bt_value_map_insert_empty_map_entry(bt_value *value, const char *key, bt_value **entry_value)
Creates an empty map value and inserts or replaces an entry with the key key and this value in the ma...
bt_value_map_insert_entry_status bt_value_map_insert_empty_array_entry(bt_value *value, const char *key, bt_value **entry_value)
Creates an empty array value and inserts or replaces an entry with the key key and this value in the ...
bt_value_array_set_element_by_index_status
Status codes for bt_value_array_set_element_by_index().
Definition: value.h:1336
bt_value * bt_value_array_create(void)
Creates and returns an empty array value.
struct bt_value bt_value
Value.
Definition: types.h:93
Out of memory.
Definition: value.h:2302
User function error.
Definition: value.h:2101
String value.
Definition: value.h:281
bt_value_map_insert_entry_status bt_value_map_insert_bool_entry(bt_value *value, const char *key, bt_bool raw_value)
Creates a boolean value initialized to raw_value and inserts or replaces an entry with the key key an...
Map value.
Definition: value.h:293
Success.
Definition: value.h:2296
bt_value_map_insert_entry_status bt_value_map_insert_real_entry(bt_value *value, const char *key, double raw_value)
Creates a real value initialized to raw_value and inserts or replaces an entry with the key key and t...
int bt_bool
Babeltrace 2 boolean type.
Definition: types.h:126
bt_value_array_set_element_by_index_status bt_value_array_set_element_by_index(bt_value *value, uint64_t index, bt_value *element_value)
Sets the element of the array value value at index index to the value element_value.
bt_value_array_append_element_status bt_value_array_append_string_element(bt_value *value, const char *raw_value)
Creates a string value initialized to a copy of raw_value and appends it to the array value value...
bt_value_map_insert_entry_status bt_value_map_insert_signed_integer_entry(bt_value *value, const char *key, int64_t raw_value)
Creates a signed integer value initialized to raw_value and inserts or replaces an entry with the key...
static bt_bool bt_value_type_is(const bt_value_type type, const bt_value_type other_type)
Returns whether or not the value type type conceptually is the value type other_type.
Definition: value.h:372
Success.
Definition: value.h:2025
bt_value_string_set_status bt_value_string_set(bt_value *value, const char *raw_value)
Sets the raw value of the string value value to a copy of raw_value.
static bt_bool bt_value_is_map(const bt_value *value)
Returns whether or not the value value is a map value.
Definition: value.h:574
void bt_value_get_ref(const bt_value *value)
Increments the reference count of the value value.
bt_value * bt_value_map_create(void)
Creates and returns an empty map value.
bt_value_map_foreach_entry_const_status
Status codes for bt_value_map_foreach_entry_const().
Definition: value.h:2084
Success.
Definition: value.h:2089
bt_value_map_insert_entry_status bt_value_map_insert_string_entry(bt_value *value, const char *key, const char *raw_value)
Creates a string value initialized to a copy of raw_value and inserts or replaces an entry with the k...
bt_value_array_append_element_status bt_value_array_append_unsigned_integer_element(bt_value *value, uint64_t raw_value)
Creates an unsigned integer value initialized to raw_value and appends it to the array value value...
bt_value * bt_value_integer_signed_create_init(int64_t raw_value)
Creates and returns a signed integer value initialized to raw_value.
Out of memory.
Definition: value.h:2107
static bt_bool bt_value_map_is_empty(const bt_value *value)
Returns whether or not the map value value is empty.
Definition: value.h:2166
bt_value * bt_value_integer_unsigned_create(void)
Creates and returns an unsigned integer value initialized to 0.
const bt_value * bt_value_array_borrow_element_by_index_const(const bt_value *value, uint64_t index)
Borrows the element at index index from the array value value (const version).
Other error.
Definition: value.h:1958
bt_value_map_foreach_entry_func_status
Status codes for bt_value_map_foreach_entry_func.
Definition: value.h:1865
bt_value * bt_value_array_borrow_element_by_index(bt_value *value, uint64_t index)
Borrows the element at index index from the array value value.
User error.
Definition: value.h:2043
Success.
Definition: value.h:1341
bt_value * bt_value_string_create_init(const char *raw_value)
Creates and returns a string value initialized to a copy of raw_value.
Out of memory.
Definition: value.h:1882
static bt_bool bt_value_is_string(const bt_value *value)
Returns whether or not the value value is a string value.
Definition: value.h:526
static bt_bool bt_value_is_signed_integer(const bt_value *value)
Returns whether or not the value value is a signed integer value.
Definition: value.h:478
bt_value * bt_value_bool_create(void)
Creates and returns a boolean value initialized to BT_FALSE.
Signed integer value.
Definition: value.h:269
bt_value_map_foreach_entry_status bt_value_map_foreach_entry(bt_value *value, bt_value_map_foreach_entry_func user_func, void *user_data)
Iterates the entries of the map value value, calling user_func for each entry.
User function error.
Definition: value.h:1946
bt_value_copy_status
Status codes for bt_value_copy().
Definition: value.h:2291
bt_value *const bt_value_null
The null value singleton.
bt_value_map_foreach_entry_const_func_status(* bt_value_map_foreach_entry_const_func)(const char *key, const bt_value *value, void *user_data)
User function for bt_value_map_foreach_entry_const_func().
Definition: value.h:2077
bt_bool bt_value_is_equal(const bt_value *a_value, const bt_value *b_value)
Returns whether or not the value a_value is equal, recursively, to b_value.
Success.
Definition: value.h:1870
static bt_bool bt_value_is_unsigned_integer(const bt_value *value)
Returns whether or not the value value is an unsigned integer value.
Definition: value.h:453
bt_value_map_foreach_entry_status
Status codes for bt_value_map_foreach_entry().
Definition: value.h:1929
void bt_value_integer_signed_set(bt_value *value, int64_t raw_value)
Sets the raw value of the signed integer value value to raw_value.
User error.
Definition: value.h:1888
bt_value_array_append_element_status bt_value_array_append_empty_array_element(bt_value *value, bt_value **element_value)
Creates an empty array value and appends it to the array value value.
Real value.
Definition: value.h:275
static bt_bool bt_value_is_array(const bt_value *value)
Returns whether or not the value value is an array value.
Definition: value.h:550
Success.
Definition: value.h:1498