lib: add internal bt_field_type_structure_replace_field()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 14 Feb 2018 19:53:36 +0000 (14:53 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:32:03 +0000 (23:32 -0400)
This new internal function replaces the field type of a field identified
by name within a structure field type.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/ctf-ir/field-types-internal.h
lib/ctf-ir/field-types.c

index 3d478ae74d6a5c1565f4ddad17a523eb31d00755..fbe0bb788449884975427e7b83ac6d3b0486559b 100644 (file)
@@ -179,6 +179,10 @@ BT_HIDDEN
 int bt_field_type_structure_get_field_name_index(
                struct bt_field_type *structure, const char *name);
 
+BT_HIDDEN
+int bt_field_type_structure_replace_field(struct bt_field_type *type,
+               const char *field_name, struct bt_field_type *field_type);
+
 BT_HIDDEN
 int bt_field_type_variant_get_field_name_index(
                struct bt_field_type *variant, const char *name);
index 62f2412b5b81bc4ab99296d71eb49198395d762c..ba288b2ebc9ab04aaa158bf82bedb5d4c3f527ee 100644 (file)
@@ -2006,6 +2006,35 @@ error:
        return NULL;
 }
 
+BT_HIDDEN
+int bt_field_type_structure_replace_field(struct bt_field_type *type,
+               const char *field_name, struct bt_field_type *field_type)
+{
+       int ret = 0;
+       struct bt_field_type_structure *structure;
+       GQuark name_quark;
+       uint64_t i;
+
+       assert(type);
+       assert(field_name);
+       assert(field_type);
+       assert(type->id == BT_FIELD_TYPE_ID_STRUCT);
+       structure = container_of(type, struct bt_field_type_structure, parent);
+       name_quark = g_quark_from_string(field_name);
+
+       for (i = 0; i < structure->fields->len; i++) {
+               struct structure_field *field = g_ptr_array_index(
+                       structure->fields, i);
+
+               if (field->name == name_quark) {
+                       bt_put(field->type);
+                       field->type = bt_get(field_type);
+               }
+       }
+
+       return ret;
+}
+
 int bt_field_type_structure_add_field(struct bt_field_type *type,
                struct bt_field_type *field_type,
                const char *field_name)
This page took 0.026728 seconds and 4 git commands to generate.