lib: commonize some precondition assertion macros
[babeltrace.git] / src / lib / trace-ir / field-class.h
index 1cd14e39aa247d1c023b4fa75d0863bc85be224d..464dd286c98e23e2a4dba8f80ff0a629e26ca560 100644 (file)
 #include <stdint.h>
 #include <glib.h>
 
-#define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc)                             \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
-
-#define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name)                            \
-       _name " is not an integer field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc)                    \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION)
-
-#define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name)                   \
-       _name " is not an unsigned integer field class: %![fc-]+F"
-
-
-#define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc)                      \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
-
-#define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name)                     \
-       _name " is not a signed integer field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc)                            \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
-
-#define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name)                           \
-       _name " is not an enumeration field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc)                           \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name)                          \
-       _name " is not an array field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc)                          \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name)                         \
-       _name " is not an option field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc)                 \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name)                \
-       _name " is not an option field class with a selector: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc)             \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name)            \
-       _name " is not an option field class with an integer selector: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc)                         \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name)                                \
-       _name " is not a variant field class: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc)                        \
-       (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
-       ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
-
-#define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name)               \
-       _name " is not a variant field class with a selector: %![fc-]+F"
-
-#define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type)                      \
-       (((const struct bt_field_class *) (_fc))->type == (_type))
-
-#define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name)                            \
-       _name " has the wrong type: expected-type=%s, %![fc-]+F"
-
-#define BT_ASSERT_PRE_FC_IS_INT(_fc, _name)                            \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc),               \
-               _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name)                   \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc),      \
-               _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name)                     \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc),        \
-               _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name)                           \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc),              \
-               _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name)                          \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc),             \
-               _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_OPTION(_fc, _name)                         \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc),            \
-               _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(_fc, _name)                        \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc),   \
-               _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(_fc, _name)            \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
-               _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name)                                \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc),           \
-               _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name)               \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc),  \
-               _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name)                     \
-       BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)),    \
-               _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name),                    \
-               bt_common_field_class_type_string(_type), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name)                                \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc),           \
-               _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name)               \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc),  \
-               _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name)                 \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc),    \
-               _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name)                       \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc),          \
-               _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name)                      \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc),         \
-               _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_OPTION(_fc, _name)                     \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc),        \
-               _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_SEL(_fc, _name)            \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
-               _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_INT_SEL(_fc, _name)                \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
-               _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name)                    \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc),       \
-               _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name)           \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
-               _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name)                 \
-       BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
-               _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name),                    \
-               bt_common_field_class_type_string(_type), (_fc))
-
-#define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name)                           \
-       BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc),    \
-               (_name), ": %!+F", (_fc))
-
 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index)              \
        (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
                struct bt_field_class_enumeration_mapping, (_index)))
This page took 0.025538 seconds and 4 git commands to generate.