ir: add bt_ctf_field_type_variant_get_field_name_index()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 11 May 2015 21:22:27 +0000 (17:22 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 11 May 2015 21:22:27 +0000 (17:22 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c
include/babeltrace/ctf-ir/event-types-internal.h

index 195f935d521a11f86ed58dd2aecb6c03b985f957..9b78c0dbfd5b43f02b0ad9184c5b7337ba26897e 100644 (file)
@@ -1988,6 +1988,39 @@ int bt_ctf_field_type_structure_get_field_name_index(
 end:
        return ret;
 }
+
+BT_HIDDEN
+int bt_ctf_field_type_variant_get_field_name_index(
+               struct bt_ctf_field_type *type, const char *name)
+{
+       int ret;
+       size_t index;
+       GQuark name_quark;
+       struct bt_ctf_field_type_variant *variant;
+
+       if (!type || !name ||
+               bt_ctf_field_type_get_type_id(type) != CTF_TYPE_VARIANT) {
+               ret = -1;
+               goto end;
+       }
+
+       name_quark = g_quark_try_string(name);
+       if (!name_quark) {
+               ret = -1;
+               goto end;
+       }
+
+       variant = container_of(type, struct bt_ctf_field_type_variant,
+               parent);
+       if (!g_hash_table_lookup_extended(variant->field_name_to_index,
+               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+               ret = -1;
+               goto end;
+       }
+       ret = (int) index;
+end:
+       return ret;
+}
 static
 void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
 {
index a5057e207b5cab8583781814389e0156f0a0407d..8ae102b041e30c2b13936954603045bd717882f3 100644 (file)
@@ -169,4 +169,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_copy(
 BT_HIDDEN
 int bt_ctf_field_type_structure_get_field_name_index(
                struct bt_ctf_field_type *structure, const char *name);
+
+BT_HIDDEN
+int bt_ctf_field_type_variant_get_field_name_index(
+               struct bt_ctf_field_type *variant, const char *name);
 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */
This page took 0.027155 seconds and 4 git commands to generate.