lib: metadata: add missing non-const borrowing accessors
[deliverable/babeltrace.git] / lib / trace-ir / field-class.c
index eb949bbcb945f03ea4b25e3d20a6766bbed00e22..59a2c1f50ecf0d2c160662b65aff78f9aec0dd1a 100644 (file)
@@ -81,10 +81,12 @@ void destroy_integer_field_class(struct bt_object *obj)
 }
 
 static inline
-struct bt_field_class *create_integer_field_class(enum bt_field_class_type type)
+struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class,
+               enum bt_field_class_type type)
 {
        struct bt_field_class_integer *int_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default integer field class object: type=%s",
                bt_common_field_class_type_string(type));
        int_fc = g_new0(struct bt_field_class_integer, 1);
@@ -104,16 +106,17 @@ end:
        return (void *) int_fc;
 }
 
-struct bt_field_class *
-bt_field_class_unsigned_integer_create(void)
+struct bt_field_class *bt_field_class_unsigned_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
 }
 
-struct bt_field_class *bt_field_class_signed_integer_create(void)
+struct bt_field_class *bt_field_class_signed_integer_create(
+               bt_trace_class *trace_class)
 {
-       return create_integer_field_class(
+       return create_integer_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
 }
 
@@ -226,10 +229,11 @@ void destroy_enumeration_field_class(struct bt_object *obj)
 
 static
 struct bt_field_class *create_enumeration_field_class(
-               enum bt_field_class_type type)
+               bt_trace_class *trace_class, enum bt_field_class_type type)
 {
        struct bt_field_class_enumeration *enum_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD("Creating default enumeration field class object: type=%s",
                bt_common_field_class_type_string(type));
        enum_fc = g_new0(struct bt_field_class_enumeration, 1);
@@ -263,15 +267,17 @@ end:
        return (void *) enum_fc;
 }
 
-struct bt_field_class *bt_field_class_unsigned_enumeration_create(void)
+struct bt_field_class *bt_field_class_unsigned_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
 }
 
