1 #ifndef BABELTRACE_VALUES_H
2 #define BABELTRACE_VALUES_H
5 * Babeltrace - Value objects
7 * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation
8 * Copyright (c) 2015-2016 Philippe Proulx <pproulx@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <babeltrace/types.h>
36 #include <babeltrace/ref.h>
43 @defgroup values Value objects
48 #include <babeltrace/values.h>
51 This is a set of <strong><em>value objects</em></strong>. With the
52 functions documented here, you can create and modify:
54 - \link bt_value_bool_create() Boolean value objects\endlink.
55 - \link bt_value_integer_create() Integer value objects\endlink.
56 - \link bt_value_float_create() Floating point number
57 value objects\endlink.
58 - \link bt_value_string_create() String value objects\endlink.
59 - \link bt_value_array_create() Array value objects\endlink,
60 containing zero or more value objects.
61 - \link bt_value_map_create() Map value objects\endlink, mapping
62 string keys to value objects.
64 As with any Babeltrace object, value objects have
65 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
66 counts</a>. When you \link bt_value_array_append() append a value object
67 to an array value object\endlink, or when you \link bt_value_map_insert()
68 insert a value object into a map value object\endlink, its reference
69 count is incremented, as well as when you get a value object back from
70 those objects. See \ref refs to learn more about the reference counting
71 management of Babeltrace objects.
73 Most functions of this API return a <em>status code</em>, one of the
74 values of #bt_value_status.
76 You can create a deep copy of any value object with bt_value_copy(). You
77 can compare two value objects with bt_value_compare().
79 The following matrix shows some categorized value object functions
80 to use for each value object type:
84 <th>Function role →<br>
85 Value object type ↓
93 <td>Use the \ref bt_value_null variable
94 <td>bt_value_is_null()
100 <td>bt_value_bool_create()<br>
101 bt_value_bool_create_init()
102 <td>bt_value_is_bool()
103 <td>bt_value_bool_get()
104 <td>bt_value_bool_set()
108 <td>bt_value_integer_create()<br>
109 bt_value_integer_create_init()
110 <td>bt_value_is_integer()
111 <td>bt_value_integer_get()
112 <td>bt_value_integer_set()
115 <th>Floating point<br>number
116 <td>bt_value_float_create()<br>
117 bt_value_float_create_init()
118 <td>bt_value_is_float()
119 <td>bt_value_float_get()
120 <td>bt_value_float_set()
124 <td>bt_value_string_create()<br>
125 bt_value_string_create_init()
126 <td>bt_value_is_string()
127 <td>bt_value_string_get()
128 <td>bt_value_string_set()
132 <td>bt_value_array_create()
133 <td>bt_value_is_array()
134 <td>bt_value_array_get()
135 <td>bt_value_array_append()<br>
136 bt_value_array_append_bool()<br>
137 bt_value_array_append_integer()<br>
138 bt_value_array_append_float()<br>
139 bt_value_array_append_string()<br>
140 bt_value_array_append_empty_array()<br>
141 bt_value_array_append_empty_map()<br>
146 <td>bt_value_map_create()<br>
147 bt_value_map_extend()
148 <td>bt_value_is_map()
149 <td>bt_value_map_get()<br>
150 bt_value_map_foreach()
151 <td>bt_value_map_insert()<br>
152 bt_value_map_insert_bool()<br>
153 bt_value_map_insert_integer()<br>
154 bt_value_map_insert_float()<br>
155 bt_value_map_insert_string()<br>
156 bt_value_map_insert_empty_array()<br>
157 bt_value_map_insert_empty_map()
162 @brief Value object types and functions.
172 enum bt_value_status
{
173 /// Operation canceled.
174 BT_VALUE_STATUS_CANCELED
= -3,
176 /* -22 for compatibility with -EINVAL */
177 /// Invalid argument.
178 BT_VALUE_STATUS_INVAL
= -22,
181 BT_VALUE_STATUS_ERROR
= -1,
184 BT_VALUE_STATUS_OK
= 0,
189 @brief A value object.
195 @brief The null value object singleton.
197 You \em must use this variable when you need the null value object.
199 The null value object singleton has no reference count: there is only
200 one. You can compare any value object address to the null value object
201 singleton to check if it's the null value object, or otherwise with
204 You can pass \ref bt_value_null to bt_get() or bt_put(): it has
207 The null value object singleton is <em>always frozen</em> (see
208 bt_value_is_frozen()).
210 The functions of this API return this variable when the value object
211 is actually the null value object (of type #BT_VALUE_TYPE_NULL),
212 whereas \c NULL means an error of some sort.
214 extern struct bt_value
*bt_value_null
;
217 @name Type information
222 @brief Value object type.
225 /// Unknown value object, used as an error code.
226 BT_VALUE_TYPE_UNKNOWN
= -1,
228 /// Null value object.
229 BT_VALUE_TYPE_NULL
= 0,
231 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
232 BT_VALUE_TYPE_BOOL
= 1,
234 /// Integer value object (holds a signed 64-bit integer raw value).
235 BT_VALUE_TYPE_INTEGER
= 2,
237 /// Floating point number value object (holds a \c double raw value).
238 BT_VALUE_TYPE_FLOAT
= 3,
240 /// String value object.
241 BT_VALUE_TYPE_STRING
= 4,
243 /// Array value object.
244 BT_VALUE_TYPE_ARRAY
= 5,
246 /// Map value object.
247 BT_VALUE_TYPE_MAP
= 6,
251 @brief Returns the type of the value object \p object.
253 @param[in] object Value object of which to get the type.
254 @returns Type of value object \p object,
255 or #BT_VALUE_TYPE_UNKNOWN on error.
258 @postrefcountsame{object}
260 @sa #bt_value_type: Value object types.
261 @sa bt_value_is_null(): Returns whether or not a given value object
262 is the null value object.
263 @sa bt_value_is_bool(): Returns whether or not a given value object
264 is a boolean value object.
265 @sa bt_value_is_integer(): Returns whether or not a given value
266 object is an integer value object.
267 @sa bt_value_is_float(): Returns whether or not a given value object
268 is a floating point number value object.
269 @sa bt_value_is_string(): Returns whether or not a given value object
270 is a string value object.
271 @sa bt_value_is_array(): Returns whether or not a given value object
272 is an array value object.
273 @sa bt_value_is_map(): Returns whether or not a given value object
274 is a map value object.
276 extern enum bt_value_type
bt_value_get_type(const struct bt_value
*object
);
279 @brief Returns whether or not the value object \p object is the null
282 The only valid null value object is \ref bt_value_null.
284 An alternative to calling this function is to directly compare the value
285 object pointer to the \ref bt_value_null variable.
287 @param[in] object Value object to check.
288 @returns #BT_TRUE if \p object is the null value object.
291 @postrefcountsame{object}
293 @sa bt_value_get_type(): Returns the type of a given value object.
296 bt_bool
bt_value_is_null(const struct bt_value
*object
)
298 return bt_value_get_type(object
) == BT_VALUE_TYPE_NULL
;
302 @brief Returns whether or not the value object \p object is a boolean
305 @param[in] object Value object to check.
306 @returns #BT_TRUE if \p object is a boolean value object.
309 @postrefcountsame{object}
311 @sa bt_value_get_type(): Returns the type of a given value object.
314 bt_bool
bt_value_is_bool(const struct bt_value
*object
)
316 return bt_value_get_type(object
) == BT_VALUE_TYPE_BOOL
;
320 @brief Returns whether or not the value object \p object is an integer
323 @param[in] object Value object to check.
324 @returns #BT_TRUE if \p object is an integer value object.
326 @sa bt_value_get_type(): Returns the type of a given value object.
329 bt_bool
bt_value_is_integer(const struct bt_value
*object
)
331 return bt_value_get_type(object
) == BT_VALUE_TYPE_INTEGER
;
335 @brief Returns whether or not the value object \p object is a floating
336 point number value object.
338 @param[in] object Value object to check.
339 @returns #BT_TRUE if \p object is a floating point
343 @postrefcountsame{object}
345 @sa bt_value_get_type(): Returns the type of a given value object.
348 bt_bool
bt_value_is_float(const struct bt_value
*object
)
350 return bt_value_get_type(object
) == BT_VALUE_TYPE_FLOAT
;
354 @brief Returns whether or not the value object \p object is a string
357 @param[in] object Value object to check.
358 @returns #BT_TRUE if \p object is a string value object.
361 @postrefcountsame{object}
363 @sa bt_value_get_type(): Returns the type of a given value object.
366 bt_bool
bt_value_is_string(const struct bt_value
*object
)
368 return bt_value_get_type(object
) == BT_VALUE_TYPE_STRING
;
372 @brief Returns whether or not the value object \p object is an array
375 @param[in] object Value object to check.
376 @returns #BT_TRUE if \p object is an array value object.
379 @postrefcountsame{object}
381 @sa bt_value_get_type(): Returns the type of a given value object.
384 bt_bool
bt_value_is_array(const struct bt_value
*object
)
386 return bt_value_get_type(object
) == BT_VALUE_TYPE_ARRAY
;
390 @brief Returns whether or not the value object \p object is a map value
393 @param[in] object Value object to check.
394 @returns #BT_TRUE if \p object is a map value object.
397 @postrefcountsame{object}
399 @sa bt_value_get_type(): Returns the type of a given value object.
402 bt_bool
bt_value_is_map(const struct bt_value
*object
)
404 return bt_value_get_type(object
) == BT_VALUE_TYPE_MAP
;
410 @name Common value object functions
415 @brief Creates a \em deep copy of the value object \p object.
417 You can copy a frozen value object: the resulting copy is
420 @param[in] object Value object to copy.
421 @returns Deep copy of \p object on success, or \c NULL
425 @post <strong>On success, if the returned value object is not
426 \ref bt_value_null</strong>, its reference count is 1.
427 @postrefcountsame{object}
429 extern struct bt_value
*bt_value_copy(const struct bt_value
*object
);
432 @brief Recursively compares the value objects \p object_a and
433 \p object_b and returns #BT_TRUE if they have the same
434 \em content (raw values).
436 @param[in] object_a Value object A to compare to \p object_b.
437 @param[in] object_b Value object B to compare to \p object_a.
438 @returns #BT_TRUE if \p object_a and \p object_b have the
439 same \em content, or #BT_FALSE if they differ
442 @postrefcountsame{object_a}
443 @postrefcountsame{object_b}
445 extern bt_bool
bt_value_compare(const struct bt_value
*object_a
,
446 const struct bt_value
*object_b
);
451 @name Boolean value object functions
456 @brief Creates a default boolean value object.
458 The created boolean value object's initial raw value is #BT_FALSE.
460 @returns Created boolean value object on success, or \c NULL
463 @postsuccessrefcountret1
465 @sa bt_value_bool_create_init(): Creates an initialized boolean
468 extern struct bt_value
*bt_value_bool_create(void);
471 @brief Creates a boolean value object with its initial raw value set to
474 @param[in] val Initial raw value.
475 @returns Created boolean value object on success, or
478 @postsuccessrefcountret1
480 @sa bt_value_bool_create(): Creates a default boolean value object.
482 extern struct bt_value
*bt_value_bool_create_init(bt_bool val
);
485 @brief Returns the boolean raw value of the boolean value object
488 @param[in] bool_obj Boolean value object of which to get the
490 @param[out] val Returned boolean raw value.
491 @returns Status code.
493 @prenotnull{bool_obj}
495 @pre \p bool_obj is a boolean value object.
496 @postrefcountsame{bool_obj}
498 @sa bt_value_bool_set(): Sets the raw value of a boolean value object.
500 extern enum bt_value_status
bt_value_bool_get(
501 const struct bt_value
*bool_obj
, bt_bool
*val
);
504 @brief Sets the boolean raw value of the boolean value object
505 \p bool_obj to \p val.
507 @param[in] bool_obj Boolean value object of which to set
509 @param[in] val New boolean raw value.
510 @returns Status code.
512 @prenotnull{bool_obj}
513 @pre \p bool_obj is a boolean value object.
515 @postrefcountsame{bool_obj}
517 @sa bt_value_bool_get(): Returns the raw value of a given boolean
520 extern enum bt_value_status
bt_value_bool_set(struct bt_value
*bool_obj
,
526 @name Integer value object functions
531 @brief Creates a default integer value object.
533 The created integer value object's initial raw value is 0.
535 @returns Created integer value object on success, or \c NULL
538 @postsuccessrefcountret1
540 @sa bt_value_integer_create_init(): Creates an initialized integer
543 extern struct bt_value
*bt_value_integer_create(void);
546 @brief Creates an integer value object with its initial raw value set to
549 @param[in] val Initial raw value.
550 @returns Created integer value object on success, or
553 @postsuccessrefcountret1
555 @sa bt_value_integer_create(): Creates a default integer
558 extern struct bt_value
*bt_value_integer_create_init(int64_t val
);
561 @brief Returns the integer raw value of the integer value object
564 @param[in] integer_obj Integer value object of which to get the
566 @param[out] val Returned integer raw value.
567 @returns Status code.
569 @prenotnull{integer_obj}
571 @pre \p integer_obj is an integer value object.
572 @postrefcountsame{integer_obj}
574 @sa bt_value_integer_set(): Sets the raw value of an integer value
577 extern enum bt_value_status
bt_value_integer_get(
578 const struct bt_value
*integer_obj
, int64_t *val
);
581 @brief Sets the integer raw value of the integer value object
582 \p integer_obj to \p val.
584 @param[in] integer_obj Integer value object of which to set
586 @param[in] val New integer raw value.
587 @returns Status code.
589 @prenotnull{integer_obj}
590 @pre \p integer_obj is an integer value object.
592 @postrefcountsame{integer_obj}
594 @sa bt_value_integer_get(): Returns the raw value of a given integer
597 extern enum bt_value_status
bt_value_integer_set(
598 struct bt_value
*integer_obj
, int64_t val
);
603 @name Floating point number value object functions
608 @brief Creates a default floating point number value object.
610 The created floating point number value object's initial raw value is 0.
612 @returns Created floating point number value object on success,
615 @postsuccessrefcountret1
617 @sa bt_value_float_create_init(): Creates an initialized floating
618 point number value object.
620 extern struct bt_value
*bt_value_float_create(void);
623 @brief Creates a floating point number value object with its initial raw
626 @param[in] val Initial raw value.
627 @returns Created floating point number value object on
628 success, or \c NULL on error.
630 @postsuccessrefcountret1
632 @sa bt_value_float_create(): Creates a default floating point number
635 extern struct bt_value
*bt_value_float_create_init(double val
);
638 @brief Returns the floating point number raw value of the floating point
639 number value object \p float_obj.
641 @param[in] float_obj Floating point number value object of which to
643 @param[out] val Returned floating point number raw value
644 @returns Status code.
646 @prenotnull{float_obj}
648 @pre \p float_obj is a floating point number value object.
649 @postrefcountsame{float_obj}
651 @sa bt_value_float_set(): Sets the raw value of a given floating
652 point number value object.
654 extern enum bt_value_status
bt_value_float_get(
655 const struct bt_value
*float_obj
, double *val
);
658 @brief Sets the floating point number raw value of the floating point
659 number value object \p float_obj to \p val.
661 @param[in] float_obj Floating point number value object of which to set
663 @param[in] val New floating point number raw value.
664 @returns Status code.
666 @prenotnull{float_obj}
667 @pre \p float_obj is a floating point number value object.
669 @postrefcountsame{float_obj}
671 @sa bt_value_float_get(): Returns the raw value of a floating point
674 extern enum bt_value_status
bt_value_float_set(
675 struct bt_value
*float_obj
, double val
);
680 @name String value object functions
685 @brief Creates a default string value object.
687 The string value object is initially empty.
689 @returns Created string value object on success, or \c NULL
692 @postsuccessrefcountret1
694 @sa bt_value_string_create_init(): Creates an initialized string
697 extern struct bt_value
*bt_value_string_create(void);
700 @brief Creates a string value object with its initial raw value set to
703 On success, \p val is copied.
705 @param[in] val Initial raw value (copied on success).
706 @returns Created string value object on success, or
710 @postsuccessrefcountret1
712 @sa bt_value_float_create(): Creates a default string value object.
714 extern struct bt_value
*bt_value_string_create_init(const char *val
);
717 @brief Returns the string raw value of the string value object
720 The returned string is placed in \p *val. It is valid as long as this
721 value object exists and is \em not modified. The ownership of the
722 returned string is \em not transferred to the caller.
724 @param[in] string_obj String value object of which to get the
726 @param[out] val Returned string raw value.
727 @returns Status code.
729 @prenotnull{string_obj}
731 @pre \p string_obj is a string value object.
732 @postrefcountsame{string_obj}
734 @sa bt_value_string_set(): Sets the raw value of a string
737 extern enum bt_value_status
bt_value_string_get(
738 const struct bt_value
*string_obj
, const char **val
);
741 @brief Sets the string raw value of the string value object
742 \p string_obj to \p val.
744 On success, \p val is copied.
746 @param[in] string_obj String value object of which to set
748 @param[in] val New string raw value (copied on success).
749 @returns Status code.
751 @prenotnull{string_obj}
753 @pre \p string_obj is a string value object.
755 @postrefcountsame{string_obj}
757 @sa bt_value_string_get(): Returns the raw value of a given string
760 extern enum bt_value_status
bt_value_string_set(struct bt_value
*string_obj
,
768 * @name Array value object functions
773 @brief Creates an empty array value object.
775 @returns Created array value object on success, or \c NULL
778 @postsuccessrefcountret1
780 extern struct bt_value
*bt_value_array_create(void);
783 @brief Returns the size of the array value object \p array_obj, that is,
784 the number of value objects contained in \p array_obj.
786 @param[in] array_obj Array value object of which to get the size.
787 @returns Number of value objects contained in
788 \p array_obj if the return value is 0 (empty)
789 or a positive value, or one of
790 #bt_value_status negative values otherwise.
792 @prenotnull{array_obj}
793 @pre \p array_obj is an array value object.
794 @postrefcountsame{array_obj}
796 @sa bt_value_array_is_empty(): Checks whether or not a given array
797 value object is empty.
799 extern int64_t bt_value_array_size(const struct bt_value
*array_obj
);
802 @brief Checks whether or not the array value object \p array_obj
805 @param[in] array_obj Array value object to check.
806 @returns #BT_TRUE if \p array_obj is empty.
808 @prenotnull{array_obj}
809 @pre \p array_obj is an array value object.
810 @postrefcountsame{array_obj}
812 @sa bt_value_array_size(): Returns the size of a given array value
815 extern bt_bool
bt_value_array_is_empty(const struct bt_value
*array_obj
);
817 extern struct bt_value
*bt_value_array_borrow(const struct bt_value
*array_obj
,
821 @brief Returns the value object contained in the array value object
822 \p array_obj at the index \p index.
824 @param[in] array_obj Array value object of which to get an element.
825 @param[in] index Index of value object to get.
826 @returns Value object at index \p index on
827 success, or \c NULL on error.
829 @prenotnull{array_obj}
830 @pre \p array_obj is an array value object.
831 @pre \p index is lesser than the size of \p array_obj (see
832 bt_value_array_size()).
833 @post <strong>On success, if the returned value object is not
834 \ref bt_value_null</strong>, its reference count is incremented.
835 @postrefcountsame{array_obj}
838 struct bt_value
*bt_value_array_get(const struct bt_value
*array_obj
,
841 return bt_get(bt_value_array_borrow(array_obj
, index
));
845 @brief Appends the value object \p element_obj to the array value
848 @param[in] array_obj Array value object in which to append
850 @param[in] element_obj Value object to append.
851 @returns Status code.
853 @prenotnull{array_obj}
854 @prenotnull{element_obj}
855 @pre \p array_obj is an array value object.
857 @post <strong>On success, if \p element_obj is not
858 \ref bt_value_null</strong>, its reference count is incremented.
859 @postrefcountsame{array_obj}
861 @sa bt_value_array_append_bool(): Appends a boolean raw value to a
862 given array value object.
863 @sa bt_value_array_append_integer(): Appends an integer raw value
864 to a given array value object.
865 @sa bt_value_array_append_float(): Appends a floating point number
866 raw value to a given array value object.
867 @sa bt_value_array_append_string(): Appends a string raw value to a
868 given array value object.
869 @sa bt_value_array_append_empty_array(): Appends an empty array value
870 object to a given array value object.
871 @sa bt_value_array_append_empty_map(): Appends an empty map value
872 object to a given array value object.
874 extern enum bt_value_status
bt_value_array_append(struct bt_value
*array_obj
,
875 struct bt_value
*element_obj
);
878 @brief Appends the boolean raw value \p val to the array value object
881 This is a convenience function which creates the underlying boolean
882 value object before appending it.
884 @param[in] array_obj Array value object in which to append \p val.
885 @param[in] val Boolean raw value to append to \p array_obj.
886 @returns Status code.
888 @prenotnull{array_obj}
889 @pre \p array_obj is an array value object.
891 @postrefcountsame{array_obj}
893 @sa bt_value_array_append(): Appends a value object to a given
896 extern enum bt_value_status
bt_value_array_append_bool(
897 struct bt_value
*array_obj
, bt_bool val
);
900 @brief Appends the integer raw value \p val to the array value object
903 This is a convenience function which creates the underlying integer
904 value object before appending it.
906 @param[in] array_obj Array value object in which to append \p val.
907 @param[in] val Integer raw value to append to \p array_obj.
908 @returns Status code.
910 @prenotnull{array_obj}
911 @pre \p array_obj is an array value object.
913 @postrefcountsame{array_obj}
915 @sa bt_value_array_append(): Appends a value object to a given
918 extern enum bt_value_status
bt_value_array_append_integer(
919 struct bt_value
*array_obj
, int64_t val
);
922 @brief Appends the floating point number raw value \p val to the array
923 value object \p array_obj.
925 This is a convenience function which creates the underlying floating
926 point number value object before appending it.
928 @param[in] array_obj Array value object in which to append \p val.
929 @param[in] val Floating point number raw value to append
931 @returns Status code.
933 @prenotnull{array_obj}
934 @pre \p array_obj is an array value object.
936 @postrefcountsame{array_obj}
938 @sa bt_value_array_append(): Appends a value object to a given
941 extern enum bt_value_status
bt_value_array_append_float(
942 struct bt_value
*array_obj
, double val
);
945 @brief Appends the string raw value \p val to the array value object
948 This is a convenience function which creates the underlying string value
949 object before appending it.
951 On success, \p val is copied.
953 @param[in] array_obj Array value object in which to append \p val.
954 @param[in] val String raw value to append to \p array_obj
956 @returns Status code.
958 @prenotnull{array_obj}
959 @pre \p array_obj is an array value object.
962 @postrefcountsame{array_obj}
964 @sa bt_value_array_append(): Appends a value object to a given
967 extern enum bt_value_status
bt_value_array_append_string(
968 struct bt_value
*array_obj
, const char *val
);
971 @brief Appends an empty array value object to the array value object
974 This is a convenience function which creates the underlying array value
975 object before appending it.
977 @param[in] array_obj Array value object in which to append an
978 empty array value object
979 @returns Status code.
981 @prenotnull{array_obj}
982 @pre \p array_obj is an array value object.
984 @postrefcountsame{array_obj}
986 @sa bt_value_array_append(): Appends a value object to a given
989 extern enum bt_value_status
bt_value_array_append_empty_array(
990 struct bt_value
*array_obj
);
993 @brief Appends an empty map value object to the array value object
996 This is a convenience function which creates the underlying map value
997 object before appending it.
999 @param[in] array_obj Array value object in which to append an empty
1001 @returns Status code.
1003 @prenotnull{array_obj}
1004 @pre \p array_obj is an array value object.
1006 @postrefcountsame{array_obj}
1008 @sa bt_value_array_append(): Appends a value object to a given
1011 extern enum bt_value_status
bt_value_array_append_empty_map(
1012 struct bt_value
*array_obj
);
1015 @brief Replaces the value object contained in the array value object
1016 \p array_obj at the index \p index by \p element_obj.
1018 @param[in] array_obj Array value object in which to replace
1020 @param[in] index Index of value object to replace in
1022 @param[in] element_obj New value object at position \p index of
1024 @returns Status code.
1026 @prenotnull{array_obj}
1027 @prenotnull{element_obj}
1028 @pre \p array_obj is an array value object.
1029 @pre \p index is lesser than the size of \p array_obj (see
1030 bt_value_array_size()).
1032 @post <strong>On success, if the replaced value object is not
1033 \ref bt_value_null</strong>, its reference count is decremented.
1034 @post <strong>On success, if \p element_obj is not
1035 \ref bt_value_null</strong>, its reference count is incremented.
1036 @postrefcountsame{array_obj}
1038 extern enum bt_value_status
bt_value_array_set(struct bt_value
*array_obj
,
1039 uint64_t index
, struct bt_value
*element_obj
);
1044 @name Map value object functions
1049 @brief Creates an empty map value object.
1051 @returns Created map value object on success, or \c NULL on error.
1053 @postsuccessrefcountret1
1055 extern struct bt_value
*bt_value_map_create(void);
1058 @brief Returns the size of the map value object \p map_obj, that is, the
1059 number of entries contained in \p map_obj.
1061 @param[in] map_obj Map value object of which to get the size.
1062 @returns Number of entries contained in \p map_obj if the
1063 return value is 0 (empty) or a positive value,
1064 or one of #bt_value_status negative values
1067 @prenotnull{map_obj}
1068 @pre \p map_obj is a map value object.
1069 @postrefcountsame{map_obj}
1071 @sa bt_value_map_is_empty(): Checks whether or not a given map value
1074 extern int64_t bt_value_map_size(const struct bt_value
*map_obj
);
1077 @brief Checks whether or not the map value object \p map_obj is empty.
1079 @param[in] map_obj Map value object to check.
1080 @returns #BT_TRUE if \p map_obj is empty.
1082 @prenotnull{map_obj}
1083 @pre \p map_obj is a map value object.
1084 @postrefcountsame{map_obj}
1086 @sa bt_value_map_size(): Returns the size of a given map value object.
1088 extern bt_bool
bt_value_map_is_empty(const struct bt_value
*map_obj
);
1090 extern struct bt_value
*bt_value_map_borrow(const struct bt_value
*map_obj
,
1094 @brief Returns the value object associated with the key \p key within
1095 the map value object \p map_obj.
1097 @param[in] map_obj Map value object of which to get an entry.
1098 @param[in] key Key of the value object to get.
1099 @returns Value object associated with the key \p key
1100 on success, or \c NULL on error.
1102 @prenotnull{map_obj}
1104 @pre \p map_obj is a map value object.
1105 @postrefcountsame{map_obj}
1106 @post <strong>On success, if the returned value object is not
1107 \ref bt_value_null</strong>, its reference count is incremented.
1110 struct bt_value
*bt_value_map_get(const struct bt_value
*map_obj
,
1113 return bt_get(bt_value_map_borrow(map_obj
, key
));
1117 @brief User function type to use with bt_value_map_foreach().
1119 \p object is a <em>weak reference</em>: you \em must pass it to bt_get()
1120 if you need to keep a reference after this function returns.
1122 This function \em must return #BT_TRUE to continue the map value object
1123 traversal, or #BT_FALSE to break it.
1125 @param[in] key Key of map entry.
1126 @param[in] object Value object of map entry (weak reference).
1127 @param[in] data User data.
1128 @returns #BT_TRUE to continue the loop, or #BT_FALSE to break it.
1132 @post The reference count of \p object is not lesser than what it is
1133 when the function is called.
1135 typedef bt_bool (* bt_value_map_foreach_cb
)(const char *key
,
1136 struct bt_value
*object
, void *data
);
1139 @brief Calls a provided user function \p cb for each value object of the
1140 map value object \p map_obj.
1142 The value object passed to the user function is a <b>weak reference</b>:
1143 you \em must pass it to bt_get() if you need to keep a persistent
1144 reference after the user function returns.
1146 The key passed to the user function is only valid in the scope of
1147 this user function call.
1149 The user function \em must return #BT_TRUE to continue the traversal of
1150 \p map_obj, or #BT_FALSE to break it.
1152 @param[in] map_obj Map value object on which to iterate.
1153 @param[in] cb User function to call back.
1154 @param[in] data User data passed to the user function.
1155 @returns Status code. More
1156 specifically, #BT_VALUE_STATUS_CANCELED is
1157 returned if the loop was canceled by the user
1160 @prenotnull{map_obj}
1162 @pre \p map_obj is a map value object.
1163 @postrefcountsame{map_obj}
1165 extern enum bt_value_status
bt_value_map_foreach(
1166 const struct bt_value
*map_obj
, bt_value_map_foreach_cb cb
,
1170 @brief Returns whether or not the map value object \p map_obj contains
1171 an entry mapped to the key \p key.
1173 @param[in] map_obj Map value object to check.
1174 @param[in] key Key to check.
1175 @returns #BT_TRUE if \p map_obj has an entry mapped to the
1176 key \p key, or #BT_FALSE if it does not or
1179 @prenotnull{map_obj}
1181 @pre \p map_obj is a map value object.
1182 @postrefcountsame{map_obj}
1184 extern bt_bool
bt_value_map_has_key(const struct bt_value
*map_obj
,
1188 @brief Inserts the value object \p element_obj mapped to the key
1189 \p key into the map value object \p map_obj.
1191 If a value object is already mapped to \p key in \p map_obj, the
1192 associated value object is first put, and then replaced by
1195 On success, \p key is copied.
1197 @param[in] map_obj Map value object in which to insert
1199 @param[in] key Key (copied on success) to which the
1200 value object to insert is mapped.
1201 @param[in] element_obj Value object to insert, mapped to the
1203 @returns Status code.
1205 @prenotnull{map_obj}
1207 @prenotnull{element_obj}
1208 @pre \p map_obj is a map value object.
1210 @post <strong>On success, if \p element_obj is not
1211 \ref bt_value_null</strong>, its reference count is incremented.
1212 @postrefcountsame{map_obj}
1214 @sa bt_value_map_insert_bool(): Inserts a boolean raw value into a
1215 given map value object.
1216 @sa bt_value_map_insert_integer(): Inserts an integer raw value into
1217 a given map value object.
1218 @sa bt_value_map_insert_float(): Inserts a floating point number raw
1219 value into a given map value object.
1220 @sa bt_value_map_insert_string(): Inserts a string raw value into a
1221 given map value object.
1222 @sa bt_value_map_insert_empty_array(): Inserts an empty array value
1223 object into a given map value object.
1224 @sa bt_value_map_insert_empty_map(): Inserts an empty map value
1225 object into a given map value object.
1227 extern enum bt_value_status
bt_value_map_insert(
1228 struct bt_value
*map_obj
, const char *key
,
1229 struct bt_value
*element_obj
);
1232 @brief Inserts the boolean raw value \p val mapped to the key \p key
1233 into the map value object \p map_obj.
1235 This is a convenience function which creates the underlying boolean
1236 value object before inserting it.
1238 On success, \p key is copied.
1240 @param[in] map_obj Map value object in which to insert \p val.
1241 @param[in] key Key (copied on success) to which the boolean
1242 value object to insert is mapped.
1243 @param[in] val Boolean raw value to insert, mapped to
1245 @returns Status code.
1247 @prenotnull{map_obj}
1249 @pre \p map_obj is a map value object.
1251 @postrefcountsame{map_obj}
1253 @sa bt_value_map_insert(): Inserts a value object into a given map
1256 extern enum bt_value_status
bt_value_map_insert_bool(
1257 struct bt_value
*map_obj
, const char *key
, bt_bool val
);
1260 @brief Inserts the integer raw value \p val mapped to the key \p key
1261 into the map value object \p map_obj.
1263 This is a convenience function which creates the underlying integer
1264 value object before inserting it.
1266 On success, \p key is copied.
1268 @param[in] map_obj Map value object in which to insert \p val.
1269 @param[in] key Key (copied on success) to which the integer
1270 value object to insert is mapped.
1271 @param[in] val Integer raw value to insert, mapped to
1273 @returns Status code.
1275 @prenotnull{map_obj}
1277 @pre \p map_obj is a map value object.
1279 @postrefcountsame{map_obj}
1281 @sa bt_value_map_insert(): Inserts a value object into a given map
1284 extern enum bt_value_status
bt_value_map_insert_integer(
1285 struct bt_value
*map_obj
, const char *key
, int64_t val
);
1288 @brief Inserts the floating point number raw value \p val mapped to
1289 the key \p key into the map value object \p map_obj.
1291 This is a convenience function which creates the underlying floating
1292 point number value object before inserting it.
1294 On success, \p key is copied.
1296 @param[in] map_obj Map value object in which to insert \p val.
1297 @param[in] key Key (copied on success) to which the floating
1298 point number value object to insert is mapped.
1299 @param[in] val Floating point number raw value to insert,
1300 mapped to the key \p key.
1301 @returns Status code.
1303 @prenotnull{map_obj}
1305 @pre \p map_obj is a map value object.
1307 @postrefcountsame{map_obj}
1309 @sa bt_value_map_insert(): Inserts a value object into a given map
1312 extern enum bt_value_status
bt_value_map_insert_float(
1313 struct bt_value
*map_obj
, const char *key
, double val
);
1316 @brief Inserts the string raw value \p val mapped to the key \p key
1317 into the map value object \p map_obj.
1319 This is a convenience function which creates the underlying string value
1320 object before inserting it.
1322 On success, \p val and \p key are copied.
1324 @param[in] map_obj Map value object in which to insert \p val.
1325 @param[in] key Key (copied on success) to which the string
1326 value object to insert is mapped.
1327 @param[in] val String raw value to insert (copied on success),
1328 mapped to the key \p key.
1329 @returns Status code.
1331 @prenotnull{map_obj}
1334 @pre \p map_obj is a map value object.
1336 @postrefcountsame{map_obj}
1338 @sa bt_value_map_insert(): Inserts a value object into a given map
1341 extern enum bt_value_status
bt_value_map_insert_string(
1342 struct bt_value
*map_obj
, const char *key
, const char *val
);
1345 @brief Inserts an empty array value object mapped to the key \p key
1346 into the map value object \p map_obj.
1348 This is a convenience function which creates the underlying array value
1349 object before inserting it.
1351 On success, \p key is copied.
1353 @param[in] map_obj Map value object in which to insert an empty
1355 @param[in] key Key (copied on success) to which the empty array
1356 value object to insert is mapped.
1357 @returns Status code.
1359 @prenotnull{map_obj}
1361 @pre \p map_obj is a map value object.
1363 @postrefcountsame{map_obj}
1365 @sa bt_value_map_insert(): Inserts a value object into a given map
1368 extern enum bt_value_status
bt_value_map_insert_empty_array(
1369 struct bt_value
*map_obj
, const char *key
);
1372 @brief Inserts an empty map value object mapped to the key \p key into
1373 the map value object \p map_obj.
1375 This is a convenience function which creates the underlying map value
1376 object before inserting it.
1378 On success, \p key is copied.
1380 @param[in] map_obj Map value object in which to insert an empty
1382 @param[in] key Key (copied on success) to which the empty map
1383 value object to insert is mapped.
1384 @returns Status code.
1386 @prenotnull{map_obj}
1388 @pre \p map_obj is a map value object.
1390 @postrefcountsame{map_obj}
1392 @sa bt_value_map_insert(): Inserts a value object into a given map
1395 extern enum bt_value_status
bt_value_map_insert_empty_map(
1396 struct bt_value
*map_obj
, const char *key
);
1399 @brief Creates a copy of the base map value object \p base_map_obj
1400 superficially extended with the entries of the extension map
1401 value object \p extension_map_obj.
1403 This function creates a superficial extension of \p base_map_obj with
1404 \p extension_map_obj by adding new entries to it and replacing the
1405 ones that share the keys in the extension object. The extension is
1406 \em superficial because it does not merge internal array and map
1409 For example, consider the following \p base_map_obj (JSON representation):
1416 "return": [5, 6, null]
1420 and the following \p extension_map_obj (JSON representation):
1430 The extended object is (JSON representation):
1442 @param[in] base_map_obj Base map value object with initial
1444 @param[in] extension_map_obj Extension map value object containing
1445 the entries to add to or replace in
1447 @returns Created extended map value object, or
1450 @prenotnull{base_map_obj}
1451 @prenotnull{extension_map_obj}
1452 @pre \p base_map_obj is a map value object.
1453 @pre \p extension_map_obj is a map value object.
1454 @postrefcountsame{base_map_obj}
1455 @postrefcountsame{extension_map_obj}
1456 @postsuccessrefcountret1
1458 extern struct bt_value
*bt_value_map_extend(struct bt_value
*base_map_obj
,
1459 struct bt_value
*extension_map_obj
);
1469 #endif /* BABELTRACE_VALUES_H */