1 #ifndef _BABELTRACE_OBJECTS_H
2 #define _BABELTRACE_OBJECTS_H
9 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
10 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * @brief Basic object system
35 * This is a basic object system API. The following functions allow you
36 * to create, modify, and destroy:
38 * - \link bt_object_null null objects\endlink
39 * - \link bt_object_bool_create() boolean objects\endlink
40 * - \link bt_object_integer_create() integer objects\endlink
41 * - \link bt_object_float_create() floating point number
43 * - \link bt_object_string_create() string objects\endlink
44 * - \link bt_object_array_create() array objects\endlink,
45 * containing zero or more objects
46 * - \link bt_object_map_create() map objects\endlink, mapping
47 * string keys to objects
49 * All the object types above, except for null objects (which always
50 * point to the same \link bt_object_null singleton\endlink), have a
51 * reference count property. Once an object is created, its reference
52 * count is set to 1. When \link bt_object_array_append() appending an
53 * object to an array object\endlink, or \link bt_object_map_insert()
54 * inserting an object into a map object\endlink, its reference count
55 * is incremented, as well as when getting an object back from those
56 * structures. The bt_object_get() and bt_object_put() functions exist
57 * to deal with reference counting. Once you are done with an object,
58 * pass it to bt_object_put().
60 * A common action with objects is to create or get one, do something
61 * with it, and then put it. To avoid putting it a second time later
62 * (if an error occurs, for example), the variable is often reset to
63 * \c NULL after putting the object it points to. Since this is so
64 * common, you can use the BT_OBJECT_PUT() macro, which does just that:
67 * struct bt_object *int_obj = bt_object_integer_create_init(34);
73 * // stuff, which could jump to error
75 * BT_OBJECT_PUT(int_obj);
77 * // stuff, which could jump to error
82 * // safe, even if int_obj is NULL
83 * BT_OBJECT_PUT(int_obj);
88 * Another common manipulation is to move the ownership of an object
89 * from one variable to another: since the reference count is not
90 * incremented, and since, to avoid errors, two variables should not
91 * point to same object without each of them having their own reference,
92 * it is best practice to set the original variable to \c NULL. This
93 * too can be accomplished in a single step using the BT_OBJECT_MOVE()
97 * struct bt_object *int_obj2 = NULL;
98 * struct bt_object *int_obj = bt_object_integer_create_init(-23);
104 * // stuff, which could jump to error
106 * BT_OBJECT_MOVE(int_obj2, int_obj);
108 * // stuff, which could jump to error
113 * // safe, since only one of int_obj/int_obj2 (or none)
114 * // points to the object
115 * BT_OBJECT_PUT(int_obj);
116 * BT_OBJECT_PUT(int_obj2);
121 * Most functions return a status code, one of the values in
124 * You can create a deep copy of any object using the bt_object_copy()
125 * function. You can compare two given objects using
126 * bt_object_compare().
128 * Any object may be frozen using bt_object_freeze(). You may get the
129 * value of a frozen object, but you cannot modify it. Reference
130 * counting still works on frozen objects. You may also copy and compare
133 * @author Philippe Proulx <pproulx@efficios.com>
148 enum bt_object_type
{
149 /** Unknown object, used as an error code. */
150 BT_OBJECT_TYPE_UNKNOWN
= -1,
153 BT_OBJECT_TYPE_NULL
= 0,
155 /** Boolean object (holds \c true or \c false). */
156 BT_OBJECT_TYPE_BOOL
= 1,
158 /** Integer (holds a signed 64-bit integer value). */
159 BT_OBJECT_TYPE_INTEGER
= 2,
162 * Floating point number object (holds a \c double value).
164 BT_OBJECT_TYPE_FLOAT
= 3,
166 /** String object. */
167 BT_OBJECT_TYPE_STRING
= 4,
170 BT_OBJECT_TYPE_ARRAY
= 5,
173 BT_OBJECT_TYPE_MAP
= 6,
179 enum bt_object_status
{
180 /** Object cannot be altered because it's frozen. */
181 BT_OBJECT_STATUS_FROZEN
= -4,
183 /** Operation cancelled. */
184 BT_OBJECT_STATUS_CANCELLED
= -3,
186 /** Invalid arguments. */
187 /* -22 for compatibility with -EINVAL */
188 BT_OBJECT_STATUS_INVAL
= -22,
190 /** General error. */
191 BT_OBJECT_STATUS_ERROR
= -1,
193 /** Okay, no error. */
194 BT_OBJECT_STATUS_OK
= 0,
203 * The null object singleton.
205 * Use this everytime you need a null object.
207 * The null object singleton has no reference count; there's only one.
208 * You may directly compare any object to the null object singleton to
209 * find out if it's a null object, or otherwise use bt_object_is_null().
211 * The null object singleton is always frozen (see bt_object_freeze()
212 * and bt_object_is_frozen()).
214 * Functions of this API return this when the object is actually a
215 * null object (of type #BT_OBJECT_TYPE_NULL), whereas \c NULL means an
216 * error of some sort.
218 extern struct bt_object
*bt_object_null
;
221 * User function type for bt_object_map_foreach().
223 * \p object is a \em weak reference; you must pass it to
224 * bt_object_get() to get your own reference.
226 * Return \c true to continue the loop, or \c false to break it.
228 * @param key Key of map entry
229 * @param object Object of map entry (weak reference)
230 * @param data User data
231 * @returns \c true to continue the loop
233 typedef bool (* bt_object_map_foreach_cb
)(const char *key
,
234 struct bt_object
*object
, void *data
);
237 * Puts the object \p _object (calls bt_object_put() on it), and resets
238 * the variable to \c NULL.
240 * This is something that is often done when putting and object;
241 * resetting the variable to \c NULL makes sure it cannot be put a
244 * @param _object Object to put
246 * @see BT_OBJECT_MOVE() (moves an object from one variable to the other
247 * without putting it)
249 #define BT_OBJECT_PUT(_object) \
251 bt_object_put(_object); \
256 * Moves the object referenced by the variable \p _src_object to the
257 * \p _dst_object variable, then resets \p _src_object to \c NULL.
259 * The object's reference count is <b>not changed</b>. Resetting
260 * \p _src_object to \c NULL ensures the object will not be put
261 * twice later; its ownership is indeed \em moved from the source
262 * variable to the destination variable.
264 * @param _src_object Source object variable
265 * @param _dst_object Destination object variable
267 #define BT_OBJECT_MOVE(_dst_object, _src_object) \
269 (_dst_object) = (_src_object); \
270 (_src_object) = NULL; \
274 * Increments the reference count of \p object.
276 * @param object Object of which to increment the reference count
278 extern void bt_object_get(struct bt_object
*object
);
281 * Decrements the reference count of \p object, destroying it when this
284 * @param object Object of which to decrement the reference count
286 * @see BT_OBJECT_PUT() (puts an object and resets the variable to
289 extern void bt_object_put(struct bt_object
*object
);
292 * Recursively freezes the object \p object.
294 * A frozen object cannot be modified; it is considered immutable.
295 * Reference counting still works on a frozen object though: you may
296 * pass a frozen object to bt_object_get() and bt_object_put().
298 * @param object Object to freeze
299 * @returns One of #bt_object_status values; if \p object
300 * is already frozen, though, #BT_OBJECT_STATUS_OK
301 * is returned anyway (i.e. this function never
302 * returns #BT_OBJECT_STATUS_FROZEN)
304 extern enum bt_object_status
bt_object_freeze(struct bt_object
*object
);
307 * Checks whether \p object is frozen or not.
309 * @param object Object to check
310 * @returns \c true if \p object is frozen
312 extern bool bt_object_is_frozen(const struct bt_object
*object
);
315 * Returns the type of \p object.
317 * @param object Object of which to get the type
318 * @returns Object's type, or #BT_OBJECT_TYPE_UNKNOWN
321 * @see #bt_object_type (object types)
323 extern enum bt_object_type
bt_object_get_type(const struct bt_object
*object
);
326 * Checks whether \p object is a null object. The only valid null
327 * object is \ref bt_object_null.
329 * @param object Object to check
330 * @returns \c true if \p object is a null object
333 bool bt_object_is_null(const struct bt_object
*object
)
335 return bt_object_get_type(object
) == BT_OBJECT_TYPE_NULL
;
339 * Checks whether \p object is a boolean object.
341 * @param object Object to check
342 * @returns \c true if \p object is a boolean object
345 bool bt_object_is_bool(const struct bt_object
*object
)
347 return bt_object_get_type(object
) == BT_OBJECT_TYPE_BOOL
;
351 * Checks whether \p object is an integer object.
353 * @param object Object to check
354 * @returns \c true if \p object is an integer object
357 bool bt_object_is_integer(const struct bt_object
*object
)
359 return bt_object_get_type(object
) == BT_OBJECT_TYPE_INTEGER
;
363 * Checks whether \p object is a floating point number object.
365 * @param object Object to check
366 * @returns \c true if \p object is a floating point number object
369 bool bt_object_is_float(const struct bt_object
*object
)
371 return bt_object_get_type(object
) == BT_OBJECT_TYPE_FLOAT
;
375 * Checks whether \p object is a string object.
377 * @param object Object to check
378 * @returns \c true if \p object is a string object
381 bool bt_object_is_string(const struct bt_object
*object
)
383 return bt_object_get_type(object
) == BT_OBJECT_TYPE_STRING
;
387 * Checks whether \p object is an array object.
389 * @param object Object to check
390 * @returns \c true if \p object is an array object
393 bool bt_object_is_array(const struct bt_object
*object
)
395 return bt_object_get_type(object
) == BT_OBJECT_TYPE_ARRAY
;
399 * Checks whether \p object is a map object.
401 * @param object Object to check
402 * @returns \c true if \p object is a map object
405 bool bt_object_is_map(const struct bt_object
*object
)
407 return bt_object_get_type(object
) == BT_OBJECT_TYPE_MAP
;
411 * Creates a boolean object. The created boolean object's initial value
414 * The created object's reference count is set to 1.
416 * @returns Created object on success, or \c NULL on error
418 extern struct bt_object
*bt_object_bool_create(void);
421 * Creates a boolean object with its initial value set to \p val.
423 * The created object's reference count is set to 1.
425 * @param val Initial value
426 * @returns Created object on success, or \c NULL on error
428 extern struct bt_object
*bt_object_bool_create_init(bool val
);
431 * Creates an integer object. The created integer object's initial value
434 * The created object's reference count is set to 1.
436 * @returns Created object on success, or \c NULL on error
438 extern struct bt_object
*bt_object_integer_create(void);
441 * Creates an integer object with its initial value set to \p val.
443 * The created object's reference count is set to 1.
445 * @param val Initial value
446 * @returns Created object on success, or \c NULL on error
448 extern struct bt_object
*bt_object_integer_create_init(int64_t val
);
451 * Creates a floating point number object. The created floating point
452 * number object's initial value is 0.
454 * The created object's reference count is set to 1.
456 * @returns Created object on success, or \c NULL on error
458 extern struct bt_object
*bt_object_float_create(void);
461 * Creates a floating point number object with its initial value set
464 * The created object's reference count is set to 1.
466 * @param val Initial value
467 * @returns Created object on success, or \c NULL on error
469 extern struct bt_object
*bt_object_float_create_init(double val
);
472 * Creates a string object. The string object is initially empty.
474 * The created object's reference count is set to 1.
476 * @returns Created object on success, or \c NULL on error
478 extern struct bt_object
*bt_object_string_create(void);
481 * Creates a string object with its initial value set to \p val.
485 * The created object's reference count is set to 1.
487 * @param val Initial value (will be copied)
488 * @returns Created object on success, or \c NULL on error
490 extern struct bt_object
*bt_object_string_create_init(const char *val
);
493 * Creates an empty array object.
495 * The created object's reference count is set to 1.
497 * @returns Created object on success, or \c NULL on error
499 extern struct bt_object
*bt_object_array_create(void);
502 * Creates an empty map object.
504 * The created object's reference count is set to 1.
506 * @returns Created object on success, or \c NULL on error
508 extern struct bt_object
*bt_object_map_create(void);
511 * Gets the boolean value of the boolean object \p bool_obj.
513 * @param bool_obj Boolean object
514 * @param val Returned boolean value
515 * @returns One of #bt_object_status values
517 extern enum bt_object_status
bt_object_bool_get(
518 const struct bt_object
*bool_obj
, bool *val
);
521 * Sets the boolean value of the boolean object \p bool_obj to \p val.
523 * @param bool_obj Boolean object
524 * @param val New boolean value
525 * @returns One of #bt_object_status values
527 extern enum bt_object_status
bt_object_bool_set(struct bt_object
*bool_obj
,
531 * Gets the integer value of the integer object \p integer_obj.
533 * @param integer_obj Integer object
534 * @param val Returned integer value
535 * @returns One of #bt_object_status values
537 extern enum bt_object_status
bt_object_integer_get(
538 const struct bt_object
*integer_obj
, int64_t *val
);
541 * Sets the integer value of the integer object \p integer_obj to
544 * @param integer_obj Integer object
545 * @param val New integer value
546 * @returns One of #bt_object_status values
548 extern enum bt_object_status
bt_object_integer_set(
549 struct bt_object
*integer_obj
, int64_t val
);
552 * Gets the floating point number value of the floating point number
553 * object \p float_obj.
555 * @param float_obj Floating point number object
556 * @param val Returned floating point number value
557 * @returns One of #bt_object_status values
559 extern enum bt_object_status
bt_object_float_get(
560 const struct bt_object
*float_obj
, double *val
);
563 * Sets the floating point number value of the floating point number
564 * object \p float_obj to \p val.
566 * @param float_obj Floating point number object
567 * @param val New floating point number value
568 * @returns One of #bt_object_status values
570 extern enum bt_object_status
bt_object_float_set(
571 struct bt_object
*float_obj
, double val
);
574 * Gets the string value of the string object \p string_obj. The
575 * returned string is valid as long as this object exists and is not
576 * modified. The ownership of the returned string is \em not
577 * transferred to the caller.
579 * @param string_obj String object
580 * @param val Returned string value
581 * @returns One of #bt_object_status values
583 extern enum bt_object_status
bt_object_string_get(
584 const struct bt_object
*string_obj
, const char **val
);
587 * Sets the string value of the string object \p string_obj to
592 * @param string_obj String object
593 * @param val New string value (copied)
594 * @returns One of #bt_object_status values
596 extern enum bt_object_status
bt_object_string_set(struct bt_object
*string_obj
,
600 * Gets the size of the array object \p array_obj, that is, the number
601 * of elements contained in \p array_obj.
603 * @param array_obj Array object
604 * @returns Array size if the return value is 0 (empty) or a
605 * positive value, or one of
606 * #bt_object_status negative values otherwise
608 extern int bt_object_array_size(const struct bt_object
*array_obj
);
611 * Returns \c true if the array object \p array_obj.
613 * @param array_obj Array object
614 * @returns \c true if \p array_obj is empty
616 extern bool bt_object_array_is_empty(const struct bt_object
*array_obj
);
619 * Gets the element object of the array object \p array_obj at the
622 * The returned object's reference count is incremented, unless it's
625 * @param array_obj Array object
626 * @param index Index of element to get
627 * @returns Element object at index \p index on success,
628 * or \c NULL on error
630 extern struct bt_object
*bt_object_array_get(const struct bt_object
*array_obj
,
634 * Appends the element object \p element_obj to the array object
637 * The appended object's reference count is incremented, unless it's
640 * @param array_obj Array object
641 * @param element_obj Element object to append
642 * @returns One of #bt_object_status values
644 extern enum bt_object_status
bt_object_array_append(struct bt_object
*array_obj
,
645 struct bt_object
*element_obj
);
648 * Appends the boolean value \p val to the array object \p array_obj.
649 * This is a convenience function which creates the underlying boolean
650 * object before appending it.
652 * The created boolean object's reference count is set to 1.
654 * @param array_obj Array object
655 * @param val Boolean value to append
656 * @returns One of #bt_object_status values
658 extern enum bt_object_status
bt_object_array_append_bool(
659 struct bt_object
*array_obj
, bool val
);
662 * Appends the integer value \p val to the array object \p array_obj.
663 * This is a convenience function which creates the underlying integer
664 * object before appending it.
666 * The created integer object's reference count is set to 1.
668 * @param array_obj Array object
669 * @param val Integer value to append
670 * @returns One of #bt_object_status values
672 extern enum bt_object_status
bt_object_array_append_integer(
673 struct bt_object
*array_obj
, int64_t val
);
676 * Appends the floating point number value \p val to the array object
677 * \p array_obj. This is a convenience function which creates the
678 * underlying floating point number object before appending it.
680 * The created floating point number object's reference count is
683 * @param array_obj Array object
684 * @param val Floating point number value to append
685 * @returns One of #bt_object_status values
687 extern enum bt_object_status
bt_object_array_append_float(
688 struct bt_object
*array_obj
, double val
);
691 * Appends the string value \p val to the array object \p array_obj.
692 * This is a convenience function which creates the underlying string
693 * object before appending it.
697 * The created string object's reference count is set to 1.
699 * @param array_obj Array object
700 * @param val String value to append (copied)
701 * @returns One of #bt_object_status values
703 extern enum bt_object_status
bt_object_array_append_string(
704 struct bt_object
*array_obj
, const char *val
);
707 * Appends an empty array object to the array object \p array_obj.
708 * This is a convenience function which creates the underlying array
709 * object before appending it.
711 * The created array object's reference count is set to 1.
713 * @param array_obj Array object
714 * @returns One of #bt_object_status values
716 extern enum bt_object_status
bt_object_array_append_array(
717 struct bt_object
*array_obj
);
720 * Appends an empty map object to the array object \p array_obj. This
721 * is a convenience function which creates the underlying map object
722 * before appending it.
724 * The created map object's reference count is set to 1.
726 * @param array_obj Array object
727 * @returns One of #bt_object_status values
729 extern enum bt_object_status
bt_object_array_append_map(
730 struct bt_object
*array_obj
);
733 * Replaces the element object at index \p index of the array object
734 * \p array_obj by \p element_obj.
736 * The replaced object's reference count is decremented, unless it's
737 * a null object. The reference count of \p element_obj is incremented,
738 * unless it's a null object.
740 * @param array_obj Array object
741 * @param index Index of element object to replace
742 * @param element_obj New element object at position \p index of
744 * @returns One of #bt_object_status values
746 extern enum bt_object_status
bt_object_array_set(struct bt_object
*array_obj
,
747 size_t index
, struct bt_object
*element_obj
);
750 * Gets the size of a map object, that is, the number of elements
751 * contained in a map object.
753 * @param map_obj Map object
754 * @returns Map size if the return value is 0 (empty) or a
755 * positive value, or one of
756 * #bt_object_status negative values otherwise
758 extern int bt_object_map_size(const struct bt_object
*map_obj
);
761 * Returns \c true if the map object \p map_obj.
763 * @param map_obj Map object
764 * @returns \c true if \p map_obj is empty
766 extern bool bt_object_map_is_empty(const struct bt_object
*map_obj
);
769 * Gets the element object associated with the key \p key within the
770 * map object \p map_obj.
772 * The returned object's reference count is incremented, unless it's
775 * @param map_obj Map object
776 * @param key Key of the element to get
777 * @returns Element object associated with the key \p key
778 * on success, or \c NULL on error
780 extern struct bt_object
*bt_object_map_get(const struct bt_object
*map_obj
,
784 * Calls a provided user function \p cb for each element of the map
787 * The object passed to the user function is a <b>weak reference</b>:
788 * you must call bt_object_get() on it to obtain your own reference.
790 * The key passed to the user function is only valid in the scope of
791 * this user function.
793 * The user function must return \c true to continue the loop, or
794 * \c false to break it.
796 * @param map_obj Map object
797 * @param cb User function to call back
798 * @param data User data passed to the user function
799 * @returns One of #bt_object_status values; more
800 * specifically, #BT_OBJECT_STATUS_CANCELLED is
801 * returned if the loop was cancelled by the user
804 extern enum bt_object_status
bt_object_map_foreach(
805 const struct bt_object
*map_obj
, bt_object_map_foreach_cb cb
,
809 * Returns whether or not the map object \p map_obj contains the
812 * @param map_obj Map object
813 * @param key Key to check
814 * @returns \c true if \p map_obj contains the key \p key,
815 * or \c false if it doesn't have \p key or
818 extern bool bt_object_map_has_key(const struct bt_object
*map_obj
,
822 * Inserts the element object \p element_obj associated with the key
823 * \p key into the map object \p map_obj. If \p key exists in
824 * \p map_obj, the associated element object is first put, and then
825 * replaced by \p element_obj.
829 * The inserted object's reference count is incremented, unless it's
832 * @param map_obj Map object
833 * @param key Key (copied) of object to insert
834 * @param element_obj Element object to insert, associated with the
836 * @returns One of #bt_object_status values
838 extern enum bt_object_status
bt_object_map_insert(
839 struct bt_object
*map_obj
, const char *key
,
840 struct bt_object
*element_obj
);
843 * Inserts the boolean value \p val associated with the key \p key into
844 * the map object \p map_obj. This is a convenience function which
845 * creates the underlying boolean object before inserting it.
849 * The created boolean object's reference count is set to 1.
851 * @param map_obj Map object
852 * @param key Key (copied) of boolean value to insert
853 * @param val Boolean value to insert, associated with the
855 * @returns One of #bt_object_status values
857 extern enum bt_object_status
bt_object_map_insert_bool(
858 struct bt_object
*map_obj
, const char *key
, bool val
);
861 * Inserts the integer value \p val associated with the key \p key into
862 * the map object \p map_obj. This is a convenience function which
863 * creates the underlying integer object before inserting it.
867 * The created integer object's reference count is set to 1.
869 * @param map_obj Map object
870 * @param key Key (copied) of integer value to insert
871 * @param val Integer value to insert, associated with the
873 * @returns One of #bt_object_status values
875 extern enum bt_object_status
bt_object_map_insert_integer(
876 struct bt_object
*map_obj
, const char *key
, int64_t val
);
879 * Inserts the floating point number value \p val associated with the
880 * key \p key into the map object \p map_obj. This is a convenience
881 * function which creates the underlying floating point number object
882 * before inserting it.
886 * The created floating point number object's reference count is
889 * @param map_obj Map object
890 * @param key Key (copied) of floating point number value to
892 * @param val Floating point number value to insert,
893 * associated with the key \p key
894 * @returns One of #bt_object_status values
896 extern enum bt_object_status
bt_object_map_insert_float(
897 struct bt_object
*map_obj
, const char *key
, double val
);
900 * Inserts the string value \p val associated with the key \p key into
901 * the map object \p map_obj. This is a convenience function which
902 * creates the underlying string object before inserting it.
904 * \p val and \p key are copied.
906 * The created string object's reference count is set to 1.
908 * @param map_obj Map object
909 * @param key Key (copied) of string value to insert
910 * @param val String value to insert, associated with the
912 * @returns One of #bt_object_status values
914 extern enum bt_object_status
bt_object_map_insert_string(
915 struct bt_object
*map_obj
, const char *key
, const char *val
);
918 * Inserts an empty array object associated with the key \p key into
919 * the map object \p map_obj. This is a convenience function which
920 * creates the underlying array object before inserting it.
924 * The created array object's reference count is set to 1.
926 * @param map_obj Map object
927 * @param key Key (copied) of empty array to insert
928 * @returns One of #bt_object_status values
930 extern enum bt_object_status
bt_object_map_insert_array(
931 struct bt_object
*map_obj
, const char *key
);
934 * Inserts an empty map object associated with the key \p key into
935 * the map object \p map_obj. This is a convenience function which
936 * creates the underlying map object before inserting it.
940 * The created map object's reference count is set to 1.
942 * @param map_obj Map object
943 * @param key Key (copied) of empty map to insert
944 * @returns One of #bt_object_status values
946 extern enum bt_object_status
bt_object_map_insert_map(
947 struct bt_object
*map_obj
, const char *key
);
950 * Creates a deep copy of the object \p object.
952 * The created object's reference count is set to 1, unless
953 * \p object is a null object.
955 * @param object Object to copy
956 * @returns Deep copy of \p object on success, or \c NULL
959 extern struct bt_object
*bt_object_copy(const struct bt_object
*object
);
962 * Compares the objects \p object_a and \p object_b and returns \c true
963 * if they have the same content.
965 * @param object_a Object A
966 * @param object_B Object B
967 * @returns \c true if \p object_a and \p object_b have the
968 * same content, or \c false if they differ or on
971 extern bool bt_object_compare(const struct bt_object
*object_a
,
972 const struct bt_object
*object_b
);
978 #endif /* _BABELTRACE_OBJECTS_H */