}
BT_HIDDEN
-int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type,
+int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type,
struct bt_ctf_field_type *tag)
{
int ret = 0;
struct bt_ctf_field_type_variant *variant;
- if (!type || !tag || type->frozen ||
- bt_ctf_field_type_get_type_id(tag) != CTF_TYPE_ENUM) {
+ if (!type || !tag ||
+ bt_ctf_field_type_get_type_id(tag) != CTF_TYPE_ENUM) {
ret = -1;
goto end;
}
if (ret) {
goto end;
}
-
- ret = 1;
}
/* Equal */
if (ret) {
goto end;
}
-
- ret = 1;
}
/* Equal */
end:
return ret;
}
+
+BT_HIDDEN
+int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *field_type)
+{
+ int field_count = -1;
+ enum ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+
+ switch (type_id) {
+ case CTF_TYPE_STRUCT:
+ field_count =
+ bt_ctf_field_type_structure_get_field_count(field_type);
+ break;
+ case CTF_TYPE_VARIANT:
+ field_count =
+ bt_ctf_field_type_variant_get_field_count(field_type);
+ break;
+ case CTF_TYPE_ARRAY:
+ case CTF_TYPE_SEQUENCE:
+ /*
+ * Array and sequence types always contain a single member
+ * (the element type).
+ */
+ field_count = 1;
+ break;
+ default:
+ break;
+ }
+
+ return field_count;
+}
+
+BT_HIDDEN
+struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index(
+ struct bt_ctf_field_type *field_type, int index)
+{
+ struct bt_ctf_field_type *field = NULL;
+ enum ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+
+ switch (type_id) {
+ case CTF_TYPE_STRUCT:
+ bt_ctf_field_type_structure_get_field(field_type, NULL, &field,
+ index);
+ break;
+ case CTF_TYPE_VARIANT:
+ bt_ctf_field_type_variant_get_field(field_type, NULL,
+ &field, index);
+ break;
+ case CTF_TYPE_ARRAY:
+ field = bt_ctf_field_type_array_get_element_type(field_type);
+ break;
+ case CTF_TYPE_SEQUENCE:
+ field = bt_ctf_field_type_sequence_get_element_type(field_type);
+ break;
+ default:
+ break;
+ }
+
+ return field;
+}
+
+BT_HIDDEN
+int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *field_type,
+ const char *name)
+{
+ int field_index = -1;
+ enum ctf_type_id type_id = bt_ctf_field_type_get_type_id(field_type);
+
+ switch (type_id) {
+ case CTF_TYPE_STRUCT:
+ field_index = bt_ctf_field_type_structure_get_field_name_index(
+ field_type, name);
+ break;
+ case CTF_TYPE_VARIANT:
+ field_index = bt_ctf_field_type_variant_get_field_name_index(
+ field_type, name);
+ break;
+ default:
+ break;
+ }
+
+ return field_index;
+}