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