From 736133f1ae231a5bf12d45be43066d6825450efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 11 May 2015 17:22:27 -0400 Subject: [PATCH] ir: add bt_ctf_field_type_variant_get_field_name_index() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-types.c | 33 +++++++++++++++++++ .../babeltrace/ctf-ir/event-types-internal.h | 4 +++ 2 files changed, 37 insertions(+) diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 195f935d..9b78c0db 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -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) { diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index a5057e20..8ae102b0 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -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 */ -- 2.34.1