-struct bt_field_class *bt_field_class_signed_enumeration_create(void)
+struct bt_field_class *bt_field_class_signed_enumeration_create(
+               bt_trace_class *trace_class)
 {
-       return create_enumeration_field_class(
+       return create_enumeration_field_class(trace_class,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
 }
 
@@ -370,7 +376,7 @@ void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
 }
 
 void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges,
+               const struct bt_field_class_signed_enumeration_mapping_ranges *ranges,
                uint64_t index, int64_t *lower, int64_t *upper)
 {
        get_enumeration_field_class_mapping_range_at_index(
@@ -583,10 +589,11 @@ void destroy_real_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_real_create(void)
+struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_real *real_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default real field class object.");
        real_fc = g_new0(struct bt_field_class_real, 1);
        if (!real_fc) {
@@ -700,16 +707,18 @@ static
 void destroy_structure_field_class(struct bt_object *obj)
 {
        BT_ASSERT(obj);
-       BT_LIB_LOGD("Destroying string field class object: %!+F", obj);
+       BT_LIB_LOGD("Destroying structure field class object: %!+F", obj);
        finalize_named_field_classes_container((void *) obj);
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_structure_create(void)
+struct bt_field_class *bt_field_class_structure_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_structure *struct_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default structure field class object.");
        struct_fc = g_new0(struct bt_field_class_structure, 1);
        if (!struct_fc) {
@@ -778,7 +787,8 @@ enum bt_field_class_status bt_field_class_structure_append_member(
 {
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
        return append_named_field_class_to_container_field_class((void *) fc,
                name, member_fc);
 }
@@ -789,17 +799,18 @@ uint64_t bt_field_class_structure_get_member_count(
        struct bt_field_class_structure *struct_fc = (void *) fc;
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
        return (uint64_t) struct_fc->common.named_fcs->len;
 }
 
 static
-void borrow_named_field_class_from_container_field_class_at_index_const(
-               const struct bt_field_class_named_field_class_container *fc,
+void borrow_named_field_class_from_container_field_class_at_index(
+               struct bt_field_class_named_field_class_container *fc,
                uint64_t index, const char **name,
-               const struct bt_field_class **out_fc)
+               struct bt_field_class **out_fc)
 {
-       const struct bt_named_field_class *named_fc;
+       struct bt_named_field_class *named_fc;
 
        BT_ASSERT(fc);
        BT_ASSERT_PRE_NON_NULL(name, "Name");
@@ -815,19 +826,31 @@ void bt_field_class_structure_borrow_member_by_index_const(
                const char **name, const struct bt_field_class **out_fc)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index_const(
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       borrow_named_field_class_from_container_field_class_at_index(
+               (void *) fc, index, name, (void *) out_fc);
+}
+
+void bt_field_class_structure_borrow_member_by_index(
+               struct bt_field_class *fc, uint64_t index,
+               const char **name, struct bt_field_class **out_fc)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       borrow_named_field_class_from_container_field_class_at_index(
                (void *) fc, index, name, out_fc);
 }
 
 static
-const struct bt_field_class *
-borrow_field_class_from_container_field_class_by_name_const(
-               const struct bt_field_class_named_field_class_container *fc,
+struct bt_field_class *
+borrow_field_class_from_container_field_class_by_name(
+               struct bt_field_class_named_field_class_container *fc,
                const char *name)
 {
-       const struct bt_field_class *ret_fc = NULL;
-       const struct bt_named_field_class *named_fc;
+       struct bt_field_class *ret_fc = NULL;
+       struct bt_named_field_class *named_fc;
        gpointer orig_key;
        gpointer value;
 
@@ -847,12 +870,24 @@ end:
 }
 
 const struct bt_field_class *
-bt_field_class_structure_borrow_member_field_class_by_name(
+bt_field_class_structure_borrow_member_field_class_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class");
-       return borrow_field_class_from_container_field_class_by_name_const(
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return borrow_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
+}
+
+struct bt_field_class *
+bt_field_class_structure_borrow_member_field_class_by_name(
+               struct bt_field_class *fc, const char *name)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Field class");
+       return borrow_field_class_from_container_field_class_by_name(
                        (void *) fc, name);
 }
 
@@ -871,11 +906,13 @@ void destroy_variant_field_class(struct bt_object *obj)
        g_free(fc);
 }
 
-struct bt_field_class *bt_field_class_variant_create(void)
+struct bt_field_class *bt_field_class_variant_create(
+               bt_trace_class *trace_class)
 {
        int ret;
        struct bt_field_class_variant *var_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default variant field class object.");
        var_fc = g_new0(struct bt_field_class_variant, 1);
        if (!var_fc) {
@@ -933,7 +970,17 @@ bt_field_class_variant_borrow_option_field_class_by_name_const(
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       return borrow_field_class_from_container_field_class_by_name_const(
+       return borrow_field_class_from_container_field_class_by_name(
+               (void *) fc, name);
+}
+
+struct bt_field_class *
+bt_field_class_variant_borrow_option_field_class_by_name(
+               struct bt_field_class *fc, const char *name)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
+       return borrow_field_class_from_container_field_class_by_name(
                (void *) fc, name);
 }
 
@@ -952,7 +999,17 @@ void bt_field_class_variant_borrow_option_by_index_const(
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index_const(
+       borrow_named_field_class_from_container_field_class_at_index(
+               (void *) fc, index, name, (void *) out_fc);
+}
+
+void bt_field_class_variant_borrow_option_by_index(
+               struct bt_field_class *fc, uint64_t index,
+               const char **name, struct bt_field_class **out_fc)
+{
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
+       borrow_named_field_class_from_container_field_class_at_index(
                (void *) fc, index, name, out_fc);
 }
 
@@ -998,11 +1055,12 @@ void destroy_static_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *
-bt_field_class_static_array_create(struct bt_field_class *element_fc,
-               uint64_t length)
+bt_field_class_static_array_create(bt_trace_class *trace_class,
+               struct bt_field_class *element_fc, uint64_t length)
 {
        struct bt_field_class_static_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default static array field class object.");
        array_fc = g_new0(struct bt_field_class_static_array, 1);
@@ -1035,6 +1093,16 @@ bt_field_class_array_borrow_element_field_class_const(
        return array_fc->element_fc;
 }
 
+struct bt_field_class *
+bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc)
+{
+       struct bt_field_class_array *array_fc = (void *) fc;
+
+       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
+       BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class");
+       return array_fc->element_fc;
+}
+
 uint64_t bt_field_class_static_array_get_length(const struct bt_field_class *fc)
 {
        const struct bt_field_class_static_array *array_fc = (const void *) fc;
@@ -1061,10 +1129,12 @@ void destroy_dynamic_array_field_class(struct bt_object *obj)
 }
 
 struct bt_field_class *bt_field_class_dynamic_array_create(
+               bt_trace_class *trace_class,
                struct bt_field_class *element_fc)
 {
        struct bt_field_class_dynamic_array *array_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class");
        BT_LOGD_STR("Creating default dynamic array field class object.");
        array_fc = g_new0(struct bt_field_class_dynamic_array, 1);
@@ -1124,10 +1194,11 @@ void destroy_string_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_string_create(void)
+struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class)
 {
        struct bt_field_class_string *string_fc = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default string field class object.");
        string_fc = g_new0(struct bt_field_class_string, 1);
        if (!string_fc) {
This page took 0.04561 seconds and 5 git commands to generate.