struct bt_ctf_field_type *type,
struct bt_ctf_field *tag)
{
+ int ret;
const char *enum_value;
struct bt_ctf_field_type *field_type = NULL;
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
if (!type || !tag || type->declaration->id != BT_CTF_TYPE_ID_VARIANT) {
goto end;
}
- enum_value = bt_ctf_field_enumeration_get_single_mapping_name(tag);
- if (!enum_value) {
+ iter = bt_ctf_field_enumeration_get_mappings(tag);
+ if (!iter) {
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_enumeration_mapping_iterator_get_name(iter,
+ &enum_value);
+ if (ret) {
goto end;
}
- /* Already increments field_type's reference count */
field_type = bt_ctf_field_type_variant_get_field_type_by_name(
type, enum_value);
end:
+ bt_put(iter);
return field_type;
}
return container;
}
-const char *bt_ctf_field_enumeration_get_single_mapping_name(
- struct bt_ctf_field *field)
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field *field)
{
int ret;
- const char *name = NULL;
struct bt_ctf_field *container = NULL;
struct bt_ctf_field_type *container_type = NULL;
struct bt_ctf_field_type_integer *integer_type = NULL;
}
iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
field->type, value);
- if (!iter) {
- goto error_put_container_type;
- }
- (void) bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
- iter, &name, NULL, NULL);
} else {
int64_t value;
}
iter = bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
field->type, value);
- if (!iter) {
- goto error_put_container_type;
- }
- (void) bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
- iter, &name, NULL, NULL);
}
error_put_container_type:
error_put_container:
bt_put(container);
end:
- bt_put(iter);
- return name;
+ return iter;
}
int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *field,
struct bt_ctf_event_class;
struct bt_ctf_event;
struct bt_ctf_field_type;
-struct bt_ctf_field_type_enum_iter;
+struct bt_ctf_field_type_enumeration_mapping_iterator;
/**
@name Creation and parent field type access functions
bt_ctf_field_unsigned_integer_set_value().
Once you set the integral value of an enumeration field by following the
-previous paragraph, you can get the name of the mapping containing this
+previous paragraph, you can get the names of the mappings containing this
value in the enumeration field with
-bt_ctf_field_enumeration_get_mapping_name().
+bt_ctf_field_enumeration_get_mappings().
@sa ctfirenumfieldtype
@sa ctfirfields
struct bt_ctf_field *enum_field);
/**
-@brief Returns the name of the mapping selected by the current integral
- value of the @enumfield \p enum_field.
+@brief Returns an iterator to the mappings selected by the current
+ integral value of the @enumfield \p enum_field.
On success, \p enum_field remains the sole owner of the returned
value.
@param[in] enum_field Enumeration field of which to get the name of
mapping associated to its current integral
value.
-@returns Name of the mapping associated to the current
- integral value of \p enum_field, or \c NULL
- on error.
+@returns An iterator to the mappings associated to the
+ current integral value of \p enum_field, or
+ \c NULL on error.
@prenotnull{enum_field}
@preisenumfield{enum_field}
value.
@postrefcountsame{enum_field}
*/
-extern const char *bt_ctf_field_enumeration_get_mapping_name(
- struct bt_ctf_field *enum_field);
+extern struct bt_ctf_field_type_enumeration_mapping_iterator *
+bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field *enum_field);
/** @} */
/** @} */
-const char *bt_ctf_field_enumeration_get_single_mapping_name(
- struct bt_ctf_field *field);
-
#ifdef __cplusplus
}
#endif
fprintf(text->out, "{ ");
text->depth++;
if (print_names) {
+ int iter_ret;
struct bt_ctf_field *tag_field = NULL;
const char *tag_choice;
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
tag_field = bt_ctf_field_variant_get_tag(variant);
if (!tag_field) {
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- tag_choice = bt_ctf_field_enumeration_get_single_mapping_name(tag_field);
- if (!tag_choice) {
+
+ iter = bt_ctf_field_enumeration_get_mappings(tag_field);
+ if (!iter) {
+ bt_put(tag_field);
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+
+ iter_ret =
+ bt_ctf_field_type_enumeration_mapping_iterator_get_name(
+ iter, &tag_choice);
+ if (iter_ret) {
+ bt_put(iter);
bt_put(tag_field);
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
fprintf(text->out, "%s = ", rem_(tag_choice));
bt_put(tag_field);
+ bt_put(iter);
}
ret = print_field(text, field, print_names);
if (ret != BT_COMPONENT_STATUS_OK) {
#define DEFAULT_CLOCK_TIME 0
#define DEFAULT_CLOCK_VALUE 0
-#define NR_TESTS 600
+#define NR_TESTS 602
static int64_t current_time = 42;
enum_field = bt_ctf_field_create(ep_enum_field_type);
assert(enum_field);
- ret_char = bt_ctf_field_enumeration_get_single_mapping_name(NULL);
- ok(!ret_char, "bt_ctf_field_enumeration_get_single_mapping_name handles NULL correctly");
- ret_char = bt_ctf_field_enumeration_get_single_mapping_name(enum_field);
- ok(!ret_char, "bt_ctf_field_enumeration_get_single_mapping_name returns NULL if the enumeration's container field is unset");
+ iter = bt_ctf_field_enumeration_get_mappings(NULL);
+ ok(!iter, "bt_ctf_field_enumeration_get_mappings handles NULL correctly");
+ iter = bt_ctf_field_enumeration_get_mappings(enum_field);
+ ok(!iter, "bt_ctf_field_enumeration_get_mappings returns NULL if the enumeration's container field is unset");
enum_container_field = bt_ctf_field_enumeration_get_container(
enum_field);
ok(bt_ctf_field_signed_integer_set_value(
enum_container_field, -42) == 0,
"Set signed enumeration container value");
- ret_char = bt_ctf_field_enumeration_get_single_mapping_name(enum_field);
+ iter = bt_ctf_field_enumeration_get_mappings(enum_field);
+ ok(iter, "bt_ctf_field_enumeration_get_mappings returns an iterator to matching mappings");
+ ret = bt_ctf_field_type_enumeration_mapping_iterator_get_name(iter, &ret_char);
+ ok(!ret && ret_char, "bt_ctf_field_type_enumeration_mapping_iterator_get_name return a mapping name");
ok(!strcmp(ret_char, mapping_name_negative_test),
"bt_ctf_field_enumeration_get_single_mapping_name returns the correct mapping name with an signed container");
ret = bt_ctf_event_set_payload(simple_event, "enum_field", enum_field);
assert(!ret);
+ BT_PUT(iter);
enum_field_unsigned = bt_ctf_field_create(ep_enum_field_unsigned_type);
assert(enum_field_unsigned);
ret = bt_ctf_event_set_payload(simple_event, "enum_field_unsigned",
enum_field_unsigned);
assert(!ret);
- ret_char = bt_ctf_field_enumeration_get_single_mapping_name(enum_field_unsigned);
+ iter = bt_ctf_field_enumeration_get_mappings(enum_field_unsigned);
+ assert(iter);
+ (void) bt_ctf_field_type_enumeration_mapping_iterator_get_name(iter, &ret_char);
ok(ret_char && !strcmp(ret_char, mapping_name_test),
"bt_ctf_field_enumeration_get_single_mapping_name returns the correct mapping name with an unsigned container");
bt_put(ep_integer_field_type);
bt_put(ep_enum_field_type);
bt_put(ep_enum_field_unsigned_type);
+ bt_put(iter);
}
static
struct bt_ctf_field *a_3_copy = NULL;
struct bt_ctf_field *a_4_copy = NULL;
struct bt_ctf_field *strct_copy = NULL;
+ struct bt_ctf_field_type_enumeration_mapping_iterator *e_iter = NULL;
uint64_t uint64_t_val;
const char *str_val;
double double_val;
"bt_ctf_field_copy creates a valid enum's integer field copy");
/* validate e copy */
- str_val = bt_ctf_field_enumeration_get_single_mapping_name(e_copy);
+ e_iter = bt_ctf_field_enumeration_get_mappings(e_copy);
+ (void) bt_ctf_field_type_enumeration_mapping_iterator_get_name(e_iter,
+ &str_val);
ok(str_val && !strcmp(str_val, "LABEL2"),
"bt_ctf_field_copy creates a valid enum field copy");
bt_put(a_3_copy);
bt_put(a_4_copy);
bt_put(strct_copy);
+ bt_put(e_iter);
}
static