+BT_EXPORT
+struct bt_field_class *
+bt_field_class_option_with_selector_field_integer_unsigned_create(
+ struct bt_trace_class *trace_class,
+ struct bt_field_class *content_fc,
+ struct bt_field_class *selector_fc,
+ const struct bt_integer_range_set_unsigned *u_range_set)
+{
+ struct bt_field_class_option_with_selector_field_integer *fc;
+ const struct bt_integer_range_set *range_set =
+ (const void *) u_range_set;
+
+ BT_ASSERT_PRE_NO_ERROR();
+ BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set);
+ BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set);
+ fc = (void *) create_option_field_class(trace_class,
+ BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
+ content_fc, selector_fc, __func__);
+
+ if (!fc) {
+ goto end;
+ }
+
+ fc->range_set = range_set;
+ bt_object_get_ref_no_null_check(fc->range_set);
+ bt_integer_range_set_freeze(range_set);
+
+end:
+ return (void *) fc;
+}
+
+BT_EXPORT
+struct bt_field_class *
+bt_field_class_option_with_selector_field_integer_signed_create(
+ struct bt_trace_class *trace_class,
+ struct bt_field_class *content_fc,
+ struct bt_field_class *selector_fc,
+ const struct bt_integer_range_set_signed *i_range_set)
+{
+ struct bt_field_class_option_with_selector_field_integer *fc;
+ const struct bt_integer_range_set *range_set =
+ (const void *) i_range_set;
+
+ BT_ASSERT_PRE_NO_ERROR();
+ BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set);
+ BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set);
+ fc = (void *) create_option_field_class(trace_class,
+ BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
+ content_fc, selector_fc, __func__);
+
+ if (!fc) {
+ goto end;
+ }
+
+ fc->range_set = range_set;
+ bt_object_get_ref_no_null_check(fc->range_set);
+ bt_integer_range_set_freeze(range_set);
+
+end:
+ return (void *) fc;
+}
+
+BT_EXPORT
+const struct bt_field_class *bt_field_class_option_borrow_field_class_const(
+ const struct bt_field_class *fc)
+{
+ struct bt_field_class_option *opt_fc = (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc, "Field class");
+ return opt_fc->content_fc;
+}
+
+BT_EXPORT
+struct bt_field_class *bt_field_class_option_borrow_field_class(
+ struct bt_field_class *fc)
+{
+ struct bt_field_class_option *opt_fc = (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc, "Field class");
+ return opt_fc->content_fc;
+}
+
+BT_EXPORT
+const struct bt_field_path *
+bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
+ const struct bt_field_class *fc)
+{
+ const struct bt_field_class_option_with_selector_field *opt_fc =
+ (const void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL("field-class", fc, "Field class");
+ return opt_fc->selector_field_path;
+}
+
+BT_EXPORT
+void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
+ struct bt_field_class *fc, bt_bool sel_is_reversed)
+{
+ struct bt_field_class_option_with_selector_field_bool *opt_fc = (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc,
+ "option-field-class-with-boolean-selector-field",
+ BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
+ "Field class");
+ BT_ASSERT_PRE_DEV_FC_HOT(fc);
+ opt_fc->sel_is_reversed = sel_is_reversed;
+}
+
+BT_EXPORT
+bt_bool bt_field_class_option_with_selector_field_bool_selector_is_reversed(
+ const struct bt_field_class *fc)
+{
+ struct bt_field_class_option_with_selector_field_bool *opt_fc = (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc,
+ "option-field-class-with-boolean-selector-field",
+ BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
+ "Field class");
+ return opt_fc->sel_is_reversed;
+}
+
+BT_EXPORT
+const struct bt_integer_range_set_unsigned *
+bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
+ const struct bt_field_class *fc)
+{
+ struct bt_field_class_option_with_selector_field_integer *opt_fc =
+ (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc,
+ "Field class");
+ return (const void *) opt_fc->range_set;
+}
+
+BT_EXPORT
+const struct bt_integer_range_set_signed *
+bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
+ const struct bt_field_class *fc)
+{
+ struct bt_field_class_option_with_selector_field_integer *opt_fc =
+ (void *) fc;
+
+ BT_ASSERT_PRE_FC_NON_NULL(fc);
+ BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc,
+ "Field class");
+ return (const void *) opt_fc->range_set;
+}
+
+static
+void finalize_variant_field_class(struct bt_field_class_variant *var_fc)
+{
+ BT_ASSERT(var_fc);
+ BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc);
+ finalize_field_class((void *) var_fc);
+ finalize_named_field_classes_container((void *) var_fc);
+}
+
+static
+void destroy_variant_field_class(struct bt_object *obj)
+{
+ struct bt_field_class_variant *fc = (void *) obj;
+
+ BT_ASSERT(fc);
+ finalize_variant_field_class(fc);
+ g_free(fc);
+}
+
+static
+void destroy_variant_with_selector_field_field_class(struct bt_object *obj)
+{
+ struct bt_field_class_variant_with_selector_field *fc = (void *) obj;
+
+ BT_ASSERT(fc);
+ finalize_variant_field_class(&fc->common);
+ BT_LOGD_STR("Putting selector field path.");
+ BT_OBJECT_PUT_REF_AND_RESET(fc->selector_field_path);
+ BT_LOGD_STR("Putting selector field class.");
+ BT_OBJECT_PUT_REF_AND_RESET(fc->selector_fc);
+ g_free(fc);
+}
+
+BT_EXPORT
+struct bt_field_class *bt_field_class_variant_create(
+ bt_trace_class *trace_class, bt_field_class *selector_fc)
+{
+ int ret;
+ struct bt_field_class_variant *var_fc = NULL;
+ struct bt_field_class_variant_with_selector_field *var_with_sel_fc = NULL;
+ enum bt_field_class_type fc_type;
+
+ BT_ASSERT_PRE_NO_ERROR();
+ BT_ASSERT_PRE_TC_NON_NULL(trace_class);
+
+ if (selector_fc) {
+ BT_ASSERT_PRE_FC_IS_INT("selector-field-class", selector_fc,
+ "Selector field class");
+ }
+
+ BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
+ selector_fc);
+
+ if (selector_fc) {
+ var_with_sel_fc = g_new0(
+ struct bt_field_class_variant_with_selector_field, 1);
+ if (!var_with_sel_fc) {
+ BT_LIB_LOGE_APPEND_CAUSE(
+ "Failed to allocate one variant field class with selector.");
+ goto error;
+ }
+
+ if (bt_field_class_type_is(selector_fc->type,
+ BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) {
+ fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD;
+ } else {
+ fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD;
+ }
+
+ ret = init_named_field_classes_container(
+ (void *) var_with_sel_fc, fc_type,
+ destroy_variant_with_selector_field_field_class,
+ destroy_variant_with_selector_field_option);
+ if (ret) {
+ /* init_named_field_classes_container() logs errors */
+ goto error;
+ }
+
+ var_with_sel_fc->selector_fc = selector_fc;
+ bt_object_get_ref_no_null_check(var_with_sel_fc->selector_fc);
+ bt_field_class_freeze(selector_fc);
+ var_fc = (void *) var_with_sel_fc;
+ BT_LIB_LOGD("Created default variant field class with selector object: "
+ "%![var-fc-]+F, %![sel-fc-]+F", var_fc, selector_fc);
+ } else {
+ var_fc = g_new0(struct bt_field_class_variant, 1);
+ if (!var_fc) {
+ BT_LIB_LOGE_APPEND_CAUSE(
+ "Failed to allocate one variant field class without selector.");
+ goto error;
+ }
+
+ ret = init_named_field_classes_container((void *) var_fc,
+ BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD,
+ destroy_variant_field_class, destroy_named_field_class);
+ if (ret) {
+ /* init_named_field_classes_container() logs errors */
+ goto error;
+ }
+ BT_LIB_LOGD("Created default variant field class without selector object: "
+ "%![var-fc-]+F", var_fc);
+ }
+
+ BT_ASSERT(var_fc);
+ goto end;
+
+error:
+ BT_OBJECT_PUT_REF_AND_RESET(var_fc);
+ BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc);
+
+end:
+ return (void *) var_fc;
+}
+
+#define VAR_FC_OPT_NAME_IS_UNIQUE_ID \
+ "variant-field-class-option-name-is-unique"
+
+BT_EXPORT
+enum bt_field_class_variant_without_selector_append_option_status
+bt_field_class_variant_without_selector_append_option(struct bt_field_class *fc,