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
31 #include <babeltrace/ref.h>
32 #include <babeltrace/types.h>
39 @defgroup values Value objects
44 #include <babeltrace/values.h>
47 This is a set of <strong><em>value objects</em></strong>. With the
48 functions documented here, you can create and modify:
50 - \link bt_value_bool_create() Boolean value objects\endlink.
51 - \link bt_value_integer_create() Integer value objects\endlink.
52 - \link bt_value_float_create() Floating point number
53 value objects\endlink.
54 - \link bt_value_string_create() String value objects\endlink.
55 - \link bt_value_array_create() Array value objects\endlink,
56 containing zero or more value objects.
57 - \link bt_value_map_create() Map value objects\endlink, mapping
58 string keys to value objects.
60 As with any Babeltrace object, value objects have
61 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
62 counts</a>. When you \link bt_value_array_append() append a value object
63 to an array value object\endlink, or when you \link bt_value_map_insert()
64 insert a value object into a map value object\endlink, its reference
65 count is incremented, as well as when you get a value object back from
66 those objects. See \ref refs to learn more about the reference counting
67 management of Babeltrace objects.
69 Most functions of this API return a <em>status code</em>, one of the
70 values of #bt_value_status.
72 You can create a deep copy of any value object with bt_value_copy(). You
73 can compare two value objects with bt_value_compare().
75 You can \em freeze a value object with bt_value_freeze(). You can get
76 the raw value of a frozen value object, but you cannot modify it.
77 Reference counting still works on frozen value objects. You can copy
78 a frozen value object: the returned copy is not frozen. You can also
79 compare a frozen value object to another value object (frozen or not).
80 Freezing a value object is typically used to make it immutable after
81 it's built by its initial owner.
83 The following matrix shows some categorized value object functions
84 to use for each value object type:
88 <th>Function role →<br>
89 Value object type ↓
97 <td>Use the \ref bt_value_null variable
98 <td>bt_value_is_null()
104 <td>bt_value_bool_create()<br>
105 bt_value_bool_create_init()
106 <td>bt_value_is_bool()
107 <td>bt_value_bool_get()
108 <td>bt_value_bool_set()
112 <td>bt_value_integer_create()<br>
113 bt_value_integer_create_init()
114 <td>bt_value_is_integer()
115 <td>bt_value_integer_get()
116 <td>bt_value_integer_set()
119 <th>Floating point<br>number
120 <td>bt_value_float_create()<br>
121 bt_value_float_create_init()
122 <td>bt_value_is_float()
123 <td>bt_value_float_get()
124 <td>bt_value_float_set()
128 <td>bt_value_string_create()<br>
129 bt_value_string_create_init()
130 <td>bt_value_is_string()
131 <td>bt_value_string_get()
132 <td>bt_value_string_set()
136 <td>bt_value_array_create()
137 <td>bt_value_is_array()
138 <td>bt_value_array_get()
139 <td>bt_value_array_append()<br>
140 bt_value_array_append_bool()<br>
141 bt_value_array_append_integer()<br>
142 bt_value_array_append_float()<br>
143 bt_value_array_append_string()<br>
144 bt_value_array_append_empty_array()<br>
145 bt_value_array_append_empty_map()<br>
150 <td>bt_value_map_create()<br>
151 bt_value_map_extend()
152 <td>bt_value_is_map()
153 <td>bt_value_map_get()<br>
154 bt_value_map_foreach()
155 <td>bt_value_map_insert()<br>
156 bt_value_map_insert_bool()<br>
157 bt_value_map_insert_integer()<br>
158 bt_value_map_insert_float()<br>
159 bt_value_map_insert_string()<br>
160 bt_value_map_insert_empty_array()<br>
161 bt_value_map_insert_empty_map()
166 @brief Value object types and functions.
176 enum bt_value_status
{
177 /// Value object cannot be altered because it's frozen.
178 BT_VALUE_STATUS_FROZEN
= -4,
180 /// Operation cancelled.
181 BT_VALUE_STATUS_CANCELLED
= -3,
183 /* -22 for compatibility with -EINVAL */
184 /// Invalid argument.
185 BT_VALUE_STATUS_INVAL
= -22,
188 BT_VALUE_STATUS_ERROR
= -1,
191 BT_VALUE_STATUS_OK
= 0,
196 @brief A value object.
202 @brief The null value object singleton.
204 You \em must use this variable when you need the null value object.
206 The null value object singleton has no reference count: there is only
207 one. You can compare any value object address to the null value object
208 singleton to check if it's the null value object, or otherwise with
211 You can pass \ref bt_value_null to bt_get() or bt_put(): it has
214 The null value object singleton is <em>always frozen</em> (see
215 bt_value_is_frozen()).
217 The functions of this API return this variable when the value object
218 is actually the null value object (of type #BT_VALUE_TYPE_NULL),
219 whereas \c NULL means an error of some sort.
221 extern struct bt_value
*bt_value_null
;
224 @name Type information
229 @brief Value object type.
232 /// Unknown value object, used as an error code.
233 BT_VALUE_TYPE_UNKNOWN
= -1,
235 /// Null value object.
236 BT_VALUE_TYPE_NULL
= 0,
238 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
239 BT_VALUE_TYPE_BOOL
= 1,
241 /// Integer value object (holds a signed 64-bit integer raw value).
242 BT_VALUE_TYPE_INTEGER
= 2,
244 /// Floating point number value object (holds a \c double raw value).
245 BT_VALUE_TYPE_FLOAT
= 3,
247 /// String value object.
248 BT_VALUE_TYPE_STRING
= 4,
250 /// Array value object.
251 BT_VALUE_TYPE_ARRAY
= 5,
253 /// Map value object.
254 BT_VALUE_TYPE_MAP
= 6,
258 @brief Returns the type of the value object \p object.
260 @param[in] object Value object of which to get the type.
261 @returns Type of value object \p object,
262 or #BT_VALUE_TYPE_UNKNOWN on error.
265 @postrefcountsame{object}
267 @sa #bt_value_type: Value object types.
268 @sa bt_value_is_null(): Returns whether or not a given value object
269 is the null value object.
270 @sa bt_value_is_bool(): Returns whether or not a given value object
271 is a boolean value object.
272 @sa bt_value_is_integer(): Returns whether or not a given value
273 object is an integer value object.
274 @sa bt_value_is_float(): Returns whether or not a given value object
275 is a floating point number value object.
276 @sa bt_value_is_string(): Returns whether or not a given value object
277 is a string value object.
278 @sa bt_value_is_array(): Returns whether or not a given value object
279 is an array value object.
280 @sa bt_value_is_map(): Returns whether or not a given value object
281 is a map value object.
283 extern enum bt_value_type
bt_value_get_type(const struct bt_value
*object
);
286 @brief Returns whether or not the value object \p object is the null
289 The only valid null value object is \ref bt_value_null.
291 An alternative to calling this function is to directly compare the value
292 object pointer to the \ref bt_value_null variable.
294 @param[in] object Value object to check.
295 @returns #BT_TRUE if \p object is the null value object.
298 @postrefcountsame{object}
300 @sa bt_value_get_type(): Returns the type of a given value object.
303 bt_bool
bt_value_is_null(const struct bt_value
*object
)
305 return bt_value_get_type(object
) == BT_VALUE_TYPE_NULL
;
309 @brief Returns whether or not the value object \p object is a boolean
312 @param[in] object Value object to check.
313 @returns #BT_TRUE if \p object is a boolean value object.
316 @postrefcountsame{object}
318 @sa bt_value_get_type(): Returns the type of a given value object.
321 bt_bool
bt_value_is_bool(const struct bt_value
*object
)
323 return bt_value_get_type(object
) == BT_VALUE_TYPE_BOOL
;
327 @brief Returns whether or not the value object \p object is an integer
330 @param[in] object Value object to check.
331 @returns #BT_TRUE if \p object is an integer value object.
333 @sa bt_value_get_type(): Returns the type of a given value object.
336 bt_bool
bt_value_is_integer(const struct bt_value
*object
)
338 return bt_value_get_type(object
) == BT_VALUE_TYPE_INTEGER
;
342 @brief Returns whether or not the value object \p object is a floating
343 point number value object.
345 @param[in] object Value object to check.
346 @returns #BT_TRUE if \p object is a floating point
350 @postrefcountsame{object}
352 @sa bt_value_get_type(): Returns the type of a given value object.
355 bt_bool
bt_value_is_float(const struct bt_value
*object
)
357 return bt_value_get_type(object
) == BT_VALUE_TYPE_FLOAT
;
361 @brief Returns whether or not the value object \p object is a string
364 @param[in] object Value object to check.
365 @returns #BT_TRUE if \p object is a string value object.
368 @postrefcountsame{object}
370 @sa bt_value_get_type(): Returns the type of a given value object.
373 bt_bool
bt_value_is_string(const struct bt_value
*object
)
375 return bt_value_get_type(object
) == BT_VALUE_TYPE_STRING
;
379 @brief Returns whether or not the value object \p object is an array
382 @param[in] object Value object to check.
383 @returns #BT_TRUE if \p object is an array value object.
386 @postrefcountsame{object}
388 @sa bt_value_get_type(): Returns the type of a given value object.
391 bt_bool
bt_value_is_array(const struct bt_value
*object
)
393 return bt_value_get_type(object
) == BT_VALUE_TYPE_ARRAY
;
397 @brief Returns whether or not the value object \p object is a map value
400 @param[in] object Value object to check.
401 @returns #BT_TRUE if \p object is a map value object.
404 @postrefcountsame{object}
406 @sa bt_value_get_type(): Returns the type of a given value object.
409 bt_bool
bt_value_is_map(const struct bt_value
*object
)
411 return bt_value_get_type(object
) == BT_VALUE_TYPE_MAP
;
417 @name Common value object functions
422 @brief Recursively freezes the value object \p object.
424 You cannot modify a frozen value object: it is considered immutable.
425 Reference counting still works on a frozen value object, however: you
426 can pass a frozen value object to bt_get() and bt_put().
428 If \p object is an array value object or a map value object, this
429 function also freezes all its children recursively.
431 Freezing a value object is typically used to make it immutable after
432 it's built by its initial owner.
434 @param[in] object Value object to freeze.
435 @returns Status code. If \p object
436 is already frozen, however, #BT_VALUE_STATUS_OK
437 is returned anyway (that is, this function never
438 returns #BT_VALUE_STATUS_FROZEN).
441 @postrefcountsame{object}
442 @post <strong>On success</strong>, \p object and all its children
445 @sa bt_value_is_frozen(): Returns whether or not a value object is
448 extern enum bt_value_status
bt_value_freeze(struct bt_value
*object
);
451 @brief Returns whether or not the value object \p object is frozen.
453 @param[in] object Value object to check.
454 @returns #BT_TRUE if \p object is frozen.
457 @postrefcountsame{object}
459 extern bt_bool
bt_value_is_frozen(const struct bt_value
*object
);
462 @brief Creates a \em deep copy of the value object \p object.
464 You can copy a frozen value object: the resulting copy is
467 @param[in] object Value object to copy.
468 @returns Deep copy of \p object on success, or \c NULL
472 @post <strong>On success, if the returned value object is not
473 \ref bt_value_null</strong>, its reference count is 1.
474 @postrefcountsame{object}
476 extern struct bt_value
*bt_value_copy(const struct bt_value
*object
);
479 @brief Recursively compares the value objects \p object_a and
480 \p object_b and returns #BT_TRUE if they have the same
481 \em content (raw values).
483 @param[in] object_a Value object A to compare to \p object_b.
484 @param[in] object_b Value object B to compare to \p object_a.
485 @returns #BT_TRUE if \p object_a and \p object_b have the
486 same \em content, or #BT_FALSE if they differ
489 @postrefcountsame{object_a}
490 @postrefcountsame{object_b}
492 extern bt_bool
bt_value_compare(const struct bt_value
*object_a
,
493 const struct bt_value
*object_b
);
498 @name Boolean value object functions
503 @brief Creates a default boolean value object.
505 The created boolean value object's initial raw value is #BT_FALSE.
507 @returns Created boolean value object on success, or \c NULL
510 @postsuccessrefcountret1
512 @sa bt_value_bool_create_init(): Creates an initialized boolean
515 extern struct bt_value
*bt_value_bool_create(void);
518 @brief Creates a boolean value object with its initial raw value set to
521 @param[in] val Initial raw value.
522 @returns Created boolean value object on success, or
525 @postsuccessrefcountret1
527 @sa bt_value_bool_create(): Creates a default boolean value object.
529 extern struct bt_value
*bt_value_bool_create_init(bt_bool val
);
532 @brief Returns the boolean raw value of the boolean value object
535 @param[in] bool_obj Boolean value object of which to get the
537 @param[out] val Returned boolean raw value.
538 @returns Status code.
540 @prenotnull{bool_obj}
542 @pre \p bool_obj is a boolean value object.
543 @postrefcountsame{bool_obj}
545 @sa bt_value_bool_set(): Sets the raw value of a boolean value object.
547 extern enum bt_value_status
bt_value_bool_get(
548 const struct bt_value
*bool_obj
, bt_bool
*val
);
551 @brief Sets the boolean raw value of the boolean value object
552 \p bool_obj to \p val.
554 @param[in] bool_obj Boolean value object of which to set
556 @param[in] val New boolean raw value.
557 @returns Status code.
559 @prenotnull{bool_obj}
560 @pre \p bool_obj is a boolean value object.
562 @postrefcountsame{bool_obj}
564 @sa bt_value_bool_get(): Returns the raw value of a given boolean
567 extern enum bt_value_status
bt_value_bool_set(struct bt_value
*bool_obj
,
573 @name Integer value object functions
578 @brief Creates a default integer value object.
580 The created integer value object's initial raw value is 0.
582 @returns Created integer value object on success, or \c NULL
585 @postsuccessrefcountret1
587 @sa bt_value_integer_create_init(): Creates an initialized integer
590 extern struct bt_value
*bt_value_integer_create(void);
593 @brief Creates an integer value object with its initial raw value set to
596 @param[in] val Initial raw value.
597 @returns Created integer value object on success, or
600 @postsuccessrefcountret1
602 @sa bt_value_integer_create(): Creates a default integer
605 extern struct bt_value
*bt_value_integer_create_init(int64_t val
);
608 @brief Returns the integer raw value of the integer value object
611 @param[in] integer_obj Integer value object of which to get the
613 @param[out] val Returned integer raw value.
614 @returns Status code.
616 @prenotnull{integer_obj}
618 @pre \p integer_obj is an integer value object.
619 @postrefcountsame{integer_obj}
621 @sa bt_value_integer_set(): Sets the raw value of an integer value
624 extern enum bt_value_status
bt_value_integer_get(
625 const struct bt_value
*integer_obj
, int64_t *val
);
628 @brief Sets the integer raw value of the integer value object
629 \p integer_obj to \p val.
631 @param[in] integer_obj Integer value object of which to set
633 @param[in] val New integer raw value.
634 @returns Status code.
636 @prenotnull{integer_obj}
637 @pre \p integer_obj is an integer value object.
639 @postrefcountsame{integer_obj}
641 @sa bt_value_integer_get(): Returns the raw value of a given integer
644 extern enum bt_value_status
bt_value_integer_set(
645 struct bt_value
*integer_obj
, int64_t val
);
650 @name Floating point number value object functions
655 @brief Creates a default floating point number value object.
657 The created floating point number value object's initial raw value is 0.
659 @returns Created floating point number value object on success,
662 @postsuccessrefcountret1
664 @sa bt_value_float_create_init(): Creates an initialized floating
665 point number value object.
667 extern struct bt_value
*bt_value_float_create(void);
670 @brief Creates a floating point number value object with its initial raw
673 @param[in] val Initial raw value.
674 @returns Created floating point number value object on
675 success, or \c NULL on error.
677 @postsuccessrefcountret1
679 @sa bt_value_float_create(): Creates a default floating point number
682 extern struct bt_value
*bt_value_float_create_init(double val
);
685 @brief Returns the floating point number raw value of the floating point
686 number value object \p float_obj.
688 @param[in] float_obj Floating point number value object of which to
690 @param[out] val Returned floating point number raw value
691 @returns Status code.
693 @prenotnull{float_obj}
695 @pre \p float_obj is a floating point number value object.
696 @postrefcountsame{float_obj}
698 @sa bt_value_float_set(): Sets the raw value of a given floating
699 point number value object.
701 extern enum bt_value_status
bt_value_float_get(
702 const struct bt_value
*float_obj
, double *val
);
705 @brief Sets the floating point number raw value of the floating point
706 number value object \p float_obj to \p val.
708 @param[in] float_obj Floating point number value object of which to set
710 @param[in] val New floating point number raw value.
711 @returns Status code.
713 @prenotnull{float_obj}
714 @pre \p float_obj is a floating point number value object.
716 @postrefcountsame{float_obj}
718 @sa bt_value_float_get(): Returns the raw value of a floating point
721 extern enum bt_value_status
bt_value_float_set(
722 struct bt_value
*float_obj
, double val
);
727 @name String value object functions
732 @brief Creates a default string value object.
734 The string value object is initially empty.
736 @returns Created string value object on success, or \c NULL
739 @postsuccessrefcountret1
741 @sa bt_value_string_create_init(): Creates an initialized string
744 extern struct bt_value
*bt_value_string_create(void);
747 @brief Creates a string value object with its initial raw value set to
750 On success, \p val is copied.
752 @param[in] val Initial raw value (copied on success).
753 @returns Created string value object on success, or
757 @postsuccessrefcountret1
759 @sa bt_value_float_create(): Creates a default string value object.
761 extern struct bt_value
*bt_value_string_create_init(const char *val
);
764 @brief Returns the string raw value of the string value object
767 The returned string is placed in \p *val. It is valid as long as this
768 value object exists and is \em not modified. The ownership of the
769 returned string is \em not transferred to the caller.
771 @param[in] string_obj String value object of which to get the
773 @param[out] val Returned string raw value.
774 @returns Status code.
776 @prenotnull{string_obj}
778 @pre \p string_obj is a string value object.
779 @postrefcountsame{string_obj}
781 @sa bt_value_string_set(): Sets the raw value of a string
784 extern enum bt_value_status
bt_value_string_get(
785 const struct bt_value
*string_obj
, const char **val
);
788 @brief Sets the string raw value of the string value object
789 \p string_obj to \p val.
791 On success, \p val is copied.
793 @param[in] string_obj String value object of which to set
795 @param[in] val New string raw value (copied on success).
796 @returns Status code.
798 @prenotnull{string_obj}
800 @pre \p string_obj is a string value object.
802 @postrefcountsame{string_obj}
804 @sa bt_value_string_get(): Returns the raw value of a given string
807 extern enum bt_value_status
bt_value_string_set(struct bt_value
*string_obj
,
815 * @name Array value object functions
820 @brief Creates an empty array value object.
822 @returns Created array value object on success, or \c NULL
825 @postsuccessrefcountret1
827 extern struct bt_value
*bt_value_array_create(void);
830 @brief Returns the size of the array value object \p array_obj, that is,
831 the number of value objects contained in \p array_obj.
833 @param[in] array_obj Array value object of which to get the size.
834 @returns Number of value objects contained in
835 \p array_obj if the return value is 0 (empty)
836 or a positive value, or one of
837 #bt_value_status negative values otherwise.
839 @prenotnull{array_obj}
840 @pre \p array_obj is an array value object.
841 @postrefcountsame{array_obj}
843 @sa bt_value_array_is_empty(): Checks whether or not a given array
844 value object is empty.
846 extern int64_t bt_value_array_size(const struct bt_value
*array_obj
);
849 @brief Checks whether or not the array value object \p array_obj
852 @param[in] array_obj Array value object to check.
853 @returns #BT_TRUE if \p array_obj is empty.
855 @prenotnull{array_obj}
856 @pre \p array_obj is an array value object.
857 @postrefcountsame{array_obj}
859 @sa bt_value_array_size(): Returns the size of a given array value
862 extern bt_bool
bt_value_array_is_empty(const struct bt_value
*array_obj
);
865 @brief Returns the value object contained in the array value object
866 \p array_obj at the index \p index.
868 @param[in] array_obj Array value object of which to get an element.
869 @param[in] index Index of value object to get.
870 @returns Value object at index \p index on
871 success, or \c NULL on error.
873 @prenotnull{array_obj}
874 @pre \p array_obj is an array value object.
875 @pre \p index is lesser than the size of \p array_obj (see
876 bt_value_array_size()).
877 @post <strong>On success, if the returned value object is not
878 \ref bt_value_null</strong>, its reference count is incremented.
879 @postrefcountsame{array_obj}
881 extern struct bt_value
*bt_value_array_get(const struct bt_value
*array_obj
,
885 @brief Appends the value object \p element_obj to the array value
888 @param[in] array_obj Array value object in which to append
890 @param[in] element_obj Value object to append.
891 @returns Status code.
893 @prenotnull{array_obj}
894 @prenotnull{element_obj}
895 @pre \p array_obj is an array value object.
897 @post <strong>On success, if \p element_obj is not
898 \ref bt_value_null</strong>, its reference count is incremented.
899 @postrefcountsame{array_obj}
901 @sa bt_value_array_append_bool(): Appends a boolean raw value to a
902 given array value object.
903 @sa bt_value_array_append_integer(): Appends an integer raw value
904 to a given array value object.
905 @sa bt_value_array_append_float(): Appends a floating point number
906 raw value to a given array value object.
907 @sa bt_value_array_append_string(): Appends a string raw value to a
908 given array value object.
909 @sa bt_value_array_append_empty_array(): Appends an empty array value
910 object to a given array value object.
911 @sa bt_value_array_append_empty_map(): Appends an empty map value
912 object to a given array value object.
914 extern enum bt_value_status
bt_value_array_append(struct bt_value
*array_obj
,
915 struct bt_value
*element_obj
);
918 @brief Appends the boolean raw value \p val to the array value object
921 This is a convenience function which creates the underlying boolean
922 value object before appending it.
924 @param[in] array_obj Array value object in which to append \p val.
925 @param[in] val Boolean raw value to append to \p array_obj.
926 @returns Status code.
928 @prenotnull{array_obj}
929 @pre \p array_obj is an array value object.
931 @postrefcountsame{array_obj}
933 @sa bt_value_array_append(): Appends a value object to a given
936 extern enum bt_value_status
bt_value_array_append_bool(
937 struct bt_value
*array_obj
, bt_bool val
);
940 @brief Appends the integer raw value \p val to the array value object
943 This is a convenience function which creates the underlying integer
944 value object before appending it.
946 @param[in] array_obj Array value object in which to append \p val.
947 @param[in] val Integer raw value to append to \p array_obj.
948 @returns Status code.
950 @prenotnull{array_obj}
951 @pre \p array_obj is an array value object.
953 @postrefcountsame{array_obj}
955 @sa bt_value_array_append(): Appends a value object to a given
958 extern enum bt_value_status
bt_value_array_append_integer(
959 struct bt_value
*array_obj
, int64_t val
);
962 @brief Appends the floating point number raw value \p val to the array
963 value object \p array_obj.
965 This is a convenience function which creates the underlying floating
966 point number value object before appending it.
968 @param[in] array_obj Array value object in which to append \p val.
969 @param[in] val Floating point number raw value to append
971 @returns Status code.
973 @prenotnull{array_obj}
974 @pre \p array_obj is an array value object.
976 @postrefcountsame{array_obj}
978 @sa bt_value_array_append(): Appends a value object to a given
981 extern enum bt_value_status
bt_value_array_append_float(
982 struct bt_value
*array_obj
, double val
);
985 @brief Appends the string raw value \p val to the array value object
988 This is a convenience function which creates the underlying string value
989 object before appending it.
991 On success, \p val is copied.
993 @param[in] array_obj Array value object in which to append \p val.
994 @param[in] val String raw value to append to \p array_obj
996 @returns Status code.
998 @prenotnull{array_obj}
999 @pre \p array_obj is an array value object.
1002 @postrefcountsame{array_obj}
1004 @sa bt_value_array_append(): Appends a value object to a given
1007 extern enum bt_value_status
bt_value_array_append_string(
1008 struct bt_value
*array_obj
, const char *val
);
1011 @brief Appends an empty array value object to the array value object
1014 This is a convenience function which creates the underlying array value
1015 object before appending it.
1017 @param[in] array_obj Array value object in which to append an
1018 empty array value object
1019 @returns Status code.
1021 @prenotnull{array_obj}
1022 @pre \p array_obj is an array value object.
1024 @postrefcountsame{array_obj}
1026 @sa bt_value_array_append(): Appends a value object to a given
1029 extern enum bt_value_status
bt_value_array_append_empty_array(
1030 struct bt_value
*array_obj
);
1033 @brief Appends an empty map value object to the array value object
1036 This is a convenience function which creates the underlying map value
1037 object before appending it.
1039 @param[in] array_obj Array value object in which to append an empty
1041 @returns Status code.
1043 @prenotnull{array_obj}
1044 @pre \p array_obj is an array value object.
1046 @postrefcountsame{array_obj}
1048 @sa bt_value_array_append(): Appends a value object to a given
1051 extern enum bt_value_status
bt_value_array_append_empty_map(
1052 struct bt_value
*array_obj
);
1055 @brief Replaces the value object contained in the array value object
1056 \p array_obj at the index \p index by \p element_obj.
1058 @param[in] array_obj Array value object in which to replace
1060 @param[in] index Index of value object to replace in
1062 @param[in] element_obj New value object at position \p index of
1064 @returns Status code.
1066 @prenotnull{array_obj}
1067 @prenotnull{element_obj}
1068 @pre \p array_obj is an array value object.
1069 @pre \p index is lesser than the size of \p array_obj (see
1070 bt_value_array_size()).
1072 @post <strong>On success, if the replaced value object is not
1073 \ref bt_value_null</strong>, its reference count is decremented.
1074 @post <strong>On success, if \p element_obj is not
1075 \ref bt_value_null</strong>, its reference count is incremented.
1076 @postrefcountsame{array_obj}
1078 extern enum bt_value_status
bt_value_array_set(struct bt_value
*array_obj
,
1079 uint64_t index
, struct bt_value
*element_obj
);
1084 @name Map value object functions
1089 @brief Creates an empty map value object.
1091 @returns Created map value object on success, or \c NULL on error.
1093 @postsuccessrefcountret1
1095 extern struct bt_value
*bt_value_map_create(void);
1098 @brief Returns the size of the map value object \p map_obj, that is, the
1099 number of entries contained in \p map_obj.
1101 @param[in] map_obj Map value object of which to get the size.
1102 @returns Number of entries contained in \p map_obj if the
1103 return value is 0 (empty) or a positive value,
1104 or one of #bt_value_status negative values
1107 @prenotnull{map_obj}
1108 @pre \p map_obj is a map value object.
1109 @postrefcountsame{map_obj}
1111 @sa bt_value_map_is_empty(): Checks whether or not a given map value
1114 extern int64_t bt_value_map_size(const struct bt_value
*map_obj
);
1117 @brief Checks whether or not the map value object \p map_obj is empty.
1119 @param[in] map_obj Map value object to check.
1120 @returns #BT_TRUE if \p map_obj is empty.
1122 @prenotnull{map_obj}
1123 @pre \p map_obj is a map value object.
1124 @postrefcountsame{map_obj}
1126 @sa bt_value_map_size(): Returns the size of a given map value object.
1128 extern bt_bool
bt_value_map_is_empty(const struct bt_value
*map_obj
);
1131 @brief Returns the value object associated with the key \p key within
1132 the map value object \p map_obj.
1134 @param[in] map_obj Map value object of which to get an entry.
1135 @param[in] key Key of the value object to get.
1136 @returns Value object associated with the key \p key
1137 on success, or \c NULL on error.
1139 @prenotnull{map_obj}
1141 @pre \p map_obj is a map value object.
1142 @postrefcountsame{map_obj}
1143 @post <strong>On success, if the returned value object is not
1144 \ref bt_value_null</strong>, its reference count is incremented.
1146 extern struct bt_value
*bt_value_map_get(const struct bt_value
*map_obj
,
1150 @brief User function type to use with bt_value_map_foreach().
1152 \p object is a <em>weak reference</em>: you \em must pass it to bt_get()
1153 if you need to keep a reference after this function returns.
1155 This function \em must return #BT_TRUE to continue the map value object
1156 traversal, or #BT_FALSE to break it.
1158 @param[in] key Key of map entry.
1159 @param[in] object Value object of map entry (weak reference).
1160 @param[in] data User data.
1161 @returns #BT_TRUE to continue the loop, or #BT_FALSE to break it.
1165 @post The reference count of \p object is not lesser than what it is
1166 when the function is called.
1168 typedef bt_bool (* bt_value_map_foreach_cb
)(const char *key
,
1169 struct bt_value
*object
, void *data
);
1172 @brief Calls a provided user function \p cb for each value object of the
1173 map value object \p map_obj.
1175 The value object passed to the user function is a <b>weak reference</b>:
1176 you \em must pass it to bt_get() if you need to keep a persistent
1177 reference after the user function returns.
1179 The key passed to the user function is only valid in the scope of
1180 this user function call.
1182 The user function \em must return #BT_TRUE to continue the traversal of
1183 \p map_obj, or #BT_FALSE to break it.
1185 @param[in] map_obj Map value object on which to iterate.
1186 @param[in] cb User function to call back.
1187 @param[in] data User data passed to the user function.
1188 @returns Status code. More
1189 specifically, #BT_VALUE_STATUS_CANCELLED is
1190 returned if the loop was cancelled by the user
1193 @prenotnull{map_obj}
1195 @pre \p map_obj is a map value object.
1196 @postrefcountsame{map_obj}
1198 extern enum bt_value_status
bt_value_map_foreach(
1199 const struct bt_value
*map_obj
, bt_value_map_foreach_cb cb
,
1203 @brief Returns whether or not the map value object \p map_obj contains
1204 an entry mapped to the key \p key.
1206 @param[in] map_obj Map value object to check.
1207 @param[in] key Key to check.
1208 @returns #BT_TRUE if \p map_obj has an entry mapped to the
1209 key \p key, or #BT_FALSE if it does not or
1212 @prenotnull{map_obj}
1214 @pre \p map_obj is a map value object.
1215 @postrefcountsame{map_obj}
1217 extern bt_bool
bt_value_map_has_key(const struct bt_value
*map_obj
,
1221 @brief Inserts the value object \p element_obj mapped to the key
1222 \p key into the map value object \p map_obj.
1224 If a value object is already mapped to \p key in \p map_obj, the
1225 associated value object is first put, and then replaced by
1228 On success, \p key is copied.
1230 @param[in] map_obj Map value object in which to insert
1232 @param[in] key Key (copied on success) to which the
1233 value object to insert is mapped.
1234 @param[in] element_obj Value object to insert, mapped to the
1236 @returns Status code.
1238 @prenotnull{map_obj}
1240 @prenotnull{element_obj}
1241 @pre \p map_obj is a map value object.
1243 @post <strong>On success, if \p element_obj is not
1244 \ref bt_value_null</strong>, its reference count is incremented.
1245 @postrefcountsame{map_obj}
1247 @sa bt_value_map_insert_bool(): Inserts a boolean raw value into a
1248 given map value object.
1249 @sa bt_value_map_insert_integer(): Inserts an integer raw value into
1250 a given map value object.
1251 @sa bt_value_map_insert_float(): Inserts a floating point number raw
1252 value into a given map value object.
1253 @sa bt_value_map_insert_string(): Inserts a string raw value into a
1254 given map value object.
1255 @sa bt_value_map_insert_empty_array(): Inserts an empty array value
1256 object into a given map value object.
1257 @sa bt_value_map_insert_empty_map(): Inserts an empty map value
1258 object into a given map value object.
1260 extern enum bt_value_status
bt_value_map_insert(
1261 struct bt_value
*map_obj
, const char *key
,
1262 struct bt_value
*element_obj
);
1265 @brief Inserts the boolean raw value \p val mapped to the key \p key
1266 into the map value object \p map_obj.
1268 This is a convenience function which creates the underlying boolean
1269 value object before inserting it.
1271 On success, \p key is copied.
1273 @param[in] map_obj Map value object in which to insert \p val.
1274 @param[in] key Key (copied on success) to which the boolean
1275 value object to insert is mapped.
1276 @param[in] val Boolean raw value to insert, mapped to
1278 @returns Status code.
1280 @prenotnull{map_obj}
1282 @pre \p map_obj is a map value object.
1284 @postrefcountsame{map_obj}
1286 @sa bt_value_map_insert(): Inserts a value object into a given map
1289 extern enum bt_value_status
bt_value_map_insert_bool(
1290 struct bt_value
*map_obj
, const char *key
, bt_bool val
);
1293 @brief Inserts the integer raw value \p val mapped to the key \p key
1294 into the map value object \p map_obj.
1296 This is a convenience function which creates the underlying integer
1297 value object before inserting it.
1299 On success, \p key is copied.
1301 @param[in] map_obj Map value object in which to insert \p val.
1302 @param[in] key Key (copied on success) to which the integer
1303 value object to insert is mapped.
1304 @param[in] val Integer raw value to insert, mapped to
1306 @returns Status code.
1308 @prenotnull{map_obj}
1310 @pre \p map_obj is a map value object.
1312 @postrefcountsame{map_obj}
1314 @sa bt_value_map_insert(): Inserts a value object into a given map
1317 extern enum bt_value_status
bt_value_map_insert_integer(
1318 struct bt_value
*map_obj
, const char *key
, int64_t val
);
1321 @brief Inserts the floating point number raw value \p val mapped to
1322 the key \p key into the map value object \p map_obj.
1324 This is a convenience function which creates the underlying floating
1325 point number value object before inserting it.
1327 On success, \p key is copied.
1329 @param[in] map_obj Map value object in which to insert \p val.
1330 @param[in] key Key (copied on success) to which the floating
1331 point number value object to insert is mapped.
1332 @param[in] val Floating point number raw value to insert,
1333 mapped to the key \p key.
1334 @returns Status code.
1336 @prenotnull{map_obj}
1338 @pre \p map_obj is a map value object.
1340 @postrefcountsame{map_obj}
1342 @sa bt_value_map_insert(): Inserts a value object into a given map
1345 extern enum bt_value_status
bt_value_map_insert_float(
1346 struct bt_value
*map_obj
, const char *key
, double val
);
1349 @brief Inserts the string raw value \p val mapped to the key \p key
1350 into the map value object \p map_obj.
1352 This is a convenience function which creates the underlying string value
1353 object before inserting it.
1355 On success, \p val and \p key are copied.
1357 @param[in] map_obj Map value object in which to insert \p val.
1358 @param[in] key Key (copied on success) to which the string
1359 value object to insert is mapped.
1360 @param[in] val String raw value to insert (copied on success),
1361 mapped to the key \p key.
1362 @returns Status code.
1364 @prenotnull{map_obj}
1367 @pre \p map_obj is a map value object.
1369 @postrefcountsame{map_obj}
1371 @sa bt_value_map_insert(): Inserts a value object into a given map
1374 extern enum bt_value_status
bt_value_map_insert_string(
1375 struct bt_value
*map_obj
, const char *key
, const char *val
);
1378 @brief Inserts an empty array value object mapped to the key \p key
1379 into the map value object \p map_obj.
1381 This is a convenience function which creates the underlying array value
1382 object before inserting it.
1384 On success, \p key is copied.
1386 @param[in] map_obj Map value object in which to insert an empty
1388 @param[in] key Key (copied on success) to which the empty array
1389 value object to insert is mapped.
1390 @returns Status code.
1392 @prenotnull{map_obj}
1394 @pre \p map_obj is a map value object.
1396 @postrefcountsame{map_obj}
1398 @sa bt_value_map_insert(): Inserts a value object into a given map
1401 extern enum bt_value_status
bt_value_map_insert_empty_array(
1402 struct bt_value
*map_obj
, const char *key
);
1405 @brief Inserts an empty map value object mapped to the key \p key into
1406 the map value object \p map_obj.
1408 This is a convenience function which creates the underlying map value
1409 object before inserting it.
1411 On success, \p key is copied.
1413 @param[in] map_obj Map value object in which to insert an empty
1415 @param[in] key Key (copied on success) to which the empty map
1416 value object to insert is mapped.
1417 @returns Status code.
1419 @prenotnull{map_obj}
1421 @pre \p map_obj is a map value object.
1423 @postrefcountsame{map_obj}
1425 @sa bt_value_map_insert(): Inserts a value object into a given map
1428 extern enum bt_value_status
bt_value_map_insert_empty_map(
1429 struct bt_value
*map_obj
, const char *key
);
1432 @brief Creates a copy of the base map value object \p base_map_obj
1433 superficially extended with the entries of the extension map
1434 value object \p extension_map_obj.
1436 This function creates a superficial extension of \p base_map_obj with
1437 \p extension_map_obj by adding new entries to it and replacing the
1438 ones that share the keys in the extension object. The extension is
1439 \em superficial because it does not merge internal array and map
1442 For example, consider the following \p base_map_obj (JSON representation):
1449 "return": [5, 6, null]
1453 and the following \p extension_map_obj (JSON representation):
1463 The extended object is (JSON representation):
1475 @param[in] base_map_obj Base map value object with initial
1477 @param[in] extension_map_obj Extension map value object containing
1478 the entries to add to or replace in
1480 @returns Created extended map value object, or
1483 @prenotnull{base_map_obj}
1484 @prenotnull{extension_map_obj}
1485 @pre \p base_map_obj is a map value object.
1486 @pre \p extension_map_obj is a map value object.
1487 @postrefcountsame{base_map_obj}
1488 @postrefcountsame{extension_map_obj}
1489 @postsuccessrefcountret1
1491 extern struct bt_value
*bt_value_map_extend(struct bt_value
*base_map_obj
,
1492 struct bt_value
*extension_map_obj
);
1502 #endif /* BABELTRACE_VALUES_H */