objects: add bt_object_array_set()
[babeltrace.git] / lib / objects.c
index cd86f976d8032b1ae6ade811c41656ff6b99c583..1439b4d48085374e923427a637067491e9a05e99 100644 (file)
@@ -857,6 +857,27 @@ int bt_object_array_append_map(struct bt_object *array_obj)
        return ret;
 }
 
+int bt_object_array_set(struct bt_object *array_obj, size_t index,
+       struct bt_object *element_obj)
+{
+       int ret = 0;
+       struct bt_object_array *typed_array_obj =
+               BT_OBJECT_TO_ARRAY(array_obj);
+
+       if (!array_obj || !bt_object_is_array(array_obj) || !element_obj ||
+                       index >= typed_array_obj->garray->len) {
+               ret = -1;
+               goto end;
+       }
+
+       bt_object_put(g_ptr_array_index(typed_array_obj->garray, index));
+       g_ptr_array_index(typed_array_obj->garray, index) = element_obj;
+       bt_object_get(element_obj);
+
+end:
+       return ret;
+}
+
 int bt_object_map_size(const struct bt_object *map_obj)
 {
        int ret;
This page took 0.023116 seconds and 4 git commands to generate.