tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / trace-ir / field-path.c
index 5cb2a96d70049e85c82910997bcfacb76cf92150..23b65a75c7573455fedd751dcb5fb8b2845c1392 100644 (file)
@@ -1,10 +1,6 @@
 /*
- * field-path.c
- *
- * Babeltrace trace IR - Field path
- *
+ * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  */
 
 #define BT_LOG_TAG "FIELD-PATH"
-#include <babeltrace/lib-logging-internal.h>
+#include <babeltrace2/lib-logging-internal.h>
 
-#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/trace-ir/field-classes.h>
-#include <babeltrace/trace-ir/field-classes-internal.h>
-#include <babeltrace/trace-ir/field-path-internal.h>
-#include <babeltrace/trace-ir/field-path.h>
+#include <babeltrace2/assert-pre-internal.h>
+#include <babeltrace2/trace-ir/field-class.h>
+#include <babeltrace2/trace-ir/field-class-internal.h>
+#include <babeltrace2/trace-ir/field-path-internal.h>
+#include <babeltrace2/trace-ir/field-path-const.h>
 #include <limits.h>
 #include <stdint.h>
 #include <inttypes.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/assert-internal.h>
 #include <glib.h>
 
 static
@@ -46,7 +42,8 @@ void destroy_field_path(struct bt_object *obj)
 
        BT_ASSERT(field_path);
        BT_LIB_LOGD("Destroying field path: %!+P", field_path);
-       g_array_free(field_path->indexes, TRUE);
+       g_array_free(field_path->items, TRUE);
+       field_path->items = NULL;
        g_free(field_path);
 }
 
@@ -64,8 +61,9 @@ struct bt_field_path *bt_field_path_create(void)
        }
 
        bt_object_init_shared(&field_path->base, destroy_field_path);
-       field_path->indexes = g_array_new(FALSE, FALSE, sizeof(uint64_t));
-       if (!field_path->indexes) {
+       field_path->items = g_array_new(FALSE, FALSE,
+               sizeof(struct bt_field_path_item));
+       if (!field_path->items) {
                BT_LOGE_STR("Failed to allocate a GArray.");
                goto error;
        }
@@ -74,28 +72,57 @@ struct bt_field_path *bt_field_path_create(void)
        goto end;
 
 error:
-       BT_PUT(field_path);
+       BT_OBJECT_PUT_REF_AND_RESET(field_path);
 
 end:
        return field_path;
 }
 
-enum bt_scope bt_field_path_get_root_scope(struct bt_field_path *field_path)
+enum bt_scope bt_field_path_get_root_scope(
+               const struct bt_field_path *field_path)
 {
        BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
        return field_path->root;
 }
 
-uint64_t bt_field_path_get_index_count(struct bt_field_path *field_path)
+uint64_t bt_field_path_get_item_count(const struct bt_field_path *field_path)
 {
        BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
-       return (uint64_t) field_path->indexes->len;
+       return (uint64_t) field_path->items->len;
 }
 
-uint64_t bt_field_path_get_index_by_index(struct bt_field_path *field_path,
-               uint64_t index)
+const struct bt_field_path_item *bt_field_path_borrow_item_by_index_const(
+               const struct bt_field_path *field_path, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
-       BT_ASSERT_PRE_VALID_INDEX(index, field_path->indexes->len);
-       return bt_field_path_get_index_by_index_inline(field_path, index);
+       BT_ASSERT_PRE_VALID_INDEX(index, field_path->items->len);
+       return bt_field_path_borrow_item_by_index_inline(field_path, index);
+}
+
+enum bt_field_path_item_type bt_field_path_item_get_type(
+               const struct bt_field_path_item *field_path_item)
+{
+       BT_ASSERT_PRE_NON_NULL(field_path_item, "Field path item");
+       return field_path_item->type;
+}
+
+uint64_t bt_field_path_item_index_get_index(
+               const struct bt_field_path_item *field_path_item)
+{
+       BT_ASSERT_PRE_NON_NULL(field_path_item, "Field path item");
+       BT_ASSERT_PRE(field_path_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX,
+               "Field path item is not an index field path item: "
+               "addr=%p, type=%s", field_path_item,
+               bt_field_path_item_type_string(field_path_item->type));
+       return  field_path_item->index;
+}
+
+void bt_field_path_get_ref(const struct bt_field_path *field_path)
+{
+       bt_object_get_ref(field_path);
+}
+
+void bt_field_path_put_ref(const struct bt_field_path *field_path)
+{
+       bt_object_put_ref(field_path);
 }
This page took 0.025237 seconds and 4 git commands to generate.