ir: add bt_ctf_field_type_structure_get_field_name_index()
[babeltrace.git] / formats / ctf / ir / event-types.c
index 94723f2b7724e00c4a7ce0f86569e913690e9a9a..195f935d521a11f86ed58dd2aecb6c03b985f957 100644 (file)
@@ -358,9 +358,6 @@ void bt_ctf_field_type_destroy(struct bt_ctf_ref *ref)
                return;
        }
 
-       if (type->alias_name) {
-               g_string_free(type->alias_name, TRUE);
-       }
        type_destroy_funcs[type_id](ref);
 }
 
@@ -385,6 +382,27 @@ int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
                ret = enumeration->entries->len ? 0 : -1;
                break;
        }
+       case CTF_TYPE_SEQUENCE:
+       {
+               struct bt_ctf_field_type_sequence *sequence =
+                       container_of(type, struct bt_ctf_field_type_sequence,
+                       parent);
+
+               /* length field name should be set at this point */
+               ret = sequence->length_field_name->len ? 0 : -1;
+               break;
+       }
+       case CTF_TYPE_VARIANT:
+       {
+               struct bt_ctf_field_type_variant *variant =
+                       container_of(type, struct bt_ctf_field_type_variant,
+                               parent);
+
+               if (variant->tag_name->len == 0 || !variant->tag) {
+                       ret = -1;
+               }
+               break;
+       }
        default:
                break;
        }
@@ -1316,6 +1334,25 @@ end:
        return tag_name;
 }
 
+int bt_ctf_field_type_variant_set_tag_name(
+               struct bt_ctf_field_type *type, const char *name)
+{
+       int ret = 0;
+       struct bt_ctf_field_type_variant *variant;
+
+       if (!type || type->frozen ||
+               (type->declaration->id != CTF_TYPE_VARIANT) ||
+               bt_ctf_validate_identifier(name)) {
+               ret = -1;
+               goto end;
+       }
+
+       variant = container_of(type, struct bt_ctf_field_type_variant, parent);
+       g_string_assign(variant->tag_name, name);
+end:
+       return ret;
+}
+
 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type,
                struct bt_ctf_field_type *field_type,
                const char *field_name)
@@ -1745,7 +1782,6 @@ int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
                goto end;
        }
 
-       type_id = type->declaration->id;
        switch (byte_order) {
        case BT_CTF_BYTE_ORDER_NATIVE:
                /* Leave unset. Will be initialized by parent. */
@@ -1763,6 +1799,7 @@ int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
                goto end;
        }
 
+       type_id = type->declaration->id;
        if (set_byte_order_funcs[type_id]) {
                set_byte_order_funcs[type_id](type, internal_byte_order, 0);
        }
@@ -1780,20 +1817,6 @@ enum ctf_type_id bt_ctf_field_type_get_type_id(
        return type->declaration->id;
 }
 
-const char *bt_ctf_field_type_get_alias_name(
-               struct bt_ctf_field_type *type)
-{
-       const char *name = NULL;
-
-       if (!type || !type->alias_name) {
-               goto end;
-       }
-
-       name = type->alias_name->str;
-end:
-       return name;
-}
-
 void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
 {
        if (!type) {
@@ -1932,6 +1955,39 @@ end:
        return copy;
 }
 
+
+BT_HIDDEN
+int bt_ctf_field_type_structure_get_field_name_index(
+               struct bt_ctf_field_type *type, const char *name)
+{
+       int ret;
+       size_t index;
+       GQuark name_quark;
+       struct bt_ctf_field_type_structure *structure;
+
+       if (!type || !name ||
+               bt_ctf_field_type_get_type_id(type) != CTF_TYPE_STRUCT) {
+               ret = -1;
+               goto end;
+       }
+
+       name_quark = g_quark_try_string(name);
+       if (!name_quark) {
+               ret = -1;
+               goto end;
+       }
+
+       structure = container_of(type, struct bt_ctf_field_type_structure,
+               parent);
+       if (!g_hash_table_lookup_extended(structure->field_name_to_index,
+               GUINT_TO_POINTER(name_quark), NULL, (gpointer *)&index)) {
+               ret = -1;
+               goto end;
+       }
+       ret = (int) index;
+end:
+       return ret;
+}
 static
 void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
 {
This page took 0.026399 seconds and 4 git commands to generate.