From e5958c30b6f602d57bbeaf2ee1fb76c2764daae2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 21 May 2014 12:15:36 -0400 Subject: [PATCH] Add bt_ctf_field_type_enumeration private search functions 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 | 45 +++++++++++++++++++ .../babeltrace/ctf-ir/event-types-internal.h | 10 +++++ 2 files changed, 55 insertions(+) diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 0c8eddc0..7c5047f9 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -436,6 +436,51 @@ end: return ret; } +const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( + struct bt_ctf_field_type_enumeration *enumeration_type, + uint64_t value) +{ + const char *name = NULL; + struct range_overlap_query query = + (struct range_overlap_query) { + /* FIXME: should not need a cast */ + .range_start = (int64_t) value, + .range_end = (int64_t) value, + .overlaps = 0 }; + + g_ptr_array_foreach(enumeration_type->entries, check_ranges_overlap, + &query); + if (!query.overlaps) { + goto end; + } + + name = g_quark_to_string(query.mapping_name); +end: + return name; +} + +const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( + struct bt_ctf_field_type_enumeration *enumeration_type, + int64_t value) +{ + const char *name = NULL; + struct range_overlap_query query = + (struct range_overlap_query) { + .range_start = value, + .range_end = value, + .overlaps = 0 }; + + g_ptr_array_foreach(enumeration_type->entries, check_ranges_overlap, + &query); + if (!query.overlaps) { + goto end; + } + + name = g_quark_to_string(query.mapping_name); +end: + return name; +} + struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void) { struct bt_ctf_field_type_floating_point *floating_point = diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index 27e4a175..a0a6f9c4 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -150,4 +150,14 @@ int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, BT_HIDDEN int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); +BT_HIDDEN +const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( + struct bt_ctf_field_type_enumeration *enumeration_type, + uint64_t value); + +BT_HIDDEN +const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( + struct bt_ctf_field_type_enumeration *enumeration_type, + int64_t value); + #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */ -- 2.34.1