| 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 | #ifndef __BT_IN_BABELTRACE_H |
| 11 | # error "Please include <babeltrace2/babeltrace.h> instead." |
| 12 | #endif |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | #include <stddef.h> |
| 16 | |
| 17 | #include <babeltrace2/types.h> |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | /*! |
| 24 | @defgroup api-val Values |
| 25 | |
| 26 | @brief |
| 27 | Generic, JSON-like basic data containers. |
| 28 | |
| 29 | <strong><em>Values</em></strong> are generic data containers. Except for |
| 30 | the fact that integer values are explicitly unsigned or signed because |
| 31 | of typing limitations, |
| 32 | \bt_name values are very similar to <a href="https://json.org/">JSON</a> |
| 33 | values. |
| 34 | |
| 35 | The value API is completely independent from the rest of the |
| 36 | \bt_api. |
| 37 | |
| 38 | \bt_c_comp initialization parameters, \ref bt_query_executor_create() |
| 39 | "query" parameters, as well as trace IR user attributes (for example, |
| 40 | bt_event_class_set_user_attributes()) use values. |
| 41 | |
| 42 | The available value types are: |
| 43 | |
| 44 | <dl> |
| 45 | <dt>Scalar values</dt> |
| 46 | <dd> |
| 47 | - Null |
| 48 | - Boolean |
| 49 | - Unsigned integer (64-bit range) |
| 50 | - Signed integer (64-bit range) |
| 51 | - Real (\c double range) |
| 52 | - String |
| 53 | </dd> |
| 54 | |
| 55 | <dt>Container values</dt> |
| 56 | <dd> |
| 57 | - Array |
| 58 | - Map (string to value) |
| 59 | </dd> |
| 60 | </dl> |
| 61 | |
| 62 | Values are \ref api-fund-shared-object "shared objects": get a new |
| 63 | reference with bt_value_get_ref() and put an existing reference with |
| 64 | bt_value_put_ref(). |
| 65 | |
| 66 | Some library functions \ref api-fund-freezing "freeze" values on |
| 67 | success. The documentation of those functions indicate this |
| 68 | postcondition. |
| 69 | |
| 70 | All the value types share the same C type, #bt_value. |
| 71 | |
| 72 | Get the type enumerator of a value with bt_value_get_type(). Get whether |
| 73 | or not a value type conceptually \em is a given type with the inline |
| 74 | bt_value_type_is() function. Get whether or not a value has a specific |
| 75 | type with one of the <code>bt_value_is_*()</code> inline helpers. |
| 76 | |
| 77 | The \em null value is special in that it's a singleton variable, |
| 78 | #bt_value_null. You can directly compare any value pointer to |
| 79 | #bt_value_null to check if it's a null value. Like other types of |
| 80 | values, the null value is a shared object: if you get a new null value |
| 81 | reference, you must eventually put it. |
| 82 | |
| 83 | Create a value with one of the <code>bt_value_*_create()</code> or |
| 84 | <code>bt_value_*_create_init()</code> functions. |
| 85 | |
| 86 | This documentation names the actual data that a scalar value wraps the |
| 87 | <em>raw value</em>. |
| 88 | |
| 89 | Set and get the raw values of scalar values with functions that are |
| 90 | named <code>bt_value_*_set()</code> and <code>bt_value_*_get()</code>. |
| 91 | |
| 92 | Check that two values are recursively equal with bt_value_is_equal(). |
| 93 | |
| 94 | Deep-copy a value with bt_value_copy(). |
| 95 | |
| 96 | Extend a map value with bt_value_map_extend(). |
| 97 | |
| 98 | The following table shows the available functions and types for each |
| 99 | type of value: |
| 100 | |
| 101 | <table> |
| 102 | <tr> |
| 103 | <th>Name |
| 104 | <th>Type enumerator |
| 105 | <th>Type query function |
| 106 | <th>Creation functions |
| 107 | <th>Writing functions |
| 108 | <th>Reading functions |
| 109 | <tr> |
| 110 | <th>\em Null |
| 111 | <td>#BT_VALUE_TYPE_NULL |
| 112 | <td>bt_value_is_null() |
| 113 | <td>\em N/A (use the #bt_value_null variable directly) |
| 114 | <td>\em N/A |
| 115 | <td>\em N/A |
| 116 | <tr> |
| 117 | <th>\em Boolean |
| 118 | <td>#BT_VALUE_TYPE_BOOL |
| 119 | <td>bt_value_is_bool() |
| 120 | <td> |
| 121 | bt_value_bool_create()<br> |
| 122 | bt_value_bool_create_init() |
| 123 | <td>bt_value_bool_set() |
| 124 | <td>bt_value_bool_get() |
| 125 | <tr> |
| 126 | <th><em>Unsigned integer</em> |
| 127 | <td>#BT_VALUE_TYPE_UNSIGNED_INTEGER |
| 128 | <td>bt_value_is_unsigned_integer() |
| 129 | <td> |
| 130 | bt_value_integer_unsigned_create()<br> |
| 131 | bt_value_integer_unsigned_create_init() |
| 132 | <td>bt_value_integer_unsigned_set() |
| 133 | <td>bt_value_integer_unsigned_get() |
| 134 | <tr> |
| 135 | <th><em>Signed integer</em> |
| 136 | <td>#BT_VALUE_TYPE_SIGNED_INTEGER |
| 137 | <td>bt_value_is_signed_integer() |
| 138 | <td> |
| 139 | bt_value_integer_signed_create()<br> |
| 140 | bt_value_integer_signed_create_init() |
| 141 | <td>bt_value_integer_signed_set() |
| 142 | <td>bt_value_integer_signed_get() |
| 143 | <tr> |
| 144 | <th>\em Real |
| 145 | <td>#BT_VALUE_TYPE_REAL |
| 146 | <td>bt_value_is_real() |
| 147 | <td> |
| 148 | bt_value_real_create()<br> |
| 149 | bt_value_real_create_init() |
| 150 | <td>bt_value_real_set() |
| 151 | <td>bt_value_real_get() |
| 152 | <tr> |
| 153 | <th>\em String |
| 154 | <td>#BT_VALUE_TYPE_STRING |
| 155 | <td>bt_value_is_string() |
| 156 | <td> |
| 157 | bt_value_string_create()<br> |
| 158 | bt_value_string_create_init() |
| 159 | <td>bt_value_string_set() |
| 160 | <td>bt_value_string_get() |
| 161 | <tr> |
| 162 | <th>\em Array |
| 163 | <td>#BT_VALUE_TYPE_ARRAY |
| 164 | <td>bt_value_is_array() |
| 165 | <td> |
| 166 | bt_value_array_create() |
| 167 | <td> |
| 168 | bt_value_array_append_element()<br> |
| 169 | bt_value_array_append_bool_element()<br> |
| 170 | bt_value_array_append_unsigned_integer_element()<br> |
| 171 | bt_value_array_append_signed_integer_element()<br> |
| 172 | bt_value_array_append_real_element()<br> |
| 173 | bt_value_array_append_string_element()<br> |
| 174 | bt_value_array_append_empty_array_element()<br> |
| 175 | bt_value_array_append_empty_map_element()<br> |
| 176 | bt_value_array_set_element_by_index() |
| 177 | <td> |
| 178 | bt_value_array_get_length()<br> |
| 179 | bt_value_array_is_empty()<br> |
| 180 | bt_value_array_borrow_element_by_index()<br> |
| 181 | bt_value_array_borrow_element_by_index_const() |
| 182 | <tr> |
| 183 | <th>\em Map |
| 184 | <td>#BT_VALUE_TYPE_MAP |
| 185 | <td>bt_value_is_map() |
| 186 | <td> |
| 187 | bt_value_map_create() |
| 188 | <td> |
| 189 | bt_value_map_insert_entry()<br> |
| 190 | bt_value_map_insert_bool_entry()<br> |
| 191 | bt_value_map_insert_unsigned_integer_entry()<br> |
| 192 | bt_value_map_insert_signed_integer_entry()<br> |
| 193 | bt_value_map_insert_real_entry()<br> |
| 194 | bt_value_map_insert_string_entry()<br> |
| 195 | bt_value_map_insert_empty_array_entry()<br> |
| 196 | bt_value_map_insert_empty_map_entry()<br> |
| 197 | bt_value_map_extend() |
| 198 | <td> |
| 199 | bt_value_map_get_size()<br> |
| 200 | bt_value_map_is_empty()<br> |
| 201 | bt_value_map_has_entry()<br> |
| 202 | bt_value_map_borrow_entry_value()<br> |
| 203 | bt_value_map_borrow_entry_value_const()<br> |
| 204 | bt_value_map_foreach_entry()<br> |
| 205 | bt_value_map_foreach_entry_const() |
| 206 | </table> |
| 207 | */ |
| 208 | |
| 209 | /*! @{ */ |
| 210 | |
| 211 | /*! |
| 212 | @name Type |
| 213 | @{ |
| 214 | |
| 215 | @typedef struct bt_value bt_value; |
| 216 | |
| 217 | @brief |
| 218 | Value. |
| 219 | |
| 220 | @} |
| 221 | */ |
| 222 | |
| 223 | /*! |
| 224 | @name Type query |
| 225 | @{ |
| 226 | */ |
| 227 | |
| 228 | /*! |
| 229 | @brief |
| 230 | Value type enumerators. |
| 231 | */ |
| 232 | typedef enum bt_value_type { |
| 233 | /*! |
| 234 | @brief |
| 235 | Null value. |
| 236 | */ |
| 237 | BT_VALUE_TYPE_NULL = 1 << 0, |
| 238 | |
| 239 | /*! |
| 240 | @brief |
| 241 | Boolean value. |
| 242 | */ |
| 243 | BT_VALUE_TYPE_BOOL = 1 << 1, |
| 244 | |
| 245 | /*! |
| 246 | @brief |
| 247 | Integer value. |
| 248 | |
| 249 | No value has this type: use it with bt_value_type_is(). |
| 250 | */ |
| 251 | BT_VALUE_TYPE_INTEGER = 1 << 2, |
| 252 | |
| 253 | /*! |
| 254 | @brief |
| 255 | Unsigned integer value. |
| 256 | |
| 257 | This type conceptually inherits #BT_VALUE_TYPE_INTEGER. |
| 258 | */ |
| 259 | BT_VALUE_TYPE_UNSIGNED_INTEGER = (1 << 3) | BT_VALUE_TYPE_INTEGER, |
| 260 | |
| 261 | /*! |
| 262 | @brief |
| 263 | Signed integer value. |
| 264 | |
| 265 | This type conceptually inherits #BT_VALUE_TYPE_INTEGER. |
| 266 | */ |
| 267 | BT_VALUE_TYPE_SIGNED_INTEGER = (1 << 4) | BT_VALUE_TYPE_INTEGER, |
| 268 | |
| 269 | /*! |
| 270 | @brief |
| 271 | Real value. |
| 272 | */ |
| 273 | BT_VALUE_TYPE_REAL = 1 << 5, |
| 274 | |
| 275 | /*! |
| 276 | @brief |
| 277 | String value. |
| 278 | */ |
| 279 | BT_VALUE_TYPE_STRING = 1 << 6, |
| 280 | |
| 281 | /*! |
| 282 | @brief |
| 283 | Array value. |
| 284 | */ |
| 285 | BT_VALUE_TYPE_ARRAY = 1 << 7, |
| 286 | |
| 287 | /*! |
| 288 | @brief |
| 289 | Map value. |
| 290 | */ |
| 291 | BT_VALUE_TYPE_MAP = 1 << 8, |
| 292 | } bt_value_type; |
| 293 | |
| 294 | /*! |
| 295 | @brief |
| 296 | Returns the type enumerator of the value \bt_p{value}. |
| 297 | |
| 298 | @param[in] value |
| 299 | Value of which to get the type enumerator |
| 300 | |
| 301 | @returns |
| 302 | Type enumerator of \bt_p{value}. |
| 303 | |
| 304 | @bt_pre_not_null{value} |
| 305 | |
| 306 | @sa bt_value_type_is() — |
| 307 | Returns whether or not the type of a value conceptually is a given |
| 308 | type. |
| 309 | @sa bt_value_is_null() — |
| 310 | Returns whether or not a value is a null value. |
| 311 | @sa bt_value_is_bool() — |
| 312 | Returns whether or not a value is a boolean value. |
| 313 | @sa bt_value_is_unsigned_integer() — |
| 314 | Returns whether or not a value is an unsigned integer value. |
| 315 | @sa bt_value_is_signed_integer() — |
| 316 | Returns whether or not a value is a signed integer value. |
| 317 | @sa bt_value_is_real() — |
| 318 | Returns whether or not a value is a real value. |
| 319 | @sa bt_value_is_string() — |
| 320 | Returns whether or not a value is a string value. |
| 321 | @sa bt_value_is_array() — |
| 322 | Returns whether or not a value is an array value. |
| 323 | @sa bt_value_is_map() — |
| 324 | Returns whether or not a value is a map value. |
| 325 | */ |
| 326 | extern bt_value_type bt_value_get_type(const bt_value *value); |
| 327 | |
| 328 | /*! |
| 329 | @brief |
| 330 | Returns whether or not the value type \bt_p{type} conceptually |
| 331 | \em is the value type \bt_p{other_type}. |
| 332 | |
| 333 | For example, an unsigned integer value conceptually \em is an integer |
| 334 | value, so |
| 335 | |
| 336 | @code |
| 337 | bt_value_type_is(BT_VALUE_TYPE_UNSIGNED_INTEGER, BT_VALUE_TYPE_INTEGER) |
| 338 | @endcode |
| 339 | |
| 340 | returns #BT_TRUE. |
| 341 | |
| 342 | @param[in] type |
| 343 | Value type to check against \bt_p{other_type}. |
| 344 | @param[in] other_type |
| 345 | Value type against which to check \bt_p{type}. |
| 346 | |
| 347 | @returns |
| 348 | #BT_TRUE if \bt_p{type} conceptually \em is \bt_p{other_type}. |
| 349 | |
| 350 | @sa bt_value_get_type() — |
| 351 | Returns the type enumerator of a value. |
| 352 | @sa bt_value_is_null() — |
| 353 | Returns whether or not a value is a null value. |
| 354 | @sa bt_value_is_bool() — |
| 355 | Returns whether or not a value is a boolean value. |
| 356 | @sa bt_value_is_unsigned_integer() — |
| 357 | Returns whether or not a value is an unsigned integer value. |
| 358 | @sa bt_value_is_signed_integer() — |
| 359 | Returns whether or not a value is a signed integer value. |
| 360 | @sa bt_value_is_real() — |
| 361 | Returns whether or not a value is a real value. |
| 362 | @sa bt_value_is_string() — |
| 363 | Returns whether or not a value is a string value. |
| 364 | @sa bt_value_is_array() — |
| 365 | Returns whether or not a value is an array value. |
| 366 | @sa bt_value_is_map() — |
| 367 | Returns whether or not a value is a map value. |
| 368 | */ |
| 369 | static inline |
| 370 | bt_bool bt_value_type_is(const bt_value_type type, |
| 371 | const bt_value_type other_type) |
| 372 | { |
| 373 | return (type & other_type) == other_type; |
| 374 | } |
| 375 | |
| 376 | /*! |
| 377 | @brief |
| 378 | Returns whether or not the value \bt_p{value} is a null value. |
| 379 | |
| 380 | @note |
| 381 | Because all null values point to the same null value singleton, you |
| 382 | can also directly compare \bt_p{value} to the #bt_value_null |
| 383 | variable. |
| 384 | |
| 385 | @param[in] value |
| 386 | Value to check. |
| 387 | |
| 388 | @returns |
| 389 | #BT_TRUE if \bt_p{value} is a null value. |
| 390 | |
| 391 | @bt_pre_not_null{value} |
| 392 | |
| 393 | @sa bt_value_get_type() — |
| 394 | Returns the type enumerator of a value. |
| 395 | @sa bt_value_type_is() — |
| 396 | Returns whether or not the type of a value conceptually is a given |
| 397 | type. |
| 398 | @sa #bt_value_null — |
| 399 | The null value singleton. |
| 400 | */ |
| 401 | static inline |
| 402 | bt_bool bt_value_is_null(const bt_value *value) |
| 403 | { |
| 404 | return bt_value_get_type(value) == BT_VALUE_TYPE_NULL; |
| 405 | } |
| 406 | |
| 407 | /*! |
| 408 | @brief |
| 409 | Returns whether or not the value \bt_p{value} is a boolean value. |
| 410 | |
| 411 | @param[in] value |
| 412 | Value to check. |
| 413 | |
| 414 | @returns |
| 415 | #BT_TRUE if \bt_p{value} is a boolean value. |
| 416 | |
| 417 | @bt_pre_not_null{value} |
| 418 | |
| 419 | @sa bt_value_get_type() — |
| 420 | Returns the type enumerator of a value. |
| 421 | @sa bt_value_type_is() — |
| 422 | Returns whether or not the type of a value conceptually is a given |
| 423 | type. |
| 424 | */ |
| 425 | static inline |
| 426 | bt_bool bt_value_is_bool(const bt_value *value) |
| 427 | { |
| 428 | return bt_value_get_type(value) == BT_VALUE_TYPE_BOOL; |
| 429 | } |
| 430 | |
| 431 | /*! |
| 432 | @brief |
| 433 | Returns whether or not the value \bt_p{value} is an unsigned integer |
| 434 | value. |
| 435 | |
| 436 | @param[in] value |
| 437 | Value to check. |
| 438 | |
| 439 | @returns |
| 440 | #BT_TRUE if \bt_p{value} is an unsigned integer value. |
| 441 | |
| 442 | @bt_pre_not_null{value} |
| 443 | |
| 444 | @sa bt_value_get_type() — |
| 445 | Returns the type enumerator of a value. |
| 446 | @sa bt_value_type_is() — |
| 447 | Returns whether or not the type of a value conceptually is a given |
| 448 | type. |
| 449 | */ |
| 450 | static inline |
| 451 | bt_bool bt_value_is_unsigned_integer(const bt_value *value) |
| 452 | { |
| 453 | return bt_value_get_type(value) == BT_VALUE_TYPE_UNSIGNED_INTEGER; |
| 454 | } |
| 455 | |
| 456 | /*! |
| 457 | @brief |
| 458 | Returns whether or not the value \bt_p{value} is a signed integer |
| 459 | value. |
| 460 | |
| 461 | @param[in] value |
| 462 | Value to check. |
| 463 | |
| 464 | @returns |
| 465 | #BT_TRUE if \bt_p{value} is a signed integer value. |
| 466 | |
| 467 | @bt_pre_not_null{value} |
| 468 | |
| 469 | @sa bt_value_get_type() — |
| 470 | Returns the type enumerator of a value. |
| 471 | @sa bt_value_type_is() — |
| 472 | Returns whether or not the type of a value conceptually is a given |
| 473 | type. |
| 474 | */ |
| 475 | static inline |
| 476 | bt_bool bt_value_is_signed_integer(const bt_value *value) |
| 477 | { |
| 478 | return bt_value_get_type(value) == BT_VALUE_TYPE_SIGNED_INTEGER; |
| 479 | } |
| 480 | |
| 481 | /*! |
| 482 | @brief |
| 483 | Returns whether or not the value \bt_p{value} is a real value. |
| 484 | |
| 485 | @param[in] value |
| 486 | Value to check. |
| 487 | |
| 488 | @returns |
| 489 | #BT_TRUE if \bt_p{value} is a real value. |
| 490 | |
| 491 | @bt_pre_not_null{value} |
| 492 | |
| 493 | @sa bt_value_get_type() — |
| 494 | Returns the type enumerator of a value. |
| 495 | @sa bt_value_type_is() — |
| 496 | Returns whether or not the type of a value conceptually is a given |
| 497 | type. |
| 498 | */ |
| 499 | static inline |
| 500 | bt_bool bt_value_is_real(const bt_value *value) |
| 501 | { |
| 502 | return bt_value_get_type(value) == BT_VALUE_TYPE_REAL; |
| 503 | } |
| 504 | |
| 505 | /*! |
| 506 | @brief |
| 507 | Returns whether or not the value \bt_p{value} is a string value. |
| 508 | |
| 509 | @param[in] value |
| 510 | Value to check. |
| 511 | |
| 512 | @returns |
| 513 | #BT_TRUE if \bt_p{value} is a string value. |
| 514 | |
| 515 | @bt_pre_not_null{value} |
| 516 | |
| 517 | @sa bt_value_get_type() — |
| 518 | Returns the type enumerator of a value. |
| 519 | @sa bt_value_type_is() — |
| 520 | Returns whether or not the type of a value conceptually is a given |
| 521 | type. |
| 522 | */ |
| 523 | static inline |
| 524 | bt_bool bt_value_is_string(const bt_value *value) |
| 525 | { |
| 526 | return bt_value_get_type(value) == BT_VALUE_TYPE_STRING; |
| 527 | } |
| 528 | |
| 529 | /*! |
| 530 | @brief |
| 531 | Returns whether or not the value \bt_p{value} is an array value. |
| 532 | |
| 533 | @param[in] value |
| 534 | Value to check. |
| 535 | |
| 536 | @returns |
| 537 | #BT_TRUE if \bt_p{value} is an array value. |
| 538 | |
| 539 | @bt_pre_not_null{value} |
| 540 | |
| 541 | @sa bt_value_get_type() — |
| 542 | Returns the type enumerator of a value. |
| 543 | @sa bt_value_type_is() — |
| 544 | Returns whether or not the type of a value conceptually is a given |
| 545 | type. |
| 546 | */ |
| 547 | static inline |
| 548 | bt_bool bt_value_is_array(const bt_value *value) |
| 549 | { |
| 550 | return bt_value_get_type(value) == BT_VALUE_TYPE_ARRAY; |
| 551 | } |
| 552 | |
| 553 | /*! |
| 554 | @brief |
| 555 | Returns whether or not the value \bt_p{value} is a map value. |
| 556 | |
| 557 | @param[in] value |
| 558 | Value to check. |
| 559 | |
| 560 | @returns |
| 561 | #BT_TRUE if \bt_p{value} is a map value. |
| 562 | |
| 563 | @bt_pre_not_null{value} |
| 564 | |
| 565 | @sa bt_value_get_type() — |
| 566 | Returns the type enumerator of a value. |
| 567 | @sa bt_value_type_is() — |
| 568 | Returns whether or not the type of a value conceptually is a given |
| 569 | type. |
| 570 | */ |
| 571 | static inline |
| 572 | bt_bool bt_value_is_map(const bt_value *value) |
| 573 | { |
| 574 | return bt_value_get_type(value) == BT_VALUE_TYPE_MAP; |
| 575 | } |
| 576 | |
| 577 | /*! @} */ |
| 578 | |
| 579 | /*! |
| 580 | @name Null value |
| 581 | @{ |
| 582 | */ |
| 583 | |
| 584 | /*! |
| 585 | @brief |
| 586 | The null value singleton. |
| 587 | |
| 588 | This is the \em only instance of a null value. |
| 589 | |
| 590 | Like any type of value, the null value is a shared object: if you get a |
| 591 | new null value reference with bt_value_get_ref(), you must eventually |
| 592 | put it with bt_value_put_ref(). The null value singleton's reference |
| 593 | count must never reach 0: libbabeltrace2 logs a warning message when |
| 594 | this programming error occurs. |
| 595 | |
| 596 | Because all null values point to the same null value singleton, you can |
| 597 | directly compare a value to the \c bt_value_null variable. |
| 598 | |
| 599 | @attention |
| 600 | @parblock |
| 601 | \c bt_value_null is different from \c NULL: the former is a true |
| 602 | \bt_name value object while the latter is a C definition which |
| 603 | usually means "no pointer". |
| 604 | |
| 605 | For example, bt_value_map_borrow_entry_value() can return |
| 606 | \c bt_value_null if the requested key is mapped to a null value, but |
| 607 | it can also return \c NULL if the key is not found. |
| 608 | @endparblock |
| 609 | |
| 610 | @sa bt_value_is_null() — |
| 611 | Returns whether or not a value is a null value. |
| 612 | */ |
| 613 | extern bt_value *const bt_value_null; |
| 614 | |
| 615 | /*! @} */ |
| 616 | |
| 617 | /*! |
| 618 | @name Boolean value |
| 619 | @{ |
| 620 | */ |
| 621 | |
| 622 | /*! |
| 623 | @brief |
| 624 | Creates and returns a boolean value initialized to #BT_FALSE. |
| 625 | |
| 626 | The returned value has the type #BT_VALUE_TYPE_BOOL. |
| 627 | |
| 628 | @returns |
| 629 | New boolean value reference, or \c NULL on memory error. |
| 630 | |
| 631 | @sa bt_value_bool_create_init() — |
| 632 | Creates a boolean value with a given initial raw value. |
| 633 | */ |
| 634 | extern bt_value *bt_value_bool_create(void); |
| 635 | |
| 636 | /*! |
| 637 | @brief |
| 638 | Creates and returns a boolean value initialized to \bt_p{raw_value}. |
| 639 | |
| 640 | The returned value has the type #BT_VALUE_TYPE_BOOL. |
| 641 | |
| 642 | @param[in] raw_value |
| 643 | Initial raw value of the boolean value to create. |
| 644 | |
| 645 | @returns |
| 646 | New boolean value reference, or \c NULL on memory error. |
| 647 | |
| 648 | @sa bt_value_bool_create() — |
| 649 | Creates a boolean value initialized to #BT_FALSE. |
| 650 | */ |
| 651 | extern bt_value *bt_value_bool_create_init(bt_bool raw_value); |
| 652 | |
| 653 | /*! |
| 654 | @brief |
| 655 | Sets the raw value of the boolean value \bt_p{value} to |
| 656 | \bt_p{raw_value}. |
| 657 | |
| 658 | @param[in] value |
| 659 | Boolean value of which to set the raw value to \bt_p{raw_value}. |
| 660 | @param[in] raw_value |
| 661 | New raw value of \bt_p{value}. |
| 662 | |
| 663 | @bt_pre_not_null{value} |
| 664 | @bt_pre_is_bool_val{value} |
| 665 | @bt_pre_hot{value} |
| 666 | |
| 667 | @sa bt_value_bool_get() — |
| 668 | Returns the raw value of a boolean value. |
| 669 | */ |
| 670 | extern void bt_value_bool_set(bt_value *value, bt_bool raw_value); |
| 671 | |
| 672 | /*! |
| 673 | @brief |
| 674 | Returns the raw value of the boolean value \bt_p{value}. |
| 675 | |
| 676 | @param[in] value |
| 677 | Boolean value of which to get the raw value. |
| 678 | |
| 679 | @returns |
| 680 | Raw value of \bt_p{value}. |
| 681 | |
| 682 | @bt_pre_not_null{value} |
| 683 | @bt_pre_is_bool_val{value} |
| 684 | |
| 685 | @sa bt_value_bool_set() — |
| 686 | Sets the raw value of a boolean value. |
| 687 | */ |
| 688 | extern bt_bool bt_value_bool_get(const bt_value *value); |
| 689 | |
| 690 | /*! @} */ |
| 691 | |
| 692 | /*! |
| 693 | @name Unsigned integer value |
| 694 | @{ |
| 695 | */ |
| 696 | |
| 697 | /*! |
| 698 | @brief |
| 699 | Creates and returns an unsigned integer value initialized to 0. |
| 700 | |
| 701 | The returned value has the type #BT_VALUE_TYPE_UNSIGNED_INTEGER. |
| 702 | |
| 703 | @returns |
| 704 | New unsigned integer value reference, or \c NULL on memory error. |
| 705 | |
| 706 | @sa bt_value_integer_unsigned_create_init() — |
| 707 | Creates an unsigned integer value with a given initial raw value. |
| 708 | */ |
| 709 | extern bt_value *bt_value_integer_unsigned_create(void); |
| 710 | |
| 711 | /*! |
| 712 | @brief |
| 713 | Creates and returns an unsigned integer value initialized to |
| 714 | \bt_p{raw_value}. |
| 715 | |
| 716 | The returned value has the type #BT_VALUE_TYPE_UNSIGNED_INTEGER. |
| 717 | |
| 718 | @param[in] raw_value |
| 719 | Initial raw value of the unsigned integer value to create. |
| 720 | |
| 721 | @returns |
| 722 | New unsigned integer value reference, or \c NULL on memory error. |
| 723 | |
| 724 | @sa bt_value_bool_create() — |
| 725 | Creates an unsigned integer value initialized to 0. |
| 726 | */ |
| 727 | extern bt_value *bt_value_integer_unsigned_create_init(uint64_t raw_value); |
| 728 | |
| 729 | /*! |
| 730 | @brief |
| 731 | Sets the raw value of the unsigned integer value \bt_p{value} to |
| 732 | \bt_p{raw_value}. |
| 733 | |
| 734 | @param[in] value |
| 735 | Unsigned integer value of which to set the raw value to |
| 736 | \bt_p{raw_value}. |
| 737 | @param[in] raw_value |
| 738 | New raw value of \bt_p{value}. |
| 739 | |
| 740 | @bt_pre_not_null{value} |
| 741 | @bt_pre_is_uint_val{value} |
| 742 | @bt_pre_hot{value} |
| 743 | |
| 744 | @sa bt_value_integer_unsigned_get() — |
| 745 | Returns the raw value of an unsigned integer value. |
| 746 | */ |
| 747 | extern void bt_value_integer_unsigned_set(bt_value *value, |
| 748 | uint64_t raw_value); |
| 749 | |
| 750 | /*! |
| 751 | @brief |
| 752 | Returns the raw value of the unsigned integer value \bt_p{value}. |
| 753 | |
| 754 | @param[in] value |
| 755 | Unsigned integer value of which to get the raw value. |
| 756 | |
| 757 | @returns |
| 758 | Raw value of \bt_p{value}. |
| 759 | |
| 760 | @bt_pre_not_null{value} |
| 761 | @bt_pre_is_uint_val{value} |
| 762 | |
| 763 | @sa bt_value_integer_unsigned_set() — |
| 764 | Sets the raw value of an unsigned integer value. |
| 765 | */ |
| 766 | extern uint64_t bt_value_integer_unsigned_get(const bt_value *value); |
| 767 | |
| 768 | /*! @} */ |
| 769 | |
| 770 | /*! |
| 771 | @name Signed integer value |
| 772 | @{ |
| 773 | */ |
| 774 | |
| 775 | /*! |
| 776 | @brief |
| 777 | Creates and returns a signed integer value initialized to 0. |
| 778 | |
| 779 | The returned value has the type #BT_VALUE_TYPE_SIGNED_INTEGER. |
| 780 | |
| 781 | @returns |
| 782 | New signed integer value reference, or \c NULL on memory error. |
| 783 | |
| 784 | @sa bt_value_integer_signed_create_init() — |
| 785 | Creates a signed integer value with a given initial raw value. |
| 786 | */ |
| 787 | extern bt_value *bt_value_integer_signed_create(void); |
| 788 | |
| 789 | /*! |
| 790 | @brief |
| 791 | Creates and returns a signed integer value initialized to |
| 792 | \bt_p{raw_value}. |
| 793 | |
| 794 | The returned value has the type #BT_VALUE_TYPE_SIGNED_INTEGER. |
| 795 | |
| 796 | @param[in] raw_value |
| 797 | Initial raw value of the signed integer value to create. |
| 798 | |
| 799 | @returns |
| 800 | New signed integer value reference, or \c NULL on memory error. |
| 801 | |
| 802 | @sa bt_value_bool_create() — |
| 803 | Creates a signed integer value initialized to 0. |
| 804 | */ |
| 805 | extern bt_value *bt_value_integer_signed_create_init(int64_t raw_value); |
| 806 | |
| 807 | /*! |
| 808 | @brief |
| 809 | Sets the raw value of the signed integer value \bt_p{value} to |
| 810 | \bt_p{raw_value}. |
| 811 | |
| 812 | @param[in] value |
| 813 | Signed integer value of which to set the raw value to |
| 814 | \bt_p{raw_value}. |
| 815 | @param[in] raw_value |
| 816 | New raw value of \bt_p{value}. |
| 817 | |
| 818 | @bt_pre_not_null{value} |
| 819 | @bt_pre_is_sint_val{value} |
| 820 | @bt_pre_hot{value} |
| 821 | |
| 822 | @sa bt_value_integer_signed_get() — |
| 823 | Returns the raw value of a signed integer value. |
| 824 | */ |
| 825 | extern void bt_value_integer_signed_set(bt_value *value, int64_t raw_value); |
| 826 | |
| 827 | /*! |
| 828 | @brief |
| 829 | Returns the raw value of the signed integer value \bt_p{value}. |
| 830 | |
| 831 | @param[in] value |
| 832 | Signed integer value of which to get the raw value. |
| 833 | |
| 834 | @returns |
| 835 | Raw value of \bt_p{value}. |
| 836 | |
| 837 | @bt_pre_not_null{value} |
| 838 | @bt_pre_is_sint_val{value} |
| 839 | |
| 840 | @sa bt_value_integer_signed_set() — |
| 841 | Sets the raw value of a signed integer value. |
| 842 | */ |
| 843 | extern int64_t bt_value_integer_signed_get(const bt_value *value); |
| 844 | |
| 845 | /*! @} */ |
| 846 | |
| 847 | /*! |
| 848 | @name Real value |
| 849 | @{ |
| 850 | */ |
| 851 | |
| 852 | /*! |
| 853 | @brief |
| 854 | Creates and returns a real value initialized to 0. |
| 855 | |
| 856 | The returned value has the type #BT_VALUE_TYPE_REAL. |
| 857 | |
| 858 | @returns |
| 859 | New real value reference, or \c NULL on memory error. |
| 860 | |
| 861 | @sa bt_value_real_create_init() — |
| 862 | Creates a real value with a given initial raw value. |
| 863 | */ |
| 864 | extern bt_value *bt_value_real_create(void); |
| 865 | |
| 866 | /*! |
| 867 | @brief |
| 868 | Creates and returns a real value initialized to \bt_p{raw_value}. |
| 869 | |
| 870 | The returned value has the type #BT_VALUE_TYPE_REAL. |
| 871 | |
| 872 | @param[in] raw_value |
| 873 | Initial raw value of the real value to create. |
| 874 | |
| 875 | @returns |
| 876 | New real value reference, or \c NULL on memory error. |
| 877 | |
| 878 | @sa bt_value_real_create() — |
| 879 | Creates a real value initialized to 0. |
| 880 | */ |
| 881 | extern bt_value *bt_value_real_create_init(double raw_value); |
| 882 | |
| 883 | /*! |
| 884 | @brief |
| 885 | Sets the raw value of the real value \bt_p{value} to |
| 886 | \bt_p{raw_value}. |
| 887 | |
| 888 | @param[in] value |
| 889 | Real value of which to set the raw value to \bt_p{raw_value}. |
| 890 | @param[in] raw_value |
| 891 | New raw value of \bt_p{value}. |
| 892 | |
| 893 | @bt_pre_not_null{value} |
| 894 | @bt_pre_is_real_val{value} |
| 895 | @bt_pre_hot{value} |
| 896 | |
| 897 | @sa bt_value_real_get() — |
| 898 | Returns the raw value of a real value. |
| 899 | */ |
| 900 | extern void bt_value_real_set(bt_value *value, double raw_value); |
| 901 | |
| 902 | /*! |
| 903 | @brief |
| 904 | Returns the raw value of the real value \bt_p{value}. |
| 905 | |
| 906 | @param[in] value |
| 907 | Real value of which to get the raw value. |
| 908 | |
| 909 | @returns |
| 910 | Raw value of \bt_p{value}. |
| 911 | |
| 912 | @bt_pre_not_null{value} |
| 913 | @bt_pre_is_real_val{value} |
| 914 | |
| 915 | @sa bt_value_real_set() — |
| 916 | Sets the raw value of a real value. |
| 917 | */ |
| 918 | extern double bt_value_real_get(const bt_value *value); |
| 919 | |
| 920 | /*! @} */ |
| 921 | |
| 922 | /*! |
| 923 | @name String value |
| 924 | @{ |
| 925 | */ |
| 926 | |
| 927 | /*! |
| 928 | @brief |
| 929 | Creates and returns an empty string value. |
| 930 | |
| 931 | The returned value has the type #BT_VALUE_TYPE_STRING. |
| 932 | |
| 933 | @returns |
| 934 | New string value reference, or \c NULL on memory error. |
| 935 | |
| 936 | @sa bt_value_string_create_init() — |
| 937 | Creates a string value with a given initial raw value. |
| 938 | */ |
| 939 | extern bt_value *bt_value_string_create(void); |
| 940 | |
| 941 | /*! |
| 942 | @brief |
| 943 | Creates and returns a string value initialized to a copy of |
| 944 | \bt_p{raw_value}. |
| 945 | |
| 946 | The returned value has the type #BT_VALUE_TYPE_STRING. |
| 947 | |
| 948 | @param[in] raw_value |
| 949 | Initial raw value of the string value to create (copied). |
| 950 | |
| 951 | @returns |
| 952 | New string value reference, or \c NULL on memory error. |
| 953 | |
| 954 | @bt_pre_not_null{raw_value} |
| 955 | |
| 956 | @sa bt_value_string_create() — |
| 957 | Creates an empty string value. |
| 958 | */ |
| 959 | extern bt_value *bt_value_string_create_init(const char *raw_value); |
| 960 | |
| 961 | /*! |
| 962 | @brief |
| 963 | Status codes for bt_value_string_set(). |
| 964 | */ |
| 965 | typedef enum bt_value_string_set_status { |
| 966 | /*! |
| 967 | @brief |
| 968 | Success. |
| 969 | */ |
| 970 | BT_VALUE_STRING_SET_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 971 | |
| 972 | /*! |
| 973 | @brief |
| 974 | Out of memory. |
| 975 | */ |
| 976 | BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 977 | } bt_value_string_set_status; |
| 978 | |
| 979 | /*! |
| 980 | @brief |
| 981 | Sets the raw value of the string value \bt_p{value} to a copy of |
| 982 | \bt_p{raw_value}. |
| 983 | |
| 984 | @param[in] value |
| 985 | String value of which to set the raw value to a copy of |
| 986 | \bt_p{raw_value}. |
| 987 | @param[in] raw_value |
| 988 | New raw value of \bt_p{value} (copied). |
| 989 | |
| 990 | @retval #BT_VALUE_STRING_SET_STATUS_OK |
| 991 | Success. |
| 992 | @retval #BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR |
| 993 | Out of memory. |
| 994 | |
| 995 | @bt_pre_not_null{value} |
| 996 | @bt_pre_is_string_val{value} |
| 997 | @bt_pre_hot{value} |
| 998 | @bt_pre_not_null{raw_value} |
| 999 | |
| 1000 | @sa bt_value_string_get() — |
| 1001 | Returns the raw value of a string value. |
| 1002 | */ |
| 1003 | extern bt_value_string_set_status bt_value_string_set(bt_value *value, |
| 1004 | const char *raw_value); |
| 1005 | |
| 1006 | /*! |
| 1007 | @brief |
| 1008 | Returns the raw value of the string value \bt_p{value}. |
| 1009 | |
| 1010 | @param[in] value |
| 1011 | String value of which to get the raw value. |
| 1012 | |
| 1013 | @returns |
| 1014 | @parblock |
| 1015 | Raw value of \bt_p{value}. |
| 1016 | |
| 1017 | The returned pointer remains valid until \bt_p{value} is modified. |
| 1018 | @endparblock |
| 1019 | |
| 1020 | @bt_pre_not_null{value} |
| 1021 | @bt_pre_is_string_val{value} |
| 1022 | |
| 1023 | @sa bt_value_string_set() — |
| 1024 | Sets the raw value of a string value. |
| 1025 | */ |
| 1026 | extern const char *bt_value_string_get(const bt_value *value); |
| 1027 | |
| 1028 | /*! @} */ |
| 1029 | |
| 1030 | /*! |
| 1031 | @name Array value |
| 1032 | @{ |
| 1033 | */ |
| 1034 | |
| 1035 | /*! |
| 1036 | @brief |
| 1037 | Creates and returns an empty array value. |
| 1038 | |
| 1039 | The returned value has the type #BT_VALUE_TYPE_ARRAY. |
| 1040 | |
| 1041 | @returns |
| 1042 | New array value reference, or \c NULL on memory error. |
| 1043 | */ |
| 1044 | extern bt_value *bt_value_array_create(void); |
| 1045 | |
| 1046 | /*! |
| 1047 | @brief |
| 1048 | Status codes for the <code>bt_value_array_append_*()</code> |
| 1049 | functions. |
| 1050 | */ |
| 1051 | typedef enum bt_value_array_append_element_status { |
| 1052 | /*! |
| 1053 | @brief |
| 1054 | Success. |
| 1055 | */ |
| 1056 | BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 1057 | |
| 1058 | /*! |
| 1059 | @brief |
| 1060 | Out of memory. |
| 1061 | */ |
| 1062 | BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 1063 | } bt_value_array_append_element_status; |
| 1064 | |
| 1065 | /*! |
| 1066 | @brief |
| 1067 | Appends the value \bt_p{element_value} to the array value \bt_p{value}. |
| 1068 | |
| 1069 | To append a null value, pass #bt_value_null as \bt_p{element_value}. |
| 1070 | |
| 1071 | @param[in] value |
| 1072 | Array value to which to append \bt_p{element_value}. |
| 1073 | @param[in] element_value |
| 1074 | Value to append to \bt_p{value}. |
| 1075 | |
| 1076 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1077 | Success. |
| 1078 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1079 | Out of memory. |
| 1080 | |
| 1081 | @bt_pre_not_null{value} |
| 1082 | @bt_pre_is_array_val{value} |
| 1083 | @bt_pre_hot{value} |
| 1084 | @bt_pre_not_null{element_value} |
| 1085 | @pre |
| 1086 | \bt_p{element_value} does not contain \bt_p{value}, recursively. |
| 1087 | |
| 1088 | @post |
| 1089 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1090 | incremented. |
| 1091 | |
| 1092 | @sa bt_value_array_append_bool_element() — |
| 1093 | Creates and appends a boolean value to an array value. |
| 1094 | @sa bt_value_array_append_unsigned_integer_element() — |
| 1095 | Creates and appends an unsigned integer value to an array value. |
| 1096 | @sa bt_value_array_append_signed_integer_element() — |
| 1097 | Creates and appends a signed integer value to an array value. |
| 1098 | @sa bt_value_array_append_real_element() — |
| 1099 | Creates and appends a real value to an array value. |
| 1100 | @sa bt_value_array_append_string_element() — |
| 1101 | Creates and appends a string value to an array value. |
| 1102 | @sa bt_value_array_append_empty_array_element() — |
| 1103 | Creates and appends an empty array value to an array value. |
| 1104 | @sa bt_value_array_append_empty_map_element() — |
| 1105 | Creates and appends an empty map value to an array value. |
| 1106 | */ |
| 1107 | extern bt_value_array_append_element_status bt_value_array_append_element( |
| 1108 | bt_value *value, bt_value *element_value); |
| 1109 | |
| 1110 | /*! |
| 1111 | @brief |
| 1112 | Creates a boolean value initialized to \bt_p{raw_value} and appends |
| 1113 | it to the array value \bt_p{value}. |
| 1114 | |
| 1115 | @param[in] value |
| 1116 | Array value to which to append the created boolean value. |
| 1117 | @param[in] raw_value |
| 1118 | Raw value of the boolean value to create and append to \bt_p{value}. |
| 1119 | |
| 1120 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1121 | Success. |
| 1122 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1123 | Out of memory. |
| 1124 | |
| 1125 | @bt_pre_not_null{value} |
| 1126 | @bt_pre_is_array_val{value} |
| 1127 | @bt_pre_hot{value} |
| 1128 | |
| 1129 | @post |
| 1130 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1131 | incremented. |
| 1132 | |
| 1133 | @sa bt_value_array_append_element() — |
| 1134 | Appends an existing value to an array value. |
| 1135 | */ |
| 1136 | extern bt_value_array_append_element_status |
| 1137 | bt_value_array_append_bool_element(bt_value *value, bt_bool raw_value); |
| 1138 | |
| 1139 | /*! |
| 1140 | @brief |
| 1141 | Creates an unsigned integer value initialized to \bt_p{raw_value} |
| 1142 | and appends it to the array value \bt_p{value}. |
| 1143 | |
| 1144 | @param[in] value |
| 1145 | Array value to which to append the created unsigned integer value. |
| 1146 | @param[in] raw_value |
| 1147 | Raw value of the unsigned integer value to create and append to |
| 1148 | \bt_p{value}. |
| 1149 | |
| 1150 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1151 | Success. |
| 1152 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1153 | Out of memory. |
| 1154 | |
| 1155 | @bt_pre_not_null{value} |
| 1156 | @bt_pre_is_array_val{value} |
| 1157 | @bt_pre_hot{value} |
| 1158 | |
| 1159 | @post |
| 1160 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1161 | incremented. |
| 1162 | |
| 1163 | @sa bt_value_array_append_element() — |
| 1164 | Appends an existing value to an array value. |
| 1165 | */ |
| 1166 | extern bt_value_array_append_element_status |
| 1167 | bt_value_array_append_unsigned_integer_element(bt_value *value, |
| 1168 | uint64_t raw_value); |
| 1169 | |
| 1170 | /*! |
| 1171 | @brief |
| 1172 | Creates a signed integer value initialized to \bt_p{raw_value} and |
| 1173 | appends it to the array value \bt_p{value}. |
| 1174 | |
| 1175 | @param[in] value |
| 1176 | Array value to which to append the created signed integer value. |
| 1177 | @param[in] raw_value |
| 1178 | Raw value of the signed integer value to create and append to |
| 1179 | \bt_p{value}. |
| 1180 | |
| 1181 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1182 | Success. |
| 1183 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1184 | Out of memory. |
| 1185 | |
| 1186 | @bt_pre_not_null{value} |
| 1187 | @bt_pre_is_array_val{value} |
| 1188 | @bt_pre_hot{value} |
| 1189 | |
| 1190 | @post |
| 1191 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1192 | incremented. |
| 1193 | |
| 1194 | @sa bt_value_array_append_element() — |
| 1195 | Appends an existing value to an array value. |
| 1196 | */ |
| 1197 | extern bt_value_array_append_element_status |
| 1198 | bt_value_array_append_signed_integer_element(bt_value *value, |
| 1199 | int64_t raw_value); |
| 1200 | |
| 1201 | /*! |
| 1202 | @brief |
| 1203 | Creates a real value initialized to \bt_p{raw_value} and appends |
| 1204 | it to the array value \bt_p{value}. |
| 1205 | |
| 1206 | @param[in] value |
| 1207 | Array value to which to append the created real value. |
| 1208 | @param[in] raw_value |
| 1209 | Raw value of the real value to create and append to \bt_p{value}. |
| 1210 | |
| 1211 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1212 | Success. |
| 1213 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1214 | Out of memory. |
| 1215 | |
| 1216 | @bt_pre_not_null{value} |
| 1217 | @bt_pre_is_array_val{value} |
| 1218 | @bt_pre_hot{value} |
| 1219 | |
| 1220 | @post |
| 1221 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1222 | incremented. |
| 1223 | |
| 1224 | @sa bt_value_array_append_element() — |
| 1225 | Appends an existing value to an array value. |
| 1226 | */ |
| 1227 | extern bt_value_array_append_element_status |
| 1228 | bt_value_array_append_real_element(bt_value *value, double raw_value); |
| 1229 | |
| 1230 | /*! |
| 1231 | @brief |
| 1232 | Creates a string value initialized to a copy of \bt_p{raw_value} and |
| 1233 | appends it to the array value \bt_p{value}. |
| 1234 | |
| 1235 | @param[in] value |
| 1236 | Array value to which to append the created string value. |
| 1237 | @param[in] raw_value |
| 1238 | Raw value of the string value to create and append to \bt_p{value} |
| 1239 | (copied). |
| 1240 | |
| 1241 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1242 | Success. |
| 1243 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1244 | Out of memory. |
| 1245 | |
| 1246 | @bt_pre_not_null{value} |
| 1247 | @bt_pre_is_array_val{value} |
| 1248 | @bt_pre_hot{value} |
| 1249 | |
| 1250 | @post |
| 1251 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1252 | incremented. |
| 1253 | |
| 1254 | @sa bt_value_array_append_element() — |
| 1255 | Appends an existing value to an array value. |
| 1256 | */ |
| 1257 | extern bt_value_array_append_element_status |
| 1258 | bt_value_array_append_string_element(bt_value *value, const char *raw_value); |
| 1259 | |
| 1260 | /*! |
| 1261 | @brief |
| 1262 | Creates an empty array value and appends it to the array |
| 1263 | value \bt_p{value}. |
| 1264 | |
| 1265 | On success, if \bt_p{element_value} is not \c NULL, this function sets |
| 1266 | \bt_p{*element_value} to a \em borrowed reference of the created empty |
| 1267 | array value. |
| 1268 | |
| 1269 | @param[in] value |
| 1270 | Array value to which to append the created empty array value. |
| 1271 | @param[out] element_value |
| 1272 | <strong>On success, if not \c NULL</strong>, \bt_p{*element_value} |
| 1273 | is a \em borrowed reference of the created empty array value. |
| 1274 | |
| 1275 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1276 | Success. |
| 1277 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1278 | Out of memory. |
| 1279 | |
| 1280 | @bt_pre_not_null{value} |
| 1281 | @bt_pre_is_array_val{value} |
| 1282 | @bt_pre_hot{value} |
| 1283 | |
| 1284 | @post |
| 1285 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1286 | incremented. |
| 1287 | |
| 1288 | @sa bt_value_array_append_element() — |
| 1289 | Appends an existing value to an array value. |
| 1290 | */ |
| 1291 | extern bt_value_array_append_element_status |
| 1292 | bt_value_array_append_empty_array_element(bt_value *value, |
| 1293 | bt_value **element_value); |
| 1294 | |
| 1295 | /*! |
| 1296 | @brief |
| 1297 | Creates an empty map value and appends it to the array |
| 1298 | value \bt_p{value}. |
| 1299 | |
| 1300 | On success, if \bt_p{element_value} is not \c NULL, this function sets |
| 1301 | \bt_p{*element_value} to a \em borrowed reference of the created empty |
| 1302 | map value. |
| 1303 | |
| 1304 | @param[in] value |
| 1305 | Array value to which to append the created empty array value. |
| 1306 | @param[out] element_value |
| 1307 | <strong>On success, if not \c NULL</strong>, \bt_p{*element_value} |
| 1308 | is a \em borrowed reference of the created empty map value. |
| 1309 | |
| 1310 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK |
| 1311 | Success. |
| 1312 | @retval #BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR |
| 1313 | Out of memory. |
| 1314 | |
| 1315 | @bt_pre_not_null{value} |
| 1316 | @bt_pre_is_array_val{value} |
| 1317 | @bt_pre_hot{value} |
| 1318 | |
| 1319 | @post |
| 1320 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1321 | incremented. |
| 1322 | |
| 1323 | @sa bt_value_array_append_element() — |
| 1324 | Appends an existing value to an array value. |
| 1325 | */ |
| 1326 | extern bt_value_array_append_element_status |
| 1327 | bt_value_array_append_empty_map_element(bt_value *value, |
| 1328 | bt_value **element_value); |
| 1329 | |
| 1330 | /*! |
| 1331 | @brief |
| 1332 | Status codes for bt_value_array_set_element_by_index(). |
| 1333 | */ |
| 1334 | typedef enum bt_value_array_set_element_by_index_status { |
| 1335 | /*! |
| 1336 | @brief |
| 1337 | Success. |
| 1338 | */ |
| 1339 | BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 1340 | |
| 1341 | /*! |
| 1342 | @brief |
| 1343 | Out of memory. |
| 1344 | */ |
| 1345 | BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 1346 | } bt_value_array_set_element_by_index_status; |
| 1347 | |
| 1348 | /*! |
| 1349 | @brief |
| 1350 | Sets the element of the array value \bt_p{value} at index |
| 1351 | \bt_p{index} to the value \bt_p{element_value}. |
| 1352 | |
| 1353 | On success, this function replaces the existing element of \bt_p{value} |
| 1354 | at index \bt_p{index}. |
| 1355 | |
| 1356 | @param[in] value |
| 1357 | Array value of which to set the element at index \bt_p{index}. |
| 1358 | @param[in] index |
| 1359 | Index of the element to set in \bt_p{value}. |
| 1360 | @param[in] element_value |
| 1361 | Value to set as the element of \bt_p{value} at index \bt_p{index}. |
| 1362 | |
| 1363 | @retval #BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK |
| 1364 | Success. |
| 1365 | @retval #BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_MEMORY_ERROR |
| 1366 | Out of memory. |
| 1367 | |
| 1368 | @bt_pre_not_null{value} |
| 1369 | @bt_pre_is_array_val{value} |
| 1370 | @bt_pre_hot{value} |
| 1371 | @pre |
| 1372 | \bt_p{index} is less than the length of \bt_p{value} (as returned by |
| 1373 | bt_value_array_get_length()). |
| 1374 | @bt_pre_not_null{element_value} |
| 1375 | @pre |
| 1376 | \bt_p{element_value} does not contain \bt_p{value}, recursively. |
| 1377 | |
| 1378 | @post |
| 1379 | <strong>On success</strong>, the length of \bt_p{value} is |
| 1380 | incremented. |
| 1381 | |
| 1382 | @sa bt_value_array_append_element() — |
| 1383 | Appends a value to an array value. |
| 1384 | */ |
| 1385 | extern bt_value_array_set_element_by_index_status |
| 1386 | bt_value_array_set_element_by_index(bt_value *value, uint64_t index, |
| 1387 | bt_value *element_value); |
| 1388 | |
| 1389 | /*! |
| 1390 | @brief |
| 1391 | Borrows the element at index \bt_p{index} from the array value |
| 1392 | \bt_p{value}. |
| 1393 | |
| 1394 | @param[in] value |
| 1395 | Array value from which to borrow the element at index \bt_p{index}. |
| 1396 | @param[in] index |
| 1397 | Index of the element to borrow from \bt_p{value}. |
| 1398 | |
| 1399 | @returns |
| 1400 | @parblock |
| 1401 | \em Borrowed reference of the element of \bt_p{value} at index |
| 1402 | \bt_p{index}. |
| 1403 | |
| 1404 | The returned pointer remains valid until \bt_p{value} is modified. |
| 1405 | @endparblock |
| 1406 | |
| 1407 | @bt_pre_not_null{value} |
| 1408 | @bt_pre_is_array_val{value} |
| 1409 | @pre |
| 1410 | \bt_p{index} is less than the length of \bt_p{value} (as returned by |
| 1411 | bt_value_array_get_length()). |
| 1412 | |
| 1413 | @sa bt_value_array_borrow_element_by_index_const() — |
| 1414 | \c const version of this function. |
| 1415 | */ |
| 1416 | extern bt_value *bt_value_array_borrow_element_by_index(bt_value *value, |
| 1417 | uint64_t index); |
| 1418 | |
| 1419 | /*! |
| 1420 | @brief |
| 1421 | Borrows the element at index \bt_p{index} from the array value |
| 1422 | \bt_p{value} (\c const version). |
| 1423 | |
| 1424 | See bt_value_array_borrow_element_by_index(). |
| 1425 | */ |
| 1426 | extern const bt_value *bt_value_array_borrow_element_by_index_const( |
| 1427 | const bt_value *value, uint64_t index); |
| 1428 | |
| 1429 | /*! |
| 1430 | @brief |
| 1431 | Returns the length of the array value \bt_p{value}. |
| 1432 | |
| 1433 | @param[in] value |
| 1434 | Array value of which to get the length. |
| 1435 | |
| 1436 | @returns |
| 1437 | Length (number of contained elements) of \bt_p{value}. |
| 1438 | |
| 1439 | @bt_pre_not_null{value} |
| 1440 | @bt_pre_is_array_val{value} |
| 1441 | |
| 1442 | @sa bt_value_array_is_empty() — |
| 1443 | Returns whether or not an array value is empty. |
| 1444 | */ |
| 1445 | extern uint64_t bt_value_array_get_length(const bt_value *value); |
| 1446 | |
| 1447 | /*! |
| 1448 | @brief |
| 1449 | Returns whether or not the array value \bt_p{value} is empty. |
| 1450 | |
| 1451 | @param[in] value |
| 1452 | Array value to check. |
| 1453 | |
| 1454 | @returns |
| 1455 | #BT_TRUE if \bt_p{value} is empty (has the length 0). |
| 1456 | |
| 1457 | @bt_pre_not_null{value} |
| 1458 | @bt_pre_is_array_val{value} |
| 1459 | |
| 1460 | @sa bt_value_array_get_length() — |
| 1461 | Returns the length of an array value. |
| 1462 | */ |
| 1463 | static inline |
| 1464 | bt_bool bt_value_array_is_empty(const bt_value *value) |
| 1465 | { |
| 1466 | return bt_value_array_get_length(value) == 0; |
| 1467 | } |
| 1468 | |
| 1469 | /*! @} */ |
| 1470 | |
| 1471 | /*! |
| 1472 | @name Map value |
| 1473 | @{ |
| 1474 | */ |
| 1475 | |
| 1476 | /*! |
| 1477 | @brief |
| 1478 | Creates and returns an empty map value. |
| 1479 | |
| 1480 | The returned value has the type #BT_VALUE_TYPE_MAP. |
| 1481 | |
| 1482 | @returns |
| 1483 | New map value reference, or \c NULL on memory error. |
| 1484 | */ |
| 1485 | extern bt_value *bt_value_map_create(void); |
| 1486 | |
| 1487 | /*! |
| 1488 | @brief |
| 1489 | Status codes for the <code>bt_value_map_insert_*()</code> functions. |
| 1490 | */ |
| 1491 | typedef enum bt_value_map_insert_entry_status { |
| 1492 | /*! |
| 1493 | @brief |
| 1494 | Success. |
| 1495 | */ |
| 1496 | BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 1497 | |
| 1498 | /*! |
| 1499 | @brief |
| 1500 | Out of memory. |
| 1501 | */ |
| 1502 | BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 1503 | } bt_value_map_insert_entry_status; |
| 1504 | |
| 1505 | /*! |
| 1506 | @brief |
| 1507 | Inserts or replaces an entry with the key \bt_p{key} and the value |
| 1508 | \bt_p{entry_value} in the map value \bt_p{value}. |
| 1509 | |
| 1510 | To insert an entry having a null value, pass #bt_value_null as |
| 1511 | \bt_p{entry_value}. |
| 1512 | |
| 1513 | On success, if \bt_p{value} already contains an entry with key |
| 1514 | \bt_p{key}, this function replaces the existing entry's value with |
| 1515 | \bt_p{entry_value}. |
| 1516 | |
| 1517 | @param[in] value |
| 1518 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1519 | and value \bt_p{entry_value}. |
| 1520 | @param[in] key |
| 1521 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1522 | @param[in] entry_value |
| 1523 | Value of the entry to insert or replace in \bt_p{value}. |
| 1524 | |
| 1525 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1526 | Success. |
| 1527 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1528 | Out of memory. |
| 1529 | |
| 1530 | @bt_pre_not_null{value} |
| 1531 | @bt_pre_is_map_val{value} |
| 1532 | @bt_pre_hot{value} |
| 1533 | @bt_pre_not_null{key} |
| 1534 | @bt_pre_not_null{entry_value} |
| 1535 | @pre |
| 1536 | \bt_p{entry_value} does not contain \bt_p{value}, recursively. |
| 1537 | |
| 1538 | @sa bt_value_map_insert_bool_entry() — |
| 1539 | Creates a boolean value and uses it to insert an entry in a map |
| 1540 | value. |
| 1541 | @sa bt_value_map_insert_unsigned_integer_entry() — |
| 1542 | Creates an unsigned integer value and uses it to insert an entry in |
| 1543 | a map value. |
| 1544 | @sa bt_value_map_insert_signed_integer_entry() — |
| 1545 | Creates a signed value and uses it to insert an entry in a map |
| 1546 | value. |
| 1547 | @sa bt_value_map_insert_real_entry() — |
| 1548 | Creates a real value and uses it to insert an entry in a map value. |
| 1549 | @sa bt_value_map_insert_string_entry() — |
| 1550 | Creates a string value and uses it to insert an entry in a map |
| 1551 | value. |
| 1552 | @sa bt_value_map_insert_empty_array_entry() — |
| 1553 | Creates an empty array value and uses it to insert an entry in a map |
| 1554 | value. |
| 1555 | @sa bt_value_map_insert_empty_map_entry() — |
| 1556 | Creates a map value and uses it to insert an entry in a map value. |
| 1557 | */ |
| 1558 | extern bt_value_map_insert_entry_status bt_value_map_insert_entry( |
| 1559 | bt_value *value, const char *key, bt_value *entry_value); |
| 1560 | |
| 1561 | /*! |
| 1562 | @brief |
| 1563 | Creates a boolean value initialized to \bt_p{raw_value} and |
| 1564 | inserts or replaces an entry with the key \bt_p{key} and this value |
| 1565 | in the map value \bt_p{value}. |
| 1566 | |
| 1567 | On success, if \bt_p{value} already contains an entry with key |
| 1568 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1569 | created boolean value. |
| 1570 | |
| 1571 | @param[in] value |
| 1572 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1573 | and the created boolean value. |
| 1574 | @param[in] key |
| 1575 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1576 | @param[in] raw_value |
| 1577 | Initial raw value of the boolean value to create. |
| 1578 | |
| 1579 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1580 | Success. |
| 1581 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1582 | Out of memory. |
| 1583 | |
| 1584 | @bt_pre_not_null{value} |
| 1585 | @bt_pre_is_map_val{value} |
| 1586 | @bt_pre_hot{value} |
| 1587 | @bt_pre_not_null{key} |
| 1588 | |
| 1589 | @sa bt_value_map_insert_entry() — |
| 1590 | Inserts an entry with an existing value in a map value. |
| 1591 | */ |
| 1592 | extern bt_value_map_insert_entry_status bt_value_map_insert_bool_entry( |
| 1593 | bt_value *value, const char *key, bt_bool raw_value); |
| 1594 | |
| 1595 | /*! |
| 1596 | @brief |
| 1597 | Creates an unsigned integer value initialized to \bt_p{raw_value} |
| 1598 | and inserts or replaces an entry with the key \bt_p{key} and this |
| 1599 | value in the map value \bt_p{value}. |
| 1600 | |
| 1601 | On success, if \bt_p{value} already contains an entry with key |
| 1602 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1603 | created unsigned integer value. |
| 1604 | |
| 1605 | @param[in] value |
| 1606 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1607 | and the created unsigned integer value. |
| 1608 | @param[in] key |
| 1609 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1610 | @param[in] raw_value |
| 1611 | Initial raw value of the unsigned integer value to create. |
| 1612 | |
| 1613 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1614 | Success. |
| 1615 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1616 | Out of memory. |
| 1617 | |
| 1618 | @bt_pre_not_null{value} |
| 1619 | @bt_pre_is_map_val{value} |
| 1620 | @bt_pre_hot{value} |
| 1621 | @bt_pre_not_null{key} |
| 1622 | |
| 1623 | @sa bt_value_map_insert_entry() — |
| 1624 | Inserts an entry with an existing value in a map value. |
| 1625 | */ |
| 1626 | extern bt_value_map_insert_entry_status |
| 1627 | bt_value_map_insert_unsigned_integer_entry(bt_value *value, const char *key, |
| 1628 | uint64_t raw_value); |
| 1629 | |
| 1630 | /*! |
| 1631 | @brief |
| 1632 | Creates a signed integer value initialized to \bt_p{raw_value} and |
| 1633 | inserts or replaces an entry with the key \bt_p{key} and this value |
| 1634 | in the map value \bt_p{value}. |
| 1635 | |
| 1636 | On success, if \bt_p{value} already contains an entry with key |
| 1637 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1638 | created signed integer value. |
| 1639 | |
| 1640 | @param[in] value |
| 1641 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1642 | and the created signed integer value. |
| 1643 | @param[in] key |
| 1644 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1645 | @param[in] raw_value |
| 1646 | Initial raw value of the signed integer value to create. |
| 1647 | |
| 1648 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1649 | Success. |
| 1650 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1651 | Out of memory. |
| 1652 | |
| 1653 | @bt_pre_not_null{value} |
| 1654 | @bt_pre_is_map_val{value} |
| 1655 | @bt_pre_hot{value} |
| 1656 | @bt_pre_not_null{key} |
| 1657 | |
| 1658 | @sa bt_value_map_insert_entry() — |
| 1659 | Inserts an entry with an existing value in a map value. |
| 1660 | */ |
| 1661 | extern bt_value_map_insert_entry_status |
| 1662 | bt_value_map_insert_signed_integer_entry(bt_value *value, const char *key, |
| 1663 | int64_t raw_value); |
| 1664 | |
| 1665 | /*! |
| 1666 | @brief |
| 1667 | Creates a real value initialized to \bt_p{raw_value} and inserts or |
| 1668 | replaces an entry with the key \bt_p{key} and this value in the map |
| 1669 | value \bt_p{value}. |
| 1670 | |
| 1671 | On success, if \bt_p{value} already contains an entry with key |
| 1672 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1673 | created real value. |
| 1674 | |
| 1675 | @param[in] value |
| 1676 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1677 | and the created real value. |
| 1678 | @param[in] key |
| 1679 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1680 | @param[in] raw_value |
| 1681 | Initial raw value of the real value to create. |
| 1682 | |
| 1683 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1684 | Success. |
| 1685 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1686 | Out of memory. |
| 1687 | |
| 1688 | @bt_pre_not_null{value} |
| 1689 | @bt_pre_is_map_val{value} |
| 1690 | @bt_pre_hot{value} |
| 1691 | @bt_pre_not_null{key} |
| 1692 | |
| 1693 | @sa bt_value_map_insert_entry() — |
| 1694 | Inserts an entry with an existing value in a map value. |
| 1695 | */ |
| 1696 | extern bt_value_map_insert_entry_status bt_value_map_insert_real_entry( |
| 1697 | bt_value *value, const char *key, double raw_value); |
| 1698 | |
| 1699 | /*! |
| 1700 | @brief |
| 1701 | Creates a string value initialized to a copy of \bt_p{raw_value} and |
| 1702 | inserts or replaces an entry with the key \bt_p{key} and this value |
| 1703 | in the map value \bt_p{value}. |
| 1704 | |
| 1705 | On success, if \bt_p{value} already contains an entry with key |
| 1706 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1707 | created string value. |
| 1708 | |
| 1709 | @param[in] value |
| 1710 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1711 | and the created string value. |
| 1712 | @param[in] key |
| 1713 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1714 | @param[in] raw_value |
| 1715 | Initial raw value of the string value to create (copied). |
| 1716 | |
| 1717 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1718 | Success. |
| 1719 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1720 | Out of memory. |
| 1721 | |
| 1722 | @bt_pre_not_null{value} |
| 1723 | @bt_pre_is_map_val{value} |
| 1724 | @bt_pre_hot{value} |
| 1725 | @bt_pre_not_null{key} |
| 1726 | |
| 1727 | @sa bt_value_map_insert_entry() — |
| 1728 | Inserts an entry with an existing value in a map value. |
| 1729 | */ |
| 1730 | extern bt_value_map_insert_entry_status |
| 1731 | bt_value_map_insert_string_entry(bt_value *value, const char *key, |
| 1732 | const char *raw_value); |
| 1733 | |
| 1734 | /*! |
| 1735 | @brief |
| 1736 | Creates an empty array value and inserts or replaces an entry with |
| 1737 | the key \bt_p{key} and this value in the map value \bt_p{value}. |
| 1738 | |
| 1739 | On success, if \bt_p{entry_value} is not \c NULL, this function sets |
| 1740 | \bt_p{*entry_value} to a \em borrowed reference of the created empty |
| 1741 | array value. |
| 1742 | |
| 1743 | On success, if \bt_p{value} already contains an entry with key |
| 1744 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1745 | created empty array value. |
| 1746 | |
| 1747 | @param[in] value |
| 1748 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1749 | and the created empty array value. |
| 1750 | @param[in] key |
| 1751 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1752 | @param[out] entry_value |
| 1753 | <strong>On success, if not \c NULL</strong>, \bt_p{*entry_value} is |
| 1754 | a \em borrowed reference of the created empty array value. |
| 1755 | |
| 1756 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1757 | Success. |
| 1758 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1759 | Out of memory. |
| 1760 | |
| 1761 | @bt_pre_not_null{value} |
| 1762 | @bt_pre_is_map_val{value} |
| 1763 | @bt_pre_hot{value} |
| 1764 | @bt_pre_not_null{key} |
| 1765 | |
| 1766 | @sa bt_value_map_insert_entry() — |
| 1767 | Inserts an entry with an existing value in a map value. |
| 1768 | */ |
| 1769 | extern bt_value_map_insert_entry_status |
| 1770 | bt_value_map_insert_empty_array_entry(bt_value *value, const char *key, |
| 1771 | bt_value **entry_value); |
| 1772 | |
| 1773 | /*! |
| 1774 | @brief |
| 1775 | Creates an empty map value and inserts or replaces an entry with |
| 1776 | the key \bt_p{key} and this value in the map value \bt_p{value}. |
| 1777 | |
| 1778 | On success, if \bt_p{entry_value} is not \c NULL, this function sets |
| 1779 | \bt_p{*entry_value} to a \em borrowed reference of the created empty map |
| 1780 | value. |
| 1781 | |
| 1782 | On success, if \bt_p{value} already contains an entry with key |
| 1783 | \bt_p{key}, this function replaces the existing entry's value with the |
| 1784 | created empty map value. |
| 1785 | |
| 1786 | @param[in] value |
| 1787 | Map value in which to insert or replace an entry with key \bt_p{key} |
| 1788 | and the created empty map value. |
| 1789 | @param[in] key |
| 1790 | Key of the entry to insert or replace in \bt_p{value} (copied). |
| 1791 | @param[out] entry_value |
| 1792 | <strong>On success, if not \c NULL</strong>, \bt_p{*entry_value} is |
| 1793 | a \em borrowed reference of the created empty map value. |
| 1794 | |
| 1795 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK |
| 1796 | Success. |
| 1797 | @retval #BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR |
| 1798 | Out of memory. |
| 1799 | |
| 1800 | @bt_pre_not_null{value} |
| 1801 | @bt_pre_is_map_val{value} |
| 1802 | @bt_pre_hot{value} |
| 1803 | @bt_pre_not_null{key} |
| 1804 | |
| 1805 | @sa bt_value_map_insert_entry() — |
| 1806 | Inserts an entry with an existing value in a map value. |
| 1807 | */ |
| 1808 | extern bt_value_map_insert_entry_status |
| 1809 | bt_value_map_insert_empty_map_entry(bt_value *value, const char *key, |
| 1810 | bt_value **entry_value); |
| 1811 | |
| 1812 | /*! |
| 1813 | @brief |
| 1814 | Borrows the value of the entry with the key \bt_p{key} in the map |
| 1815 | value \bt_p{value}. |
| 1816 | |
| 1817 | If no entry with key \bt_p{key} exists in \bt_p{value}, this function |
| 1818 | returns \c NULL. |
| 1819 | |
| 1820 | @param[in] value |
| 1821 | Map value from which to borrow the value of the entry with the |
| 1822 | key \bt_p{key}. |
| 1823 | @param[in] key |
| 1824 | Key of the entry from which to borrow the value in \bt_p{value}. |
| 1825 | |
| 1826 | @returns |
| 1827 | @parblock |
| 1828 | \em Borrowed reference of the value of the entry with key \bt_p{key} |
| 1829 | in \bt_p{value}, or \c NULL if none. |
| 1830 | |
| 1831 | The returned pointer remains valid until \bt_p{value} is modified. |
| 1832 | @endparblock |
| 1833 | |
| 1834 | @bt_pre_not_null{value} |
| 1835 | @bt_pre_is_array_val{value} |
| 1836 | @bt_pre_not_null{key} |
| 1837 | |
| 1838 | @sa bt_value_map_borrow_entry_value_const() — |
| 1839 | \c const version of this function. |
| 1840 | @sa bt_value_map_has_entry() — |
| 1841 | Returns whether or not a map value has an entry with a given key. |
| 1842 | */ |
| 1843 | extern bt_value *bt_value_map_borrow_entry_value( |
| 1844 | bt_value *value, const char *key); |
| 1845 | |
| 1846 | /*! |
| 1847 | @brief |
| 1848 | Borrows the value of the entry with the key \bt_p{key} in the map |
| 1849 | value \bt_p{value} (\c const version). |
| 1850 | |
| 1851 | See bt_value_map_borrow_entry_value(). |
| 1852 | */ |
| 1853 | extern const bt_value *bt_value_map_borrow_entry_value_const( |
| 1854 | const bt_value *value, const char *key); |
| 1855 | |
| 1856 | /*! |
| 1857 | @brief |
| 1858 | Status codes for #bt_value_map_foreach_entry_func. |
| 1859 | */ |
| 1860 | typedef enum bt_value_map_foreach_entry_func_status { |
| 1861 | /*! |
| 1862 | @brief |
| 1863 | Success. |
| 1864 | */ |
| 1865 | BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 1866 | |
| 1867 | /*! |
| 1868 | @brief |
| 1869 | Interrupt the iteration process. |
| 1870 | */ |
| 1871 | BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT = __BT_FUNC_STATUS_INTERRUPTED, |
| 1872 | |
| 1873 | /*! |
| 1874 | @brief |
| 1875 | Out of memory. |
| 1876 | */ |
| 1877 | BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 1878 | |
| 1879 | /*! |
| 1880 | @brief |
| 1881 | User error. |
| 1882 | */ |
| 1883 | BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR = __BT_FUNC_STATUS_ERROR, |
| 1884 | } bt_value_map_foreach_entry_func_status; |
| 1885 | |
| 1886 | /*! |
| 1887 | @brief |
| 1888 | User function for bt_value_map_foreach_entry(). |
| 1889 | |
| 1890 | This is the type of the user function that bt_value_map_foreach_entry() |
| 1891 | calls for each entry of the map value. |
| 1892 | |
| 1893 | @param[in] key |
| 1894 | Key of the map value entry. |
| 1895 | @param[in] value |
| 1896 | Value of the map value entry. |
| 1897 | @param[in] user_data |
| 1898 | User data, as passed as the \bt_p{user_data} parameter of |
| 1899 | bt_value_map_foreach_entry(). |
| 1900 | |
| 1901 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK |
| 1902 | Success. |
| 1903 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT |
| 1904 | Interrupt the iteration process. |
| 1905 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR |
| 1906 | Out of memory. |
| 1907 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR |
| 1908 | User error. |
| 1909 | |
| 1910 | @bt_pre_not_null{key} |
| 1911 | @bt_pre_not_null{value} |
| 1912 | |
| 1913 | @sa bt_value_map_foreach_entry() — |
| 1914 | Iterates the entries of a map value. |
| 1915 | */ |
| 1916 | typedef bt_value_map_foreach_entry_func_status |
| 1917 | (* bt_value_map_foreach_entry_func)(const char *key, |
| 1918 | bt_value *value, void *user_data); |
| 1919 | |
| 1920 | /*! |
| 1921 | @brief |
| 1922 | Status codes for bt_value_map_foreach_entry(). |
| 1923 | */ |
| 1924 | typedef enum bt_value_map_foreach_entry_status { |
| 1925 | /*! |
| 1926 | @brief |
| 1927 | Success. |
| 1928 | */ |
| 1929 | BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 1930 | |
| 1931 | /*! |
| 1932 | @brief |
| 1933 | User function interrupted the iteration process. |
| 1934 | */ |
| 1935 | BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED, |
| 1936 | |
| 1937 | /*! |
| 1938 | @brief |
| 1939 | User function error. |
| 1940 | */ |
| 1941 | BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR = __BT_FUNC_STATUS_USER_ERROR, |
| 1942 | |
| 1943 | /*! |
| 1944 | @brief |
| 1945 | Out of memory. |
| 1946 | */ |
| 1947 | BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 1948 | |
| 1949 | /*! |
| 1950 | @brief |
| 1951 | Other error. |
| 1952 | */ |
| 1953 | BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR = __BT_FUNC_STATUS_ERROR, |
| 1954 | } bt_value_map_foreach_entry_status; |
| 1955 | |
| 1956 | /*! |
| 1957 | @brief |
| 1958 | Iterates the entries of the map value \bt_p{value}, calling |
| 1959 | \bt_p{user_func} for each entry. |
| 1960 | |
| 1961 | This function iterates the entries of \bt_p{value} in no particular |
| 1962 | order. |
| 1963 | |
| 1964 | @attention |
| 1965 | You must \em not modify \bt_p{value} during the iteration process. |
| 1966 | |
| 1967 | \bt_p{user_func} receives \bt_p{user_data} as its last parameter. |
| 1968 | |
| 1969 | The iteration process stops when one of: |
| 1970 | |
| 1971 | - \bt_p{user_func} was called for each entry. |
| 1972 | - \bt_p{user_func} does not return |
| 1973 | #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK. |
| 1974 | |
| 1975 | @param[in] value |
| 1976 | Map value of which to iterate the entries. |
| 1977 | @param[in] user_func |
| 1978 | User function to call for each entry of \bt_p{value}. |
| 1979 | @param[in] user_data |
| 1980 | User data to pass as the \bt_p{user_data} parameter of each call to |
| 1981 | \bt_p{user_func}. |
| 1982 | |
| 1983 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK |
| 1984 | Success. |
| 1985 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED |
| 1986 | \bt_p{user_func} returned |
| 1987 | #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT to interrupt the |
| 1988 | iteration process. |
| 1989 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR |
| 1990 | \bt_p{user_func} returned |
| 1991 | #BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR. |
| 1992 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR |
| 1993 | Out of memory. |
| 1994 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR |
| 1995 | Other error caused the <code>bt_value_map_foreach_entry()</code> |
| 1996 | function itself. |
| 1997 | |
| 1998 | @bt_pre_not_null{value} |
| 1999 | @bt_pre_is_map_val{value} |
| 2000 | @bt_pre_not_null{user_func} |
| 2001 | |
| 2002 | @sa bt_value_map_foreach_entry_const() — |
| 2003 | \c const version of this function. |
| 2004 | @sa bt_value_map_borrow_entry_value() — |
| 2005 | Borrows the value of a specific map value entry. |
| 2006 | */ |
| 2007 | extern bt_value_map_foreach_entry_status bt_value_map_foreach_entry( |
| 2008 | bt_value *value, bt_value_map_foreach_entry_func user_func, |
| 2009 | void *user_data); |
| 2010 | |
| 2011 | /*! |
| 2012 | @brief |
| 2013 | Status codes for #bt_value_map_foreach_entry_const_func. |
| 2014 | */ |
| 2015 | typedef enum bt_value_map_foreach_entry_const_func_status { |
| 2016 | /*! |
| 2017 | @brief |
| 2018 | Success. |
| 2019 | */ |
| 2020 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 2021 | |
| 2022 | /*! |
| 2023 | @brief |
| 2024 | Interrupt the iteration process. |
| 2025 | */ |
| 2026 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT = __BT_FUNC_STATUS_INTERRUPTED, |
| 2027 | |
| 2028 | /*! |
| 2029 | @brief |
| 2030 | Out of memory. |
| 2031 | */ |
| 2032 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 2033 | |
| 2034 | /*! |
| 2035 | @brief |
| 2036 | User error. |
| 2037 | */ |
| 2038 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR = __BT_FUNC_STATUS_ERROR, |
| 2039 | } bt_value_map_foreach_entry_const_func_status; |
| 2040 | |
| 2041 | /*! |
| 2042 | @brief |
| 2043 | User function for bt_value_map_foreach_entry_const_func(). |
| 2044 | |
| 2045 | This is the type of the user function that |
| 2046 | bt_value_map_foreach_entry_const_func() calls for each entry of the map |
| 2047 | value. |
| 2048 | |
| 2049 | @param[in] key |
| 2050 | Key of the map value entry. |
| 2051 | @param[in] value |
| 2052 | Value of the map value entry. |
| 2053 | @param[in] user_data |
| 2054 | User data. |
| 2055 | |
| 2056 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK |
| 2057 | Success. |
| 2058 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT |
| 2059 | Interrupt the iteration process. |
| 2060 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR |
| 2061 | Out of memory. |
| 2062 | @retval #BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR |
| 2063 | User error. |
| 2064 | |
| 2065 | @bt_pre_not_null{key} |
| 2066 | @bt_pre_not_null{value} |
| 2067 | |
| 2068 | @sa bt_value_map_foreach_entry_const() — |
| 2069 | Iterates the entries of a \c const map value. |
| 2070 | */ |
| 2071 | typedef bt_value_map_foreach_entry_const_func_status |
| 2072 | (* bt_value_map_foreach_entry_const_func)(const char *key, |
| 2073 | const bt_value *value, void *user_data); |
| 2074 | |
| 2075 | /*! |
| 2076 | @brief |
| 2077 | Status codes for bt_value_map_foreach_entry_const(). |
| 2078 | */ |
| 2079 | typedef enum bt_value_map_foreach_entry_const_status { |
| 2080 | /*! |
| 2081 | @brief |
| 2082 | Success. |
| 2083 | */ |
| 2084 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 2085 | |
| 2086 | /*! |
| 2087 | @brief |
| 2088 | User function interrupted the iteration process. |
| 2089 | */ |
| 2090 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED, |
| 2091 | |
| 2092 | /*! |
| 2093 | @brief |
| 2094 | User function error. |
| 2095 | */ |
| 2096 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_USER_ERROR = __BT_FUNC_STATUS_USER_ERROR, |
| 2097 | |
| 2098 | /*! |
| 2099 | @brief |
| 2100 | Out of memory. |
| 2101 | */ |
| 2102 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 2103 | |
| 2104 | /*! |
| 2105 | @brief |
| 2106 | Other error. |
| 2107 | */ |
| 2108 | BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR = __BT_FUNC_STATUS_ERROR, |
| 2109 | } bt_value_map_foreach_entry_const_status; |
| 2110 | |
| 2111 | /*! |
| 2112 | @brief |
| 2113 | Iterates the entries of the map value \bt_p{value}, calling |
| 2114 | \bt_p{user_func} for each entry (\c const version). |
| 2115 | |
| 2116 | See bt_value_map_foreach_entry(). |
| 2117 | |
| 2118 | @sa bt_value_map_borrow_entry_value_const() — |
| 2119 | Borrows the value of a specific map value entry. |
| 2120 | */ |
| 2121 | extern bt_value_map_foreach_entry_const_status bt_value_map_foreach_entry_const( |
| 2122 | const bt_value *value, |
| 2123 | bt_value_map_foreach_entry_const_func user_func, |
| 2124 | void *user_data); |
| 2125 | |
| 2126 | /*! |
| 2127 | @brief |
| 2128 | Returns the size of the map value \bt_p{value}. |
| 2129 | |
| 2130 | @param[in] value |
| 2131 | Map value of which to get the size. |
| 2132 | |
| 2133 | @returns |
| 2134 | Size (number of contained entries) of \bt_p{value}. |
| 2135 | |
| 2136 | @bt_pre_not_null{value} |
| 2137 | @bt_pre_is_map_val{value} |
| 2138 | |
| 2139 | @sa bt_value_map_is_empty() — |
| 2140 | Returns whether or not a map value is empty. |
| 2141 | */ |
| 2142 | extern uint64_t bt_value_map_get_size(const bt_value *value); |
| 2143 | |
| 2144 | /*! |
| 2145 | @brief |
| 2146 | Returns whether or not the map value \bt_p{value} is empty. |
| 2147 | |
| 2148 | @param[in] value |
| 2149 | Map value to check. |
| 2150 | |
| 2151 | @returns |
| 2152 | #BT_TRUE if \bt_p{value} is empty (has the size 0). |
| 2153 | |
| 2154 | @bt_pre_not_null{value} |
| 2155 | @bt_pre_is_map_val{value} |
| 2156 | |
| 2157 | @sa bt_value_map_get_size() — |
| 2158 | Returns the size of a map value. |
| 2159 | */ |
| 2160 | static inline |
| 2161 | bt_bool bt_value_map_is_empty(const bt_value *value) |
| 2162 | { |
| 2163 | return bt_value_map_get_size(value) == 0; |
| 2164 | } |
| 2165 | |
| 2166 | /*! |
| 2167 | @brief |
| 2168 | Returns whether or not the map value \bt_p{value} has an entry with |
| 2169 | the key \bt_p{key}. |
| 2170 | |
| 2171 | @param[in] value |
| 2172 | Map value to check. |
| 2173 | @param[in] key |
| 2174 | Key to check. |
| 2175 | |
| 2176 | @returns |
| 2177 | #BT_TRUE if \bt_p{value} has an entry with the key \bt_p{key}. |
| 2178 | |
| 2179 | @bt_pre_not_null{value} |
| 2180 | @bt_pre_is_map_val{value} |
| 2181 | @bt_pre_not_null{key} |
| 2182 | |
| 2183 | @sa bt_value_map_borrow_entry_value_const() — |
| 2184 | Borrows the value of a specific map value entry. |
| 2185 | */ |
| 2186 | extern bt_bool bt_value_map_has_entry(const bt_value *value, |
| 2187 | const char *key); |
| 2188 | |
| 2189 | /*! |
| 2190 | @brief |
| 2191 | Status codes for bt_value_map_extend(). |
| 2192 | */ |
| 2193 | typedef enum bt_value_map_extend_status { |
| 2194 | /*! |
| 2195 | @brief |
| 2196 | Success. |
| 2197 | */ |
| 2198 | BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 2199 | |
| 2200 | /*! |
| 2201 | @brief |
| 2202 | Out of memory. |
| 2203 | */ |
| 2204 | BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 2205 | } bt_value_map_extend_status; |
| 2206 | |
| 2207 | /*! |
| 2208 | @brief |
| 2209 | Extends the map value \bt_p{value} with the map value |
| 2210 | \bt_p{extension_value}. |
| 2211 | |
| 2212 | For each entry in \bt_p{extension_value}, this function calls |
| 2213 | bt_value_map_insert_entry() to insert or replace it in the map value |
| 2214 | \bt_p{value}. |
| 2215 | |
| 2216 | For example, with: |
| 2217 | |
| 2218 | <dl> |
| 2219 | <dt> |
| 2220 | \bt_p{value} |
| 2221 | </dt> |
| 2222 | <dd> |
| 2223 | @code{.json} |
| 2224 | { |
| 2225 | "man": "giant", |
| 2226 | "strange": 23 |
| 2227 | } |
| 2228 | @endcode |
| 2229 | </dd> |
| 2230 | |
| 2231 | <dt> |
| 2232 | \bt_p{extension_value} |
| 2233 | </dt> |
| 2234 | <dd> |
| 2235 | @code{.json} |
| 2236 | { |
| 2237 | "balance": -17 |
| 2238 | "strange": false |
| 2239 | } |
| 2240 | @endcode |
| 2241 | </dd> |
| 2242 | </dl> |
| 2243 | |
| 2244 | The map value \bt_p{value} becomes: |
| 2245 | |
| 2246 | @code{.json} |
| 2247 | { |
| 2248 | "man": "giant", |
| 2249 | "strange": false, |
| 2250 | "balance": -17 |
| 2251 | } |
| 2252 | @endcode |
| 2253 | |
| 2254 | @param[in] value |
| 2255 | Map value to extend. |
| 2256 | @param[in] extension_value |
| 2257 | Extension map value. |
| 2258 | |
| 2259 | @retval #BT_VALUE_MAP_EXTEND_STATUS_OK |
| 2260 | Success. |
| 2261 | @retval #BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR |
| 2262 | Out of memory. |
| 2263 | |
| 2264 | @bt_pre_not_null{value} |
| 2265 | @bt_pre_is_map_val{value} |
| 2266 | @bt_pre_not_null{extension_value} |
| 2267 | @bt_pre_is_map_val{extension_value} |
| 2268 | |
| 2269 | @sa bt_value_copy() — |
| 2270 | Deep-copies a value. |
| 2271 | */ |
| 2272 | extern bt_value_map_extend_status bt_value_map_extend( |
| 2273 | bt_value *value, const bt_value *extension_value); |
| 2274 | |
| 2275 | /*! @} */ |
| 2276 | |
| 2277 | /*! |
| 2278 | @name General |
| 2279 | @{ |
| 2280 | */ |
| 2281 | |
| 2282 | /*! |
| 2283 | @brief |
| 2284 | Status codes for bt_value_copy(). |
| 2285 | */ |
| 2286 | typedef enum bt_value_copy_status { |
| 2287 | /*! |
| 2288 | @brief |
| 2289 | Success. |
| 2290 | */ |
| 2291 | BT_VALUE_COPY_STATUS_OK = __BT_FUNC_STATUS_OK, |
| 2292 | |
| 2293 | /*! |
| 2294 | @brief |
| 2295 | Out of memory. |
| 2296 | */ |
| 2297 | BT_VALUE_COPY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, |
| 2298 | } bt_value_copy_status; |
| 2299 | |
| 2300 | /*! |
| 2301 | @brief |
| 2302 | Deep-copies a value object. |
| 2303 | |
| 2304 | This function deep-copies \bt_p{value} and sets \bt_p{*copy} to the |
| 2305 | result. |
| 2306 | |
| 2307 | Because \bt_p{*copy} is a deep copy, it does not contain, recursively, |
| 2308 | any reference that \bt_p{value} contains, but the raw values are |
| 2309 | identical. |
| 2310 | |
| 2311 | @param[in] value |
| 2312 | Value to deep-copy. |
| 2313 | @param[in] copy_value |
| 2314 | <strong>On success</strong>, \bt_p{*copy_value} is a deep copy of |
| 2315 | \bt_p{value}. |
| 2316 | |
| 2317 | @retval #BT_VALUE_COPY_STATUS_OK |
| 2318 | Success. |
| 2319 | @retval #BT_VALUE_COPY_STATUS_MEMORY_ERROR |
| 2320 | Out of memory. |
| 2321 | |
| 2322 | @bt_pre_not_null{value} |
| 2323 | @bt_pre_not_null{copy_value} |
| 2324 | */ |
| 2325 | extern bt_value_copy_status bt_value_copy(const bt_value *value, |
| 2326 | bt_value **copy_value); |
| 2327 | |
| 2328 | /*! |
| 2329 | @brief |
| 2330 | Returns whether or not the value \bt_p{a_value} is equal, |
| 2331 | recursively, to \bt_p{b_value}. |
| 2332 | |
| 2333 | @note |
| 2334 | If you want to know whether or not a value is a null value, you can |
| 2335 | also directly compare its pointer to the #bt_value_null variable. |
| 2336 | |
| 2337 | @param[in] a_value |
| 2338 | Value A. |
| 2339 | @param[in] b_value |
| 2340 | Value B. |
| 2341 | |
| 2342 | @returns |
| 2343 | #BT_TRUE if \bt_p{a_value} is equal, recursively, to \bt_p{b_value}. |
| 2344 | |
| 2345 | @bt_pre_not_null{a_value} |
| 2346 | @bt_pre_not_null{b_value} |
| 2347 | */ |
| 2348 | extern bt_bool bt_value_is_equal(const bt_value *a_value, |
| 2349 | const bt_value *b_value); |
| 2350 | |
| 2351 | /*! @} */ |
| 2352 | |
| 2353 | /*! |
| 2354 | @name Reference count |
| 2355 | @{ |
| 2356 | */ |
| 2357 | |
| 2358 | /*! |
| 2359 | @brief |
| 2360 | Increments the \ref api-fund-shared-object "reference count" of |
| 2361 | the value \bt_p{value}. |
| 2362 | |
| 2363 | @param[in] value |
| 2364 | @parblock |
| 2365 | Value of which to increment the reference count. |
| 2366 | |
| 2367 | Can be \c NULL. |
| 2368 | @endparblock |
| 2369 | |
| 2370 | @sa bt_value_put_ref() — |
| 2371 | Decrements the reference count of a value. |
| 2372 | */ |
| 2373 | extern void bt_value_get_ref(const bt_value *value); |
| 2374 | |
| 2375 | /*! |
| 2376 | @brief |
| 2377 | Decrements the \ref api-fund-shared-object "reference count" of |
| 2378 | the value \bt_p{value}. |
| 2379 | |
| 2380 | @param[in] value |
| 2381 | @parblock |
| 2382 | Value of which to decrement the reference count. |
| 2383 | |
| 2384 | Can be \c NULL. |
| 2385 | @endparblock |
| 2386 | |
| 2387 | @sa bt_value_get_ref() — |
| 2388 | Increments the reference count of a value. |
| 2389 | */ |
| 2390 | extern void bt_value_put_ref(const bt_value *value); |
| 2391 | |
| 2392 | /*! |
| 2393 | @brief |
| 2394 | Decrements the reference count of the value \bt_p{_value}, and then |
| 2395 | sets \bt_p{_value} to \c NULL. |
| 2396 | |
| 2397 | @param _value |
| 2398 | @parblock |
| 2399 | Value of which to decrement the reference count. |
| 2400 | |
| 2401 | Can contain \c NULL. |
| 2402 | @endparblock |
| 2403 | |
| 2404 | @bt_pre_assign_expr{_value} |
| 2405 | */ |
| 2406 | #define BT_VALUE_PUT_REF_AND_RESET(_value) \ |
| 2407 | do { \ |
| 2408 | bt_value_put_ref(_value); \ |
| 2409 | (_value) = NULL; \ |
| 2410 | } while (0) |
| 2411 | |
| 2412 | /*! |
| 2413 | @brief |
| 2414 | Decrements the reference count of the value \bt_p{_dst}, sets |
| 2415 | \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL. |
| 2416 | |
| 2417 | This macro effectively moves a value reference from the expression |
| 2418 | \bt_p{_src} to the expression \bt_p{_dst}, putting the existing |
| 2419 | \bt_p{_dst} reference. |
| 2420 | |
| 2421 | @param _dst |
| 2422 | @parblock |
| 2423 | Destination expression. |
| 2424 | |
| 2425 | Can contain \c NULL. |
| 2426 | @endparblock |
| 2427 | @param _src |
| 2428 | @parblock |
| 2429 | Source expression. |
| 2430 | |
| 2431 | Can contain \c NULL. |
| 2432 | @endparblock |
| 2433 | |
| 2434 | @bt_pre_assign_expr{_dst} |
| 2435 | @bt_pre_assign_expr{_src} |
| 2436 | */ |
| 2437 | #define BT_VALUE_MOVE_REF(_dst, _src) \ |
| 2438 | do { \ |
| 2439 | bt_value_put_ref(_dst); \ |
| 2440 | (_dst) = (_src); \ |
| 2441 | (_src) = NULL; \ |
| 2442 | } while (0) |
| 2443 | |
| 2444 | /*! @} */ |
| 2445 | |
| 2446 | /*! @} */ |
| 2447 | |
| 2448 | #ifdef __cplusplus |
| 2449 | } |
| 2450 | #endif |
| 2451 | |
| 2452 | #endif /* BABELTRACE2_VALUE_H */ |