+ integer->mapped_clock = bt_get(clock_class);
+end:
+ return ret;
+}
+
+static
+void bt_ctf_field_type_enum_iter_destroy(struct bt_object *obj)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter =
+ container_of(obj,
+ struct bt_ctf_field_type_enumeration_mapping_iterator,
+ base);
+
+ bt_put(&iter->enumeration_type->parent);
+ g_free(iter);
+}
+
+static
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_type_enumeration_find_mappings_type(
+ struct bt_ctf_field_type *type,
+ enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type)
+{
+ struct bt_ctf_field_type_enumeration *enumeration_type;
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
+
+ if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
+ goto end;
+ }
+
+ enumeration_type = container_of(type,
+ struct bt_ctf_field_type_enumeration, parent);
+ iter = g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator, 1);
+ if (!iter) {
+ goto end;
+ }
+
+ bt_object_init(&iter->base, bt_ctf_field_type_enum_iter_destroy);
+ bt_get(type);
+ iter->enumeration_type = enumeration_type;
+ iter->index = -1;
+ iter->type = iterator_type;
+end:
+ return iter;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_type_enumeration_find_mappings_by_name(
+ struct bt_ctf_field_type *type, const char *name)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_type(
+ type, ITERATOR_BY_NAME);
+ if (!iter) {
+ goto error;
+ }
+
+ iter->u.name_quark = g_quark_try_string(name);
+ if (!iter->u.name_quark) {
+ goto error;
+ }
+
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+
+ return iter;
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_next(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter)
+{
+ struct bt_ctf_field_type_enumeration *enumeration;
+ struct bt_ctf_field_type *type;
+ int i, ret = 0, len;
+
+ enumeration = iter->enumeration_type;
+ type = &enumeration->parent;
+ len = enumeration->entries->len;
+ for (i = iter->index + 1; i < len; i++) {
+ struct enumeration_mapping *mapping =
+ get_enumeration_mapping(type, i);
+
+ switch (iter->type) {
+ case ITERATOR_BY_NAME:
+ if (mapping->string == iter->u.name_quark) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ case ITERATOR_BY_SIGNED_VALUE:
+ {
+ int64_t value = iter->u.signed_value;
+
+ if (value >= mapping->range_start._signed &&
+ value <= mapping->range_end._signed) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ }
+ case ITERATOR_BY_UNSIGNED_VALUE:
+ {
+ uint64_t value = iter->u.unsigned_value;
+
+ if (value >= mapping->range_start._unsigned &&
+ value <= mapping->range_end._unsigned) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ }
+ default:
+ abort();
+ }
+ }
+
+ ret = -1;
+end:
+ return ret;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
+ struct bt_ctf_field_type *type, int64_t value)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_type(
+ type, ITERATOR_BY_SIGNED_VALUE);
+ if (!iter) {
+ goto error;
+ }
+
+ if (bt_ctf_field_type_integer_get_signed(
+ iter->enumeration_type->container) != 1) {
+ goto error;
+ }
+ iter->u.signed_value = value;
+
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+
+ return iter;
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
+ struct bt_ctf_field_type *type, uint64_t value)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_type(
+ type, ITERATOR_BY_UNSIGNED_VALUE);
+ if (!iter) {
+ goto error;
+ }
+
+ if (bt_ctf_field_type_integer_get_signed(
+ iter->enumeration_type->container) != 0) {
+ goto error;
+ }
+ iter->u.unsigned_value = value;
+
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+
+ return iter;
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_name(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name)
+{
+ int ret = 0;
+
+ if (!iter) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_enumeration_get_mapping_name(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name);
+end:
+ return ret;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name, int64_t *range_begin,
+ int64_t *range_end)
+{
+ int ret = 0;
+
+ if (!iter) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_enumeration_get_mapping_signed(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name, range_begin, range_end);
+end:
+ return ret;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name, uint64_t *range_begin,
+ uint64_t *range_end)
+{
+ int ret = 0;
+
+ if (!iter) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_enumeration_get_mapping_unsigned(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name, range_begin, range_end);
+end:
+ return ret;
+}
+
+int bt_ctf_field_type_enumeration_get_mapping_signed(
+ struct bt_ctf_field_type *enum_field_type,
+ int index,
+ const char **mapping_name, int64_t *range_begin,
+ int64_t *range_end)
+{
+ int ret = 0;
+ struct enumeration_mapping *mapping;
+
+ if (!enum_field_type || index < 0) {
+ ret = -1;
+ goto end;
+ }
+
+ mapping = get_enumeration_mapping(enum_field_type, index);
+ if (!mapping) {
+ ret = -1;
+ goto end;
+ }
+
+ if (mapping_name) {
+ *mapping_name = g_quark_to_string(mapping->string);
+ }
+
+ if (range_begin) {
+ *range_begin = mapping->range_start._signed;
+ }
+
+ if (range_end) {
+ *range_end = mapping->range_end._signed;
+ }
+end:
+ return ret;
+}
+
+int bt_ctf_field_type_enumeration_get_mapping_unsigned(
+ struct bt_ctf_field_type *enum_field_type,
+ int index,
+ const char **mapping_name, uint64_t *range_begin,
+ uint64_t *range_end)
+{
+ int ret = 0;
+ struct enumeration_mapping *mapping;
+
+ if (!enum_field_type || index < 0) {
+ ret = -1;
+ goto end;
+ }
+
+ mapping = get_enumeration_mapping(enum_field_type, index);
+ if (!mapping) {
+ ret = -1;
+ goto end;
+ }
+
+ if (mapping_name) {
+ *mapping_name = g_quark_to_string(mapping->string);
+ }
+
+ if (range_begin) {
+ *range_begin = mapping->range_start._unsigned;
+ }
+
+ if (range_end) {
+ *range_end = mapping->range_end._unsigned;
+ }