ir: add bt_ctf_field_type_sequence/array_set_element_type()
[babeltrace.git] / formats / ctf / ir / event-types.c
index 74fa30473939440acf5266ce8353dabe7925827a..61c0404d998d30f01f281a8e8c5d387a46eb97bd 100644 (file)
@@ -1545,6 +1545,32 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *type,
+               struct bt_ctf_field_type *element_type)
+{
+       int ret = 0;
+       struct bt_ctf_field_type_array *array;
+
+       if (!type || !element_type ||
+                       (type->declaration->id != CTF_TYPE_ARRAY)) {
+               ret = -1;
+               goto end;
+       }
+
+       array = container_of(type, struct bt_ctf_field_type_array, parent);
+
+       if (array->element_type) {
+               BT_PUT(array->element_type);
+       }
+
+       array->element_type = element_type;
+       bt_get(array->element_type);
+
+end:
+       return ret;
+}
+
 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *type)
 {
        int64_t ret;
@@ -1606,6 +1632,32 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *type,
+               struct bt_ctf_field_type *element_type)
+{
+       int ret = 0;
+       struct bt_ctf_field_type_sequence *sequence;
+
+       if (!type || !element_type ||
+                       (type->declaration->id != CTF_TYPE_SEQUENCE)) {
+               ret = -1;
+               goto end;
+       }
+
+       sequence = container_of(type, struct bt_ctf_field_type_sequence, parent);
+
+       if (sequence->element_type) {
+               BT_PUT(sequence->element_type);
+       }
+
+       sequence->element_type = element_type;
+       bt_get(sequence->element_type);
+
+end:
+       return ret;
+}
+
 const char *bt_ctf_field_type_sequence_get_length_field_name(
                struct bt_ctf_field_type *type)
 {
@@ -1906,6 +1958,46 @@ enum ctf_type_id bt_ctf_field_type_get_type_id(
        return type->declaration->id;
 }
 
+int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_INTEGER;
+}
+
+int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_FLOAT;
+}
+
+int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_ENUM;
+}
+
+int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_STRING;
+}
+
+int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_STRUCT;
+}
+
+int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_ARRAY;
+}
+
+int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_SEQUENCE;
+}
+
+int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type)
+{
+       return bt_ctf_field_type_get_type_id(type) == CTF_TYPE_VARIANT;
+}
+
 void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
 {
        bt_get(type);
@@ -2464,8 +2556,6 @@ void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type *type)
        struct bt_ctf_field_type_variant *variant_type = container_of(
                type, struct bt_ctf_field_type_variant, parent);
 
-       /* Cache the alignment */
-       type->declaration->alignment = bt_ctf_field_type_get_alignment(type);
        generic_field_type_freeze(type);
        g_ptr_array_foreach(variant_type->fields,
                (GFunc) freeze_structure_field, NULL);
This page took 0.025191 seconds and 4 git commands to generate.