From: Jérémie Galarneau Date: Wed, 21 May 2014 16:15:36 +0000 (-0400) Subject: Add bt_ctf_field_type_enumeration private search functions X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=e5958c30b6f602d57bbeaf2ee1fb76c2764daae2;p=deliverable%2Fbabeltrace.git Add bt_ctf_field_type_enumeration private search functions Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 0c8eddc00..7c5047f92 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 27e4a1750..a0a6f9c4c 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 */