Document libbabeltrace2's C API
[babeltrace.git] / include / babeltrace2 / value.h
CommitLineData
924dc299
PP
1#ifndef BABELTRACE2_VALUE_H
2#define BABELTRACE2_VALUE_H
dac5c838
PP
3
4/*
bbb7b5f0 5 * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation
dac5c838
PP
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
4fa90f32
PP
26#ifndef __BT_IN_BABELTRACE_H
27# error "Please include <babeltrace2/babeltrace.h> instead."
28#endif
29
dac5c838 30#include <stdint.h>
dac5c838 31#include <stddef.h>
9d408fca 32
3fadfbc0 33#include <babeltrace2/types.h>
40f4ba76 34
dac5c838
PP
35#ifdef __cplusplus
36extern "C" {
37#endif
38
43c59509
PP
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
46the fact that integer values are explicitly unsigned or signed because
47of typing limitations,
48\bt_name values are very similar to <a href="https://json.org/">JSON</a>
49values.
50
51The 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,
56bt_event_class_set_user_attributes()) use values.
57
58The 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
78Values are \ref api-fund-shared-object "shared objects": get a new
79reference with bt_value_get_ref() and put an existing reference with
80bt_value_put_ref().
81
82Some library functions \ref api-fund-freezing "freeze" values on
83success. The documentation of those functions indicate this
84postcondition.
85
86All the value types share the same C type, #bt_value.
87
88Get the type enumerator of a value with bt_value_get_type(). Get whether
89or not a value type conceptually \em is a given type with the inline
90bt_value_type_is() function. Get whether or not a value has a specific
91type with one of the <code>bt_value_is_*()</code> inline helpers.
92
93The \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
96values, the null value is a shared object: if you get a new null value
97reference, you must eventually put it.
98
99Create a value with one of the <code>bt_value_*_create()</code> or
100<code>bt_value_*_create_init()</code> functions.
101
102This documentation names the actual data that a scalar value wraps the
103<em>raw value</em>.
104
105Set and get the raw values of scalar values with functions that are
106named <code>bt_value_*_set()</code> and <code>bt_value_*_get()</code>.
107
108Check that two values are recursively equal with bt_value_is_equal().
109
110Deep-copy a value with bt_value_copy().
111
112Extend a map value with bt_value_map_extend().
113
114The following table shows the available functions and types for each
115type 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*/
248typedef 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*/
342extern 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
349For example, an unsigned integer value conceptually \em is an integer
350value, so
351
352@code
353bt_value_type_is(BT_VALUE_TYPE_UNSIGNED_INTEGER, BT_VALUE_TYPE_INTEGER)
354@endcode
355
356returns #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*/
385static inline
386bt_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*/
417static inline
418bt_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*/
441static inline
442bt_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*/
466static inline
467bt_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*/
491static inline
492bt_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*/
515static inline
516bt_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*/
539static inline
540bt_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*/
563static inline
564bt_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*/
587static inline
588bt_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
604This is the \em only instance of a null value.
605
606Like any type of value, the null value is a shared object: if you get a
607new null value reference with bt_value_get_ref(), you must eventually
608put it with bt_value_put_ref(). The null value singleton's reference
609count must never reach 0: libbabeltrace2 logs a warning message when
610this programming error occurs.
611
612Because all null values point to the same null value singleton, you can
613directly 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*/
211796dc 629extern bt_value *const bt_value_null;
dac5c838 630
43c59509
PP
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
642The 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*/
b19ff26f 650extern bt_value *bt_value_bool_create(void);
dac5c838 651
43c59509
PP
652/*!
653@brief
654 Creates and returns a boolean value initialized to \bt_p{raw_value}.
655
656The 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*/
667extern 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}.
dac5c838 678
43c59509
PP
679@bt_pre_not_null{value}
680@bt_pre_is_bool_val{value}
681@bt_pre_hot{value}
dac5c838 682
43c59509
PP
683@sa bt_value_bool_get() &mdash;
684 Returns the raw value of a boolean value.
685*/
686extern 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*/
704extern 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
717The 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*/
9c08c816 725extern bt_value *bt_value_integer_unsigned_create(void);
dac5c838 726
43c59509
PP
727/*!
728@brief
729 Creates and returns an unsigned integer value initialized to
730 \bt_p{raw_value}.
731
732The 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*/
743extern bt_value *bt_value_integer_unsigned_create_init(uint64_t raw_value);
dac5c838 744
43c59509
PP
745/*!
746@brief
747 Sets the raw value of the unsigned integer value \bt_p{value} to
748 \bt_p{raw_value}.
fdd3a2da 749
43c59509
PP
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*/
763extern 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*/
782extern 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
795The 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*/
9c08c816 803extern bt_value *bt_value_integer_signed_create(void);
fdd3a2da 804
43c59509
PP
805/*!
806@brief
807 Creates and returns a signed integer value initialized to
808 \bt_p{raw_value}.
809
810The 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.
fdd3a2da 814
43c59509
PP
815@returns
816 New signed integer value reference, or \c NULL on memory error.
de079588 817
43c59509
PP
818@sa bt_value_bool_create() &mdash;
819 Creates a signed integer value initialized to 0.
820*/
821extern 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*/
841extern 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*/
859extern 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
872The 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*/
b19ff26f 880extern bt_value *bt_value_real_create(void);
de079588 881
43c59509
PP
882/*!
883@brief
884 Creates and returns a real value initialized to \bt_p{raw_value}.
885
886The 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*/
897extern 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*/
916extern 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*/
934extern double bt_value_real_get(const bt_value *value);
935
936/*! @} */
937
938/*!
939@name String value
940@{
941*/
dac5c838 942
43c59509
PP
943/*!
944@brief
945 Creates and returns an empty string value.
dac5c838 946
43c59509
PP
947The 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*/
b19ff26f 955extern bt_value *bt_value_string_create(void);
dac5c838 956
43c59509
PP
957/*!
958@brief
959 Creates and returns a string value initialized to a copy of
960 \bt_p{raw_value}.
961
962The 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).
dac5c838 966
43c59509
PP
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*/
975extern bt_value *bt_value_string_create_init(const char *raw_value);
976
977/*!
978@brief
979 Status codes for bt_value_string_set().
980*/
d24d5663 981typedef enum bt_value_string_set_status {
43c59509
PP
982 /*!
983 @brief
984 Success.
985 */
d24d5663 986 BT_VALUE_STRING_SET_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
987
988 /*!
989 @brief
990 Out of memory.
991 */
992 BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
d24d5663
PP
993} bt_value_string_set_status;
994
43c59509
PP
995/*!
996@brief
997 Sets the raw value of the string value \bt_p{value} to a copy of
998 \bt_p{raw_value}.
de079588 999
43c59509
PP
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).
dac5c838 1005
43c59509
PP
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*/
1019extern 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}.
dac5c838 1025
43c59509
PP
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*/
1042extern 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
1055The returned value has the type #BT_VALUE_TYPE_ARRAY.
1056
1057@returns
1058 New array value reference, or \c NULL on memory error.
1059*/
1060extern 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*/
d24d5663 1067typedef enum bt_value_array_append_element_status {
43c59509
PP
1068 /*!
1069 @brief
1070 Success.
1071 */
d24d5663 1072 BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
1073
1074 /*!
1075 @brief
1076 Out of memory.
1077 */
1078 BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
d24d5663 1079} bt_value_array_append_element_status;
dac5c838 1080
43c59509
PP
1081/*!
1082@brief
1083 Appends the value \bt_p{element_value} to the array value \bt_p{value}.
1084
1085To 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*/
d24d5663 1123extern bt_value_array_append_element_status bt_value_array_append_element(
43c59509
PP
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.
05e21286 1140
43c59509
PP
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*/
d24d5663 1152extern bt_value_array_append_element_status
43c59509
PP
1153bt_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.
fdd3a2da 1178
43c59509
PP
1179@sa bt_value_array_append_element() &mdash;
1180 Appends an existing value to an array value.
1181*/
d24d5663 1182extern bt_value_array_append_element_status
43c59509
PP
1183bt_value_array_append_unsigned_integer_element(bt_value *value,
1184 uint64_t raw_value);
05e21286 1185
43c59509
PP
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*/
d24d5663 1213extern bt_value_array_append_element_status
43c59509
PP
1214bt_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}.
05e21286 1226
43c59509
PP
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*/
d24d5663 1243extern bt_value_array_append_element_status
43c59509
PP
1244bt_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}
05e21286 1265
43c59509
PP
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*/
d24d5663 1273extern bt_value_array_append_element_status
43c59509
PP
1274bt_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
1281On 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
1283array 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.
05e21286 1290
43c59509
PP
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*/
d24d5663 1307extern bt_value_array_append_element_status
43c59509
PP
1308bt_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}.
05e21286 1315
43c59509
PP
1316On 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
1318map 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*/
d24d5663 1342extern bt_value_array_append_element_status
43c59509
PP
1343bt_value_array_append_empty_map_element(bt_value *value,
1344 bt_value **element_value);
d24d5663 1345
43c59509
PP
1346/*!
1347@brief
1348 Status codes for bt_value_array_set_element_by_index().
1349*/
d24d5663 1350typedef enum bt_value_array_set_element_by_index_status {
43c59509
PP
1351 /*!
1352 @brief
1353 Success.
1354 */
d24d5663 1355 BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
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,
d24d5663
PP
1362} bt_value_array_set_element_by_index_status;
1363
43c59509
PP
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
1369On success, this function replaces the existing element of \bt_p{value}
1370at 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*/
d24d5663 1401extern bt_value_array_set_element_by_index_status
43c59509
PP
1402bt_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*/
1432extern 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).
05e21286 1439
43c59509
PP
1440See bt_value_array_borrow_element_by_index().
1441*/
1442extern 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*/
1461extern 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*/
1479static inline
1480bt_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
1496The returned value has the type #BT_VALUE_TYPE_MAP.
1497
1498@returns
1499 New map value reference, or \c NULL on memory error.
1500*/
b19ff26f 1501extern bt_value *bt_value_map_create(void);
dac5c838 1502
43c59509
PP
1503/*!
1504@brief
1505 Status codes for the <code>bt_value_map_insert_*()</code> functions.
1506*/
1507typedef 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
1526To insert an entry having a null value, pass #bt_value_null as
1527\bt_p{entry_value}.
1528
1529On 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*/
1574extern 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
1583On 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
1585created 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*/
1608extern 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
1617On 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
1619created 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*/
1642extern bt_value_map_insert_entry_status
1643bt_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
1652On 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
1654created 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*/
1677extern bt_value_map_insert_entry_status
1678bt_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
1687On 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
1689created 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*/
1712extern 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
1721On 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
1723created 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*/
1746extern bt_value_map_insert_entry_status
1747bt_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
1755On 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
1757array value.
1758
1759On 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
1761created 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*/
1785extern bt_value_map_insert_entry_status
1786bt_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
1794On 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
1796value.
1797
1798On 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
1800created 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*/
1824extern bt_value_map_insert_entry_status
1825bt_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
1833If no entry with key \bt_p{key} exists in \bt_p{value}, this function
1834returns \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*/
b19ff26f 1859extern bt_value *bt_value_map_borrow_entry_value(
43c59509
PP
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
1867See bt_value_map_borrow_entry_value().
1868*/
1869extern const bt_value *bt_value_map_borrow_entry_value_const(
1870 const bt_value *value, const char *key);
dac5c838 1871
43c59509
PP
1872/*!
1873@brief
1874 Status codes for #bt_value_map_foreach_entry_func.
1875*/
27c61ce8 1876typedef enum bt_value_map_foreach_entry_func_status {
43c59509
PP
1877 /*!
1878 @brief
1879 Success.
1880 */
27c61ce8 1881 BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
1882
1883 /*!
1884 @brief
1885 Interrupt the iteration process.
1886 */
27c61ce8 1887 BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT = __BT_FUNC_STATUS_INTERRUPTED,
43c59509
PP
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,
27c61ce8
PP
1900} bt_value_map_foreach_entry_func_status;
1901
43c59509
PP
1902/*!
1903@brief
1904 User function for bt_value_map_foreach_entry().
1905
1906This is the type of the user function that bt_value_map_foreach_entry()
1907calls 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*/
27c61ce8
PP
1932typedef bt_value_map_foreach_entry_func_status
1933 (* bt_value_map_foreach_entry_func)(const char *key,
43c59509 1934 bt_value *value, void *user_data);
de079588 1935
43c59509
PP
1936/*!
1937@brief
1938 Status codes for bt_value_map_foreach_entry().
1939*/
d24d5663 1940typedef enum bt_value_map_foreach_entry_status {
43c59509
PP
1941 /*!
1942 @brief
1943 Success.
1944 */
d24d5663 1945 BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
1946
1947 /*!
1948 @brief
1949 User function interrupted the iteration process.
1950 */
9b4f9b42 1951 BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED,
43c59509
PP
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,
d24d5663 1970} bt_value_map_foreach_entry_status;
dac5c838 1971
43c59509
PP
1972/*!
1973@brief
1974 Iterates the entries of the map value \bt_p{value}, calling
1975 \bt_p{user_func} for each entry.
1976
1977This function iterates the entries of \bt_p{value} in no particular
1978order.
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
1985The 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*/
d24d5663 2023extern bt_value_map_foreach_entry_status bt_value_map_foreach_entry(
43c59509
PP
2024 bt_value *value, bt_value_map_foreach_entry_func user_func,
2025 void *user_data);
05e21286 2026
43c59509
PP
2027/*!
2028@brief
2029 Status codes for #bt_value_map_foreach_entry_const_func.
2030*/
2031typedef 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,
d24d5663 2037
43c59509
PP
2038 /*!
2039 @brief
2040 Interrupt the iteration process.
2041 */
2042 BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT = __BT_FUNC_STATUS_INTERRUPTED,
d24d5663 2043
43c59509
PP
2044 /*!
2045 @brief
2046 Out of memory.
2047 */
2048 BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
05e21286 2049
43c59509
PP
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;
fdd3a2da 2056
43c59509
PP
2057/*!
2058@brief
2059 User function for bt_value_map_foreach_entry_const_func().
05e21286 2060
43c59509
PP
2061This is the type of the user function that
2062bt_value_map_foreach_entry_const_func() calls for each entry of the map
2063value.
05e21286 2064
43c59509
PP
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.
05e21286 2071
43c59509
PP
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.
dac5c838 2080
43c59509
PP
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*/
2087typedef 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*/
2095typedef 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
2132See 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*/
2137extern 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*/
2158extern 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).
770750d3 2169
43c59509
PP
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*/
2176static inline
2177bt_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*/
2202extern 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*/
ab26240f 2209typedef enum bt_value_map_extend_status {
43c59509
PP
2210 /*!
2211 @brief
2212 Success.
2213 */
ab26240f 2214 BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK,
43c59509
PP
2215
2216 /*!
2217 @brief
2218 Out of memory.
2219 */
2220 BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
ab26240f
FD
2221} bt_value_map_extend_status;
2222
43c59509
PP
2223/*!
2224@brief
2225 Extends the map value \bt_p{value} with the map value
2226 \bt_p{extension_value}.
2227
2228For each entry in \bt_p{extension_value}, this function calls
2229bt_value_map_insert_entry() to insert or replace it in the map value
2230\bt_p{value}.
2231
2232For 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
2260The 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*/
ab26240f 2288extern bt_value_map_extend_status bt_value_map_extend(
43c59509
PP
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*/
2302typedef 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
2320This function deep-copies \bt_p{value} and sets \bt_p{*copy} to the
2321result.
2322
2323Because \bt_p{*copy} is a deep copy, it does not contain, recursively,
2324any reference that \bt_p{value} contains, but the raw values are
2325identical.
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*/
2341extern 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*/
2364extern 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*/
2389extern 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*/
2406extern 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
2433This 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/*! @} */
ab26240f 2463
dac5c838
PP
2464#ifdef __cplusplus
2465}
2466#endif
2467
924dc299 2468#endif /* BABELTRACE2_VALUE_H */
This page took 0.160788 seconds and 4 git commands to generate.