lib: fix can_seek_beginning method type cast
[babeltrace.git] / src / lib / trace-ir / field.c
index 805de0f8f63779f20c383a4115d7c07651a586b9..62113d576d08f11b1bc722ad6e3a80ca7aeb8b74 100644 (file)
@@ -47,6 +47,9 @@ void reset_array_field(struct bt_field *field);
 static
 void reset_structure_field(struct bt_field *field);
 
+static
+void reset_option_field(struct bt_field *field);
+
 static
 void reset_variant_field(struct bt_field *field);
 
@@ -59,6 +62,9 @@ void set_array_field_is_frozen(struct bt_field *field, bool is_frozen);
 static
 void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen);
 
+static
+void set_option_field_is_frozen(struct bt_field *field, bool is_frozen);
+
 static
 void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen);
 
@@ -71,9 +77,26 @@ bool array_field_is_set(const struct bt_field *field);
 static
 bool structure_field_is_set(const struct bt_field *field);
 
+static
+bool option_field_is_set(const struct bt_field *field);
+
 static
 bool variant_field_is_set(const struct bt_field *field);
 
+static
+struct bt_field_methods bool_field_methods = {
+       .set_is_frozen = set_single_field_is_frozen,
+       .is_set = single_field_is_set,
+       .reset = reset_single_field,
+};
+
+static
+struct bt_field_methods bit_array_field_methods = {
+       .set_is_frozen = set_single_field_is_frozen,
+       .is_set = single_field_is_set,
+       .reset = reset_single_field,
+};
+
 static
 struct bt_field_methods integer_field_methods = {
        .set_is_frozen = set_single_field_is_frozen,
@@ -109,6 +132,13 @@ struct bt_field_methods array_field_methods = {
        .reset = reset_array_field,
 };
 
+static
+struct bt_field_methods option_field_methods = {
+       .set_is_frozen = set_option_field_is_frozen,
+       .is_set = option_field_is_set,
+       .reset = reset_option_field,
+};
+
 static
 struct bt_field_methods variant_field_methods = {
        .set_is_frozen = set_variant_field_is_frozen,
@@ -116,6 +146,12 @@ struct bt_field_methods variant_field_methods = {
        .reset = reset_variant_field,
 };
 
+static
+struct bt_field *create_bool_field(struct bt_field_class *);
+
+static
+struct bt_field *create_bit_array_field(struct bt_field_class *);
+
 static
 struct bt_field *create_integer_field(struct bt_field_class *);
 
@@ -134,23 +170,37 @@ struct bt_field *create_static_array_field(struct bt_field_class *);
 static
 struct bt_field *create_dynamic_array_field(struct bt_field_class *);
 
+static
+struct bt_field *create_option_field(struct bt_field_class *);
+
 static
 struct bt_field *create_variant_field(struct bt_field_class *);
 
 static
 struct bt_field *(* const field_create_funcs[])(struct bt_field_class *) = {
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]  = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]    = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]        = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                      = create_real_field,
-       [BT_FIELD_CLASS_TYPE_STRING]            = create_string_field,
-       [BT_FIELD_CLASS_TYPE_STRUCTURE]         = create_structure_field,
-       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]              = create_static_array_field,
-       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]     = create_dynamic_array_field,
-       [BT_FIELD_CLASS_TYPE_VARIANT]           = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_BOOL]                              = create_bool_field,
+       [BT_FIELD_CLASS_TYPE_BIT_ARRAY]                         = create_bit_array_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]                  = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = create_integer_field,
+       [BT_FIELD_CLASS_TYPE_REAL]                              = create_real_field,
+       [BT_FIELD_CLASS_TYPE_STRING]                            = create_string_field,
+       [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = create_structure_field,
+       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = create_static_array_field,
+       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]                     = create_dynamic_array_field,
+       [BT_FIELD_CLASS_TYPE_OPTION]                            = create_option_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR]          = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR]    = create_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR]      = create_variant_field,
 };
 
