Babeltrace 2 C API  2.0.6
Open-source trace manipulation framework
value.h
1 #ifndef BABELTRACE2_VALUE_H
2 #define BABELTRACE2_VALUE_H
3 
4 /*
5  * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef __BT_IN_BABELTRACE_H
27 # error "Please include <babeltrace2/babeltrace.h> instead."
28 #endif
29 
30 #include <stdint.h>
31 #include <stddef.h>
32 
33 #include <babeltrace2/types.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
248 typedef enum bt_value_type {
254 
260 
268 
276 
284 
290 
296 
302 
308 } bt_value_type;
309 
342 extern bt_value_type bt_value_get_type(const bt_value *value);
343 
385 static inline
387  const bt_value_type other_type)
388 {
389  return (type & other_type) == other_type;
390 }
391 
417 static inline
419 {
420  return bt_value_get_type(value) == BT_VALUE_TYPE_NULL;
421 }
422 
441 static inline
443 {
444  return bt_value_get_type(value) == BT_VALUE_TYPE_BOOL;
445 }
446 
466 static inline
468 {
470 }
471 
491 static inline
493 {
495 }
496 
515 static inline
517 {
518  return bt_value_get_type(value) == BT_VALUE_TYPE_REAL;
519 }
520 
539 static inline
541 {
542  return bt_value_get_type(value) == BT_VALUE_TYPE_STRING;
543 }
544 
563 static inline
565 {
566  return bt_value_get_type(value) == BT_VALUE_TYPE_ARRAY;
567 }
568 
587 static inline
589 {
590  return bt_value_get_type(value) == BT_VALUE_TYPE_MAP;
591 }
592 
629 extern bt_value *const bt_value_null;
630 
650 extern bt_value *bt_value_bool_create(void);
651 
667 extern bt_value *bt_value_bool_create_init(bt_bool raw_value);
668 
686 extern void bt_value_bool_set(bt_value *value, bt_bool raw_value);
687 
704 extern bt_bool bt_value_bool_get(const bt_value *value);
705 
726 
743 extern bt_value *bt_value_integer_unsigned_create_init(uint64_t raw_value);
744 
763 extern void bt_value_integer_unsigned_set(bt_value *value,
764  uint64_t raw_value);
765 
782 extern uint64_t bt_value_integer_unsigned_get(const bt_value *value);
783 
804 
821 extern bt_value *bt_value_integer_signed_create_init(int64_t raw_value);
822 
841 extern void bt_value_integer_signed_set(bt_value *value, int64_t raw_value);
842 
859 extern int64_t bt_value_integer_signed_get(const bt_value *value);
860 
880 extern bt_value *bt_value_real_create(void);
881 
897 extern bt_value *bt_value_real_create_init(double raw_value);
898 
916 extern void bt_value_real_set(bt_value *value, double raw_value);
917 
934 extern double bt_value_real_get(const bt_value *value);
935 
955 extern bt_value *bt_value_string_create(void);
956 
975 extern bt_value *bt_value_string_create_init(const char *raw_value);
976 
986  BT_VALUE_STRING_SET_STATUS_OK = __BT_FUNC_STATUS_OK,
987 
992  BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
994 
1020  const char *raw_value);
1021 
1042 extern const char *bt_value_string_get(const bt_value *value);
1043 
1060 extern bt_value *bt_value_array_create(void);
1061 
1073 
1078  BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1080 
1124  bt_value *value, bt_value *element_value);
1125 
1154 
1184  uint64_t raw_value);
1185 
1215  int64_t raw_value);
1216 
1244 bt_value_array_append_real_element(bt_value *value, double raw_value);
1245 
1274 bt_value_array_append_string_element(bt_value *value, const char *raw_value);
1275 
1309  bt_value **element_value);
1310 
1344  bt_value **element_value);
1345 
1356 
1363 
1402 bt_value_array_set_element_by_index(bt_value *value, uint64_t index,
1403  bt_value *element_value);
1404 
1433  uint64_t index);
1434 
1443  const bt_value *value, uint64_t index);
1444 
1461 extern uint64_t bt_value_array_get_length(const bt_value *value);
1462 
1479 static inline
1481 {
1482  return bt_value_array_get_length(value) == 0;
1483 }
1484 
1501 extern bt_value *bt_value_map_create(void);
1502 
1513 
1518  BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1520 
1575  bt_value *value, const char *key, bt_value *entry_value);
1576 
1609  bt_value *value, const char *key, bt_bool raw_value);
1610 
1644  uint64_t raw_value);
1645 
1678 bt_value_map_insert_signed_integer_entry(bt_value *value, const char *key,
1679  int64_t raw_value);
1680 
1713  bt_value *value, const char *key, double raw_value);
1714 
1747 bt_value_map_insert_string_entry(bt_value *value, const char *key,
1748  const char *raw_value);
1749 
1786 bt_value_map_insert_empty_array_entry(bt_value *value, const char *key,
1787  bt_value **entry_value);
1788 
1825 bt_value_map_insert_empty_map_entry(bt_value *value, const char *key,
1826  bt_value **entry_value);
1827 
1860  bt_value *value, const char *key);
1861 
1870  const bt_value *value, const char *key);
1871 
1882 
1888 
1894 
1901 
1933  (* bt_value_map_foreach_entry_func)(const char *key,
1934  bt_value *value, void *user_data);
1935 
1946 
1951  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED,
1952 
1957  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR = __BT_FUNC_STATUS_USER_ERROR,
1958 
1963  BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
1964 
1971 
2024  bt_value *value, bt_value_map_foreach_entry_func user_func,
2025  void *user_data);
2026 
2037 
2043 
2049 
2056 
2089  const bt_value *value, void *user_data);
2090 
2101 
2107 
2113 
2119 
2126 
2138  const bt_value *value,
2140  void *user_data);
2141 
2158 extern uint64_t bt_value_map_get_size(const bt_value *value);
2159 
2176 static inline
2178 {
2179  return bt_value_map_get_size(value) == 0;
2180 }
2181 
2202 extern bt_bool bt_value_map_has_entry(const bt_value *value,
2203  const char *key);
2204 
2214  BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK,
2215 
2220  BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
2222 
2289  bt_value *value, const bt_value *extension_value);
2290 
2302 typedef enum bt_value_copy_status {
2307  BT_VALUE_COPY_STATUS_OK = __BT_FUNC_STATUS_OK,
2308 
2313  BT_VALUE_COPY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
2315 
2341 extern bt_value_copy_status bt_value_copy(const bt_value *value,
2342  bt_value **copy_value);
2343 
2364 extern bt_bool bt_value_is_equal(const bt_value *a_value,
2365  const bt_value *b_value);
2366 
2389 extern void bt_value_get_ref(const bt_value *value);
2390 
2406 extern void bt_value_put_ref(const bt_value *value);
2407 
2422 #define BT_VALUE_PUT_REF_AND_RESET(_value) \
2423  do { \
2424  bt_value_put_ref(_value); \
2425  (_value) = NULL; \
2426  } while (0)
2427 
2453 #define BT_VALUE_MOVE_REF(_dst, _src) \
2454  do { \
2455  bt_value_put_ref(_dst); \
2456  (_dst) = (_src); \
2457  (_src) = NULL; \
2458  } while (0)
2459 
2464 #ifdef __cplusplus
2465 }
2466 #endif
2467 
2468 #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:1963
bt_value_map_foreach_entry_const_func_status
Status codes for bt_value_map_foreach_entry_const_func.
Definition: value.h:2031
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:2220
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:259
Null value.
Definition: value.h:253
Integer value.
Definition: value.h:267
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:516
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:992
Array value.
Definition: value.h:301
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:442
Success.
Definition: value.h:2214
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:1480
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:2106
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:1951
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:1887
bt_value_type
Value type enumerators.
Definition: value.h:248
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:2042
Unsigned integer value.
Definition: value.h:275
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:981
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:2048
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:1518
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:1067
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:418
Out of memory.
Definition: value.h:1078
Success.
Definition: value.h:1072
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:1361
bt_value_map_insert_entry_status
Status codes for the bt_value_map_insert_*() functions.
Definition: value.h:1507
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:1933
Other error.
Definition: value.h:2124
Success.
Definition: value.h:1945
bt_value_map_extend_status
Status codes for bt_value_map_extend().
Definition: value.h:2209
uint64_t bt_value_array_get_length(const bt_value *value)
Returns the length of the array value value.
Success.
Definition: value.h:986
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:1350
bt_value * bt_value_array_create(void)
Creates and returns an empty array value.
struct bt_value bt_value
Value.
Definition: types.h:107
Out of memory.
Definition: value.h:2313
User function error.
Definition: value.h:2112
String value.
Definition: value.h:295
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:307
Success.
Definition: value.h:2307
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:140
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:386
Success.
Definition: value.h:2036
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:588
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:2095
Success.
Definition: value.h:2100
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:2118
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:2177
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:1969
bt_value_map_foreach_entry_func_status
Status codes for bt_value_map_foreach_entry_func.
Definition: value.h:1876
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:2054
Success.
Definition: value.h:1355
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:1893
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:540
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:492
bt_value * bt_value_bool_create(void)
Creates and returns a boolean value initialized to BT_FALSE.
Signed integer value.
Definition: value.h:283
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:1957
bt_value_copy_status
Status codes for bt_value_copy().
Definition: value.h:2302
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:2088
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:1881
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:467
bt_value_map_foreach_entry_status
Status codes for bt_value_map_foreach_entry().
Definition: value.h:1940
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:1899
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:289
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:564
Success.
Definition: value.h:1512