lib: add boolean field class and field types
[babeltrace.git] / src / lib / trace-ir / field-class.c
index f1dd23955d95937991f650d2395b114a147dbb85..6afc32b82acbb2a57ddbec6e257a7f8a9166c18e 100644 (file)
@@ -64,6 +64,40 @@ void init_field_class(struct bt_field_class *fc, enum bt_field_class_type type,
        fc->type = type;
 }
 
+static
+void destroy_bool_field_class(struct bt_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj);
+       g_free(obj);
+}
+
+struct bt_field_class *bt_field_class_bool_create(
+               bt_trace_class *trace_class)
+{
+       struct bt_field_class_bool *bool_fc = NULL;
+
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
+       BT_LOGD("Creating default boolean field class object.");
+       bool_fc = g_new0(struct bt_field_class_bool, 1);
+       if (!bool_fc) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one boolean field class.");
+               goto error;
+       }
+
+       init_field_class((void *) bool_fc, BT_FIELD_CLASS_TYPE_BOOL,
+               destroy_bool_field_class);
+       BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc);
+       goto end;
+
+error:
+       BT_OBJECT_PUT_REF_AND_RESET(bool_fc);
+
+end:
+       return (void *) bool_fc;
+}
+
 static
 void init_integer_field_class(struct bt_field_class_integer *fc,
                enum bt_field_class_type type,
@@ -512,7 +546,7 @@ add_mapping_to_enumeration_field_class(struct bt_field_class *fc,
 
        BT_ASSERT(fc);
        BT_ASSERT_PRE_NON_NULL(label, "Label");
-       BT_ASSERT_PRE_NON_NULL(range_set, "Range set");
+       BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set");
        BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_label(
                enum_fc, label),
                "Duplicate mapping name in enumeration field class: "
@@ -1226,10 +1260,10 @@ int append_option_to_variant_with_selector_field_class(
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
        BT_ASSERT_PRE_NON_NULL(option_fc, "Option field class");
-       BT_ASSERT_PRE_NON_NULL(range_set, "Range set");
+       BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set");
        BT_ASSERT_PRE_FC_HAS_ID(fc, expected_type, "Field class");
        BT_ASSERT_PRE(range_set->ranges->len > 0,
-               "Range set is empty: addr=%p", range_set);
+               "Integer range set is empty: %!+R", range_set);
        status = ranges_overlap(var_fc->common.common.named_fcs, range_set,
                expected_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR,
                &has_overlap);
@@ -1239,8 +1273,8 @@ int append_option_to_variant_with_selector_field_class(
        }
 
        BT_ASSERT_PRE(!has_overlap,
-               "Range set's ranges and existing ranges have an overlap: "
-               "addr=%p", range_set);
+               "Integer range set's ranges and existing ranges have an overlap: "
+               "%!+R", range_set);
        opt = create_variant_with_selector_option(name, option_fc, range_set);
        if (!opt) {
                /* create_variant_with_selector_option() logs errors */
This page took 0.027994 seconds and 4 git commands to generate.