+static
+void destroy_bool_field(struct bt_field *field);
+
+static
+void destroy_bit_array_field(struct bt_field *field);
+
 static
 void destroy_integer_field(struct bt_field *field);
 
@@ -166,39 +216,47 @@ void destroy_structure_field(struct bt_field *field);
 static
 void destroy_array_field(struct bt_field *field);
 
+static
+void destroy_option_field(struct bt_field *field);
+
 static
 void destroy_variant_field(struct bt_field *field);
 
 static
 void (* const field_destroy_funcs[])(struct bt_field *) = {
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]  = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]    = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]        = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                      = destroy_real_field,
-       [BT_FIELD_CLASS_TYPE_STRING]            = destroy_string_field,
-       [BT_FIELD_CLASS_TYPE_STRUCTURE]         = destroy_structure_field,
-       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]              = destroy_array_field,
-       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]     = destroy_array_field,
-       [BT_FIELD_CLASS_TYPE_VARIANT]           = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_BOOL]                              = destroy_bool_field,
+       [BT_FIELD_CLASS_TYPE_BIT_ARRAY]                         = destroy_bit_array_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER]                  = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = destroy_integer_field,
+       [BT_FIELD_CLASS_TYPE_REAL]                              = destroy_real_field,
+       [BT_FIELD_CLASS_TYPE_STRING]                            = destroy_string_field,
+       [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = destroy_structure_field,
+       [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = destroy_array_field,
+       [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY]                     = destroy_array_field,
+       [BT_FIELD_CLASS_TYPE_OPTION]                            = destroy_option_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR]          = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR]    = destroy_variant_field,
+       [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR]      = destroy_variant_field,
 };
 
 struct bt_field_class *bt_field_borrow_class(const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class;
 }
 
 const struct bt_field_class *bt_field_borrow_class_const(
                const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class;
 }
 
 enum bt_field_class_type bt_field_get_class_type(const struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        return field->class->type;
 }
 
@@ -207,8 +265,7 @@ struct bt_field *bt_field_create(struct bt_field_class *fc)
 {
        struct bt_field *field = NULL;
 
-       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT(bt_field_class_has_known_type(fc));
+       BT_ASSERT(fc);
        field = field_create_funcs[fc->type](fc);
        if (!field) {
                BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
@@ -232,6 +289,46 @@ void init_field(struct bt_field *field, struct bt_field_class *fc,
        bt_object_get_no_null_check(fc);
 }
 
+static
+struct bt_field *create_bool_field(struct bt_field_class *fc)
+{
+       struct bt_field_bool *bool_field;
+
+       BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc);
+       bool_field = g_new0(struct bt_field_bool, 1);
+       if (!bool_field) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one boolean field.");
+               goto end;
+       }
+
+       init_field((void *) bool_field, fc, &bool_field_methods);
+       BT_LIB_LOGD("Created boolean field object: %!+f", bool_field);
+
+end:
+       return (void *) bool_field;
+}
+
+static
+struct bt_field *create_bit_array_field(struct bt_field_class *fc)
+{
+       struct bt_field_bit_array *ba_field;
+
+       BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc);
+       ba_field = g_new0(struct bt_field_bit_array, 1);
+       if (!ba_field) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one bit array field.");
+               goto end;
+       }
+
+       init_field((void *) ba_field, fc, &bit_array_field_methods);
+       BT_LIB_LOGD("Created bit array field object: %!+f", ba_field);
+
+end:
+       return (void *) ba_field;
+}
+
 static
 struct bt_field *create_integer_field(struct bt_field_class *fc)
 {
@@ -320,8 +417,7 @@ int create_fields_from_named_field_classes(
 
        for (i = 0; i < fc->named_fcs->len; i++) {
                struct bt_field *field;
-               struct bt_named_field_class *named_fc =
-                       BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, i);
+               struct bt_named_field_class *named_fc = fc->named_fcs->pdata[i];
 
                field = bt_field_create(named_fc->fc);
                if (!field) {
@@ -369,6 +465,37 @@ end:
        return (void *) struct_field;
 }
 
+static
+struct bt_field *create_option_field(struct bt_field_class *fc)
+{
+       struct bt_field_option *opt_field;
+       struct bt_field_class_option *opt_fc = (void *) fc;
+
+       BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc);
+       opt_field = g_new0(struct bt_field_option, 1);
+       if (!opt_field) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one option field.");
+               goto end;
+       }
+
+       init_field((void *) opt_field, fc, &option_field_methods);
+       opt_field->content_field = bt_field_create(opt_fc->content_fc);
+       if (!opt_field->content_field) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to create option field's content field: "
+                       "%![opt-fc-]+F, %![content-fc-]+F",
+                       opt_fc, opt_fc->content_fc);
+               BT_OBJECT_PUT_REF_AND_RESET(opt_field);
+               goto end;
+       }
+
+       BT_LIB_LOGD("Created option field object: %!+f", opt_field);
+
+end:
+       return (void *) opt_field;
+}
+
 static
 struct bt_field *create_variant_field(struct bt_field_class *fc)
 {
@@ -437,7 +564,7 @@ end:
 static
 struct bt_field *create_static_array_field(struct bt_field_class *fc)
 {
-       struct bt_field_class_static_array *array_fc = (void *) fc;
+       struct bt_field_class_array_static *array_fc = (void *) fc;
        struct bt_field_array *array_field;
 
        BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
@@ -492,24 +619,79 @@ end:
        return (void *) array_field;
 }
 
-int64_t bt_field_signed_integer_get_value(const struct bt_field *field)
+bt_bool bt_field_bool_get_value(const struct bt_field *field)
+{
+       const struct bt_field_bool *bool_field = (const void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_BOOL,
+               "Field");
+       return (bt_bool) bool_field->value;
+}
+
+void bt_field_bool_set_value(struct bt_field *field, bt_bool value)
+{
+       struct bt_field_bool *bool_field = (void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_BOOL,
+               "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       bool_field->value = (bool) value;
+       bt_field_set_single(field, true);
+}
+
+uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field *field)
+{
+       const struct bt_field_bit_array *ba_field = (const void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
+       return ba_field->value_as_int;
+}
+
+void bt_field_bit_array_set_value_as_integer(struct bt_field *field,
+               uint64_t value)
+{
+       struct bt_field_bit_array *ba_field = (void *) field;
+       struct bt_field_class_bit_array *ba_fc;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       ba_fc = (void *) field->class;
+       ba_field->value_as_int = value;
+
+       if (ba_fc->length < 64) {
+               /* Apply mask */
+               ba_field->value_as_int &= ((UINT64_C(1) << ba_fc->length) - 1);
+       }
+
+       bt_field_set_single(field, true);
+}
+
+int64_t bt_field_integer_signed_get_value(const struct bt_field *field)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
        return int_field->value.i;
 }
 
-void bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
+void bt_field_integer_signed_set_value(struct bt_field *field, int64_t value)
 {
        struct bt_field_integer *int_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(bt_util_value_is_in_range_signed(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
                ((struct bt_field_class_integer *) field->class)->range, value),
                "Value is out of bounds: value=%" PRId64 ", %![field-]+f, "
                "%![fc-]+F", value, field, field->class);
@@ -517,24 +699,24 @@ void bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
        bt_field_set_single(field, true);
 }
 
-uint64_t bt_field_unsigned_integer_get_value(const struct bt_field *field)
+uint64_t bt_field_integer_unsigned_get_value(const struct bt_field *field)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
        return int_field->value.u;
 }
 
-void bt_field_unsigned_integer_set_value(struct bt_field *field, uint64_t value)
+void bt_field_integer_unsigned_set_value(struct bt_field *field, uint64_t value)
 {
        struct bt_field_integer *int_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(bt_util_value_is_in_range_unsigned(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
                ((struct bt_field_class_integer *) field->class)->range, value),
                "Value is out of bounds: value=%" PRIu64 ", %![field-]+f, "
                "%![fc-]+F", value, field, field->class);
@@ -546,9 +728,9 @@ double bt_field_real_get_value(const struct bt_field *field)
 {
        const struct bt_field_real *real_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
        return real_field->value;
 }
 
@@ -556,10 +738,10 @@ void bt_field_real_set_value(struct bt_field *field, double value)
 {
        struct bt_field_real *real_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE(
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV(
                !((struct bt_field_class_real *) field->class)->is_single_precision ||
                (double) (float) value == value,
                "Invalid value for a single-precision real number: value=%f, "
@@ -569,40 +751,40 @@ void bt_field_real_set_value(struct bt_field *field, double value)
 }
 
 enum bt_field_enumeration_get_mapping_labels_status
-bt_field_unsigned_enumeration_get_mapping_labels(
+bt_field_enumeration_unsigned_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_unsigned_enumeration_get_mapping_labels_for_value(
+               bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
                        field->class, int_field->value.u, label_array, count);
 }
 
 enum bt_field_enumeration_get_mapping_labels_status
-bt_field_signed_enumeration_get_mapping_labels(
+bt_field_enumeration_signed_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
 {
        const struct bt_field_integer *int_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
-       BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
+       BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_signed_enumeration_get_mapping_labels_for_value(
+               bt_field_class_enumeration_signed_get_mapping_labels_for_value(
                        field->class, int_field->value.i, label_array, count);
 }
 
@@ -610,9 +792,9 @@ const char *bt_field_string_get_value(const struct bt_field *field)
 {
        const struct bt_field_string *string_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        return (const char *) string_field->buf->data;
 }
@@ -621,9 +803,9 @@ uint64_t bt_field_string_get_length(const struct bt_field *field)
 {
        const struct bt_field_string *string_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        return string_field->length;
 }
@@ -641,10 +823,10 @@ void clear_string_field(struct bt_field *field)
 enum bt_field_string_set_value_status bt_field_string_set_value(
                struct bt_field *field, const char *value)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        clear_string_field(field);
        return (int) bt_field_string_append_with_length(field, value,
@@ -665,14 +847,14 @@ enum bt_field_string_append_status bt_field_string_append_with_length(
        char *data;
        uint64_t new_length;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRING, "Field");
 
        /* Make sure no null bytes are appended */
-       BT_ASSERT_PRE(memchr(value, '\0', length) == NULL,
+       BT_ASSERT_PRE_DEV(!memchr(value, '\0', length),
                "String value to append contains a null character: "
                "partial-value=\"%.32s\", length=%" PRIu64, value, length);
 
@@ -692,9 +874,9 @@ enum bt_field_string_append_status bt_field_string_append_with_length(
 
 void bt_field_string_clear(struct bt_field *field)
 {
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRING, "Field");
        clear_string_field(field);
 }
@@ -703,21 +885,21 @@ uint64_t bt_field_array_get_length(const struct bt_field *field)
 {
        const struct bt_field_array *array_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
        return array_field->length;
 }
 
-enum bt_field_dynamic_array_set_length_status bt_field_dynamic_array_set_length(
+enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length(
                struct bt_field *field, uint64_t length)
 {
        int ret = BT_FUNC_STATUS_OK;
        struct bt_field_array *array_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
 
        if (G_UNLIKELY(length > array_field->fields->len)) {
                /* Make more room */
@@ -759,9 +941,9 @@ struct bt_field *borrow_array_field_element_field_by_index(
 {
        struct bt_field_array *array_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, array_field->length);
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, array_field->length);
        return array_field->fields->pdata[index];
 }
 
@@ -784,10 +966,10 @@ struct bt_field *borrow_structure_field_member_field_by_index(
 {
        struct bt_field_structure *struct_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, struct_field->fields->len);
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, struct_field->fields->len);
        return struct_field->fields->pdata[index];
 }
 
@@ -816,9 +998,9 @@ struct bt_field *borrow_structure_field_member_field_by_name(
        gpointer orig_key;
        gpointer index;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_NON_NULL(name, "Field name");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_NON_NULL(name, "Field name");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
        struct_fc = (void *) field->class;
 
@@ -847,16 +1029,47 @@ const struct bt_field *bt_field_structure_borrow_member_field_by_name_const(
                (void *) field, name);
 }
 
+void bt_field_option_set_has_field(struct bt_field *field, bt_bool has_field)
+{
+       struct bt_field_option *opt_field = (void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_OPTION, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+
+       if (has_field) {
+               opt_field->selected_field = opt_field->content_field;
+       } else {
+               opt_field->selected_field = NULL;
+       }
+}
+
+struct bt_field *bt_field_option_borrow_field(struct bt_field *field)
+{
+       struct bt_field_option *opt_field = (void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_OPTION, "Field");
+       return opt_field->selected_field;
+}
+
+const struct bt_field *bt_field_option_borrow_field_const(
+               const struct bt_field *field)
+{
+       return (const void *) bt_field_option_borrow_field((void *) field);
+}
+
 static inline
 struct bt_field *borrow_variant_field_selected_option_field(
                struct bt_field *field)
 {
        struct bt_field_variant *var_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE(var_field->selected_field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
                "Variant field has no selected field: %!+f", field);
        return var_field->selected_field;
 }
@@ -873,17 +1086,59 @@ const struct bt_field *bt_field_variant_borrow_selected_option_field_const(
        return borrow_variant_field_selected_option_field((void *) field);
 }
 
-enum bt_field_variant_select_option_field_status
-bt_field_variant_select_option_field(
+static
+const struct bt_field_class_variant_option *
+borrow_variant_field_selected_class_option(const struct bt_field *field)
+{
+       const struct bt_field_class_named_field_class_container *container_fc;
+       const struct bt_field_variant *var_field = (const void *) field;
+
+       BT_ASSERT(field);
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
+               "Variant field has no selected field: %!+f", field);
+       container_fc = (const void *) field->class;
+       return container_fc->named_fcs->pdata[var_field->selected_index];
+}
+
+const struct bt_field_class_variant_option *
+bt_field_variant_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       return borrow_variant_field_selected_class_option(field);
+}
+
+const struct bt_field_class_variant_with_selector_unsigned_option *
+bt_field_variant_with_unsigned_selector_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR, "Field");
+       return (const void *) borrow_variant_field_selected_class_option(field);
+}
+
+const struct bt_field_class_variant_with_selector_signed_option *
+bt_field_variant_with_signed_selector_borrow_selected_class_option_const(
+               const struct bt_field *field)
+{
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR, "Field");
+       return (const void *) borrow_variant_field_selected_class_option(field);
+}
+
+enum bt_field_variant_select_option_field_by_index_status
+bt_field_variant_select_option_field_by_index(
                struct bt_field *field, uint64_t index)
 {
        struct bt_field_variant *var_field = (void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_VALID_INDEX(index, var_field->fields->len);
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+       BT_ASSERT_PRE_DEV_VALID_INDEX(index, var_field->fields->len);
        var_field->selected_field = var_field->fields->pdata[index];
        var_field->selected_index = index;
        return BT_FUNC_STATUS_OK;
@@ -894,10 +1149,9 @@ uint64_t bt_field_variant_get_selected_option_field_index(
 {
        const struct bt_field_variant *var_field = (const void *) field;
 
-       BT_ASSERT_PRE_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
-               BT_FIELD_CLASS_TYPE_VARIANT, "Field");
-       BT_ASSERT_PRE(var_field->selected_field,
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
+       BT_ASSERT_PRE_DEV(var_field->selected_field,
                "Variant field has no selected field: %!+f", field);
        return var_field->selected_index;
 }
@@ -910,6 +1164,24 @@ void bt_field_finalize(struct bt_field *field)
        BT_OBJECT_PUT_REF_AND_RESET(field->class);
 }
 
+static
+void destroy_bool_field(struct bt_field *field)
+{
+       BT_ASSERT(field);
+       BT_LIB_LOGD("Destroying boolean field object: %!+f", field);
+       bt_field_finalize(field);
+       g_free(field);
+}
+
+static
+void destroy_bit_array_field(struct bt_field *field)
+{
+       BT_ASSERT(field);
+       BT_LIB_LOGD("Destroying bit array field object: %!+f", field);
+       bt_field_finalize(field);
+       g_free(field);
+}
+
 static
 void destroy_integer_field(struct bt_field *field)
 {
@@ -945,6 +1217,22 @@ void destroy_structure_field(struct bt_field *field)
        g_free(field);
 }
 
+static
+void destroy_option_field(struct bt_field *field)
+{
+       struct bt_field_option *opt_field = (void *) field;
+
+       BT_ASSERT(field);
+       BT_LIB_LOGD("Destroying option field object: %!+f", field);
+       bt_field_finalize(field);
+
+       if (opt_field->content_field) {
+               bt_field_destroy(opt_field->content_field);
+       }
+
+       g_free(field);
+}
+
 static
 void destroy_variant_field(struct bt_field *field)
 {
@@ -1000,7 +1288,6 @@ BT_HIDDEN
 void bt_field_destroy(struct bt_field *field)
 {
        BT_ASSERT(field);
-       BT_ASSERT(bt_field_class_has_known_type(field->class));
        field_destroy_funcs[field->class->type](field);
 }
 
@@ -1024,6 +1311,16 @@ void reset_structure_field(struct bt_field *field)
        }
 }
 
+static
+void reset_option_field(struct bt_field *field)
+{
+       struct bt_field_option *opt_field = (void *) field;
+
+       BT_ASSERT(opt_field);
+       bt_field_reset(opt_field->content_field);
+       opt_field->selected_field = NULL;
+}
+
 static
 void reset_variant_field(struct bt_field *field)
 {
@@ -1071,12 +1368,23 @@ void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen)
                BT_LIB_LOGD("Setting structure field's member field's "
                        "frozen state: %![field-]+f, index=%" PRIu64,
                        member_field, i);
-               bt_field_set_is_frozen(member_field, is_frozen);
+               _bt_field_set_is_frozen(member_field, is_frozen);
        }
 
        set_single_field_is_frozen(field, is_frozen);
 }
 
+static
+void set_option_field_is_frozen(struct bt_field *field, bool is_frozen)
+{
+       struct bt_field_option *opt_field = (void *) field;
+
+       BT_LIB_LOGD("Setting option field's frozen state: "
+               "%![field-]+f, is-frozen=%d", field, is_frozen);
+       _bt_field_set_is_frozen(opt_field->content_field, is_frozen);
+       set_single_field_is_frozen(field, is_frozen);
+}
+
 static
 void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen)
 {
@@ -1092,7 +1400,7 @@ void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen)
                BT_LIB_LOGD("Setting variant field's option field's "
                        "frozen state: %![field-]+f, index=%" PRIu64,
                        option_field, i);
-               bt_field_set_is_frozen(option_field, is_frozen);
+               _bt_field_set_is_frozen(option_field, is_frozen);
        }
 
        set_single_field_is_frozen(field, is_frozen);
@@ -1113,7 +1421,7 @@ void set_array_field_is_frozen(struct bt_field *field, bool is_frozen)
                BT_LIB_LOGD("Setting array field's element field's "
                        "frozen state: %![field-]+f, index=%" PRIu64,
                        elem_field, i);
-               bt_field_set_is_frozen(elem_field, is_frozen);
+               _bt_field_set_is_frozen(elem_field, is_frozen);
        }
 
        set_single_field_is_frozen(field, is_frozen);
@@ -1157,6 +1465,21 @@ end:
        return is_set;
 }
 
+static
+bool option_field_is_set(const struct bt_field *field)
+{
+       const struct bt_field_option *opt_field = (const void *) field;
+       bool is_set = false;
+
+       BT_ASSERT(field);
+
+       if (opt_field->selected_field) {
+               is_set = bt_field_is_set(opt_field->selected_field);
+       }
+
+       return is_set;
+}
+
 static
 bool variant_field_is_set(const struct bt_field *field)
 {
This page took 0.035962 seconds and 4 git commands to generate.