lib: make bt_field_is_*() and bt_field_type_is_*() static inline
[babeltrace.git] / include / babeltrace / ctf-ir / field-types.h
index f1f6ef7acbe1bb17b57aeb40c8a1bf6bbc665acd..951fb48b5563456f48b632ec6da4c513c0bfed36 100644 (file)
@@ -30,6 +30,9 @@
  * http://www.efficios.com/ctf
  */
 
+/* For bt_get() */
+#include <babeltrace/ref.h>
+
 /* For bt_bool */
 #include <babeltrace/types.h>
 
@@ -320,8 +323,12 @@ extern enum bt_field_type_id bt_field_type_get_type_id(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_integer(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_integer(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) ==
+               BT_FIELD_TYPE_ID_INTEGER;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @floatft.
@@ -337,8 +344,11 @@ extern bt_bool bt_field_type_is_integer(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_floating_point(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_floating_point(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_FLOAT;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @enumft.
@@ -353,8 +363,11 @@ extern bt_bool bt_field_type_is_floating_point(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_enumeration(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_enumeration(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ENUM;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @stringft.
@@ -369,8 +382,11 @@ extern bt_bool bt_field_type_is_enumeration(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_string(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_string(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRING;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @structft.
@@ -385,8 +401,11 @@ extern bt_bool bt_field_type_is_string(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_structure(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_structure(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRUCT;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @arrayft.
@@ -401,8 +420,11 @@ extern bt_bool bt_field_type_is_structure(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_array(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_array(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ARRAY;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @seqft.
@@ -417,8 +439,12 @@ extern bt_bool bt_field_type_is_array(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_sequence(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_sequence(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) ==
+               BT_FIELD_TYPE_ID_SEQUENCE;
+}
 
 /**
 @brief Returns whether or not the @ft \p field_type is a @varft.
@@ -433,8 +459,12 @@ extern bt_bool bt_field_type_is_sequence(
 @sa bt_field_type_get_type_id(): Returns the type ID of a given
        field type.
 */
-extern bt_bool bt_field_type_is_variant(
-               struct bt_field_type *field_type);
+static inline
+bt_bool bt_field_type_is_variant(struct bt_field_type *field_type)
+{
+       return bt_field_type_get_type_id(field_type) ==
+               BT_FIELD_TYPE_ID_VARIANT;
+}
 
 /** @} */
 
@@ -950,6 +980,9 @@ extern int bt_field_type_integer_set_encoding(
                struct bt_field_type *int_field_type,
                enum bt_string_encoding encoding);
 
+extern struct bt_clock_class *bt_field_type_integer_borrow_mapped_clock_class(
+               struct bt_field_type *int_field_type);
+
 /**
 @brief  Returns the \link ctfirclockclass CTF IR clock class\endlink
        mapped to the @intft \p int_field_type.
@@ -972,8 +1005,13 @@ This mapped clock class is only indicative.
 @sa bt_field_type_integer_set_mapped_clock_class(): Sets the mapped
        clock class of a given integer field type.
 */
-extern struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class(
-               struct bt_field_type *int_field_type);
+static inline
+struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class(
+               struct bt_field_type *int_field_type)
+{
+       return bt_get(bt_field_type_integer_borrow_mapped_clock_class(
+               int_field_type));
+}
 
 /**
 @brief Sets the \link ctfirclockclass CTF IR clock class\endlink mapped
@@ -1278,6 +1316,10 @@ the \c CHERRY mapping.
 extern struct bt_field_type *bt_field_type_enumeration_create(
                struct bt_field_type *int_field_type);
 
+extern
+struct bt_field_type *bt_field_type_enumeration_borrow_container_field_type(
+               struct bt_field_type *enum_field_type);
+
 /**
 @brief  Returns the @intft wrapped by the @enumft \p enum_field_type.
 
@@ -1292,9 +1334,13 @@ extern struct bt_field_type *bt_field_type_enumeration_create(
 @postrefcountsame{enum_field_type}
 @postsuccessrefcountretinc
 */
-extern
+static inline
 struct bt_field_type *bt_field_type_enumeration_get_container_field_type(
-               struct bt_field_type *enum_field_type);
+               struct bt_field_type *enum_field_type)
+{
+       return bt_get(bt_field_type_enumeration_borrow_container_field_type(
+               enum_field_type));
+}
 
 /**
 @brief  Returns the number of mappings contained in the
@@ -1898,6 +1944,11 @@ extern struct bt_field_type *bt_field_type_structure_create(void);
 extern int64_t bt_field_type_structure_get_field_count(
                struct bt_field_type *struct_field_type);
 
+extern int bt_field_type_structure_borrow_field_by_index(
+               struct bt_field_type *struct_field_type,
+               const char **field_name, struct bt_field_type **field_type,
+               uint64_t index);
+
 /**
 @brief Returns the field of the @structft \p struct_field_type
        at index \p index.
@@ -1929,10 +1980,26 @@ On success, the field's type is placed in \p *field_type if
 @sa bt_field_type_structure_get_field_type_by_name(): Finds a
        structure field type's field by name.
 */
-extern int bt_field_type_structure_get_field_by_index(
+static inline
+int bt_field_type_structure_get_field_by_index(
                struct bt_field_type *struct_field_type,
                const char **field_name, struct bt_field_type **field_type,
-               uint64_t index);
+               uint64_t index)
+{
+       int ret = bt_field_type_structure_borrow_field_by_index(
+               struct_field_type, field_name, field_type, index);
+
+       if (ret == 0 && field_type) {
+               bt_get(*field_type);
+       }
+
+       return ret;
+}
+
+extern
+struct bt_field_type *bt_field_type_structure_borrow_field_type_by_name(
+               struct bt_field_type *struct_field_type,
+               const char *field_name);
 
 /**
 @brief  Returns the type of the field named \p field_name found in
@@ -1954,10 +2021,14 @@ extern int bt_field_type_structure_get_field_by_index(
 @sa bt_field_type_structure_get_field_by_index(): Finds a
        structure field type's field by index.
 */
-extern
+static inline
 struct bt_field_type *bt_field_type_structure_get_field_type_by_name(
                struct bt_field_type *struct_field_type,
-               const char *field_name);
+               const char *field_name)
+{
+       return bt_get(bt_field_type_structure_borrow_field_type_by_name(
+               struct_field_type, field_name));
+}
 
 /**
 @brief Adds a field named \p field_name with the @ft
@@ -2042,6 +2113,9 @@ extern struct bt_field_type *bt_field_type_array_create(
                struct bt_field_type *element_field_type,
                unsigned int length);
 
+extern struct bt_field_type *bt_field_type_array_borrow_element_field_type(
+               struct bt_field_type *array_field_type);
+
 /**
 @brief Returns the @ft of the @fields contained in
        the @arrayfields described by the @arrayft \p array_field_type.
@@ -2059,8 +2133,13 @@ extern struct bt_field_type *bt_field_type_array_create(
 @postrefcountsame{array_field_type}
 @postsuccessrefcountretinc
 */
-extern struct bt_field_type *bt_field_type_array_get_element_field_type(
-               struct bt_field_type *array_field_type);
+static inline
+struct bt_field_type *bt_field_type_array_get_element_field_type(
+               struct bt_field_type *array_field_type)
+{
+       return bt_get(bt_field_type_array_borrow_element_field_type(
+               array_field_type));
+}
 
 /**
 @brief Returns the number of @fields contained in the
@@ -2134,6 +2213,9 @@ extern struct bt_field_type *bt_field_type_sequence_create(
                struct bt_field_type *element_field_type,
                const char *length_name);
 
+extern struct bt_field_type *bt_field_type_sequence_borrow_element_field_type(
+               struct bt_field_type *sequence_field_type);
+
 /**
 @brief Returns the @ft of the @fields contained in the @seqft
        described by the @seqft \p sequence_field_type.
@@ -2151,8 +2233,13 @@ extern struct bt_field_type *bt_field_type_sequence_create(
 @postrefcountsame{sequence_field_type}
 @postsuccessrefcountretinc
 */
-extern struct bt_field_type *bt_field_type_sequence_get_element_field_type(
-               struct bt_field_type *sequence_field_type);
+static inline
+struct bt_field_type *bt_field_type_sequence_get_element_field_type(
+               struct bt_field_type *sequence_field_type)
+{
+       return bt_get(bt_field_type_sequence_borrow_element_field_type(
+               sequence_field_type));
+}
 
 /**
 @brief  Returns the length name of the @seqft \p sequence_field_type.
@@ -2174,6 +2261,9 @@ the returned string.
 extern const char *bt_field_type_sequence_get_length_field_name(
                struct bt_field_type *sequence_field_type);
 
+extern struct bt_field_path *bt_field_type_sequence_borrow_length_field_path(
+               struct bt_field_type *sequence_field_type);
+
 /**
 @brief  Returns the length's CTF IR field path of the @seqft
        \p sequence_field_type.
@@ -2195,8 +2285,13 @@ resolving is performed (see \ref ctfirfieldtypes).
 @sa bt_field_type_sequence_get_length_field_name(): Returns the
        length's name of a given sequence field type.
 */
-extern struct bt_field_path *bt_field_type_sequence_get_length_field_path(
-               struct bt_field_type *sequence_field_type);
+static inline
+struct bt_field_path *bt_field_type_sequence_get_length_field_path(
+               struct bt_field_type *sequence_field_type)
+{
+       return bt_get(bt_field_type_sequence_borrow_length_field_path(
+               sequence_field_type));
+}
 
 /** @} */
 
@@ -2271,6 +2366,9 @@ extern struct bt_field_type *bt_field_type_variant_create(
                struct bt_field_type *tag_field_type,
                const char *tag_name);
 
+extern struct bt_field_type *bt_field_type_variant_borrow_tag_field_type(
+               struct bt_field_type *variant_field_type);
+
 /**
 @brief Returns the tag's @enumft of the @varft \p variant_field_type.
 
@@ -2286,8 +2384,13 @@ extern struct bt_field_type *bt_field_type_variant_create(
 @postrefcountsame{variant_field_type}
 @postsuccessrefcountretinc
 */
-extern struct bt_field_type *bt_field_type_variant_get_tag_field_type(
-               struct bt_field_type *variant_field_type);
+static inline
+struct bt_field_type *bt_field_type_variant_get_tag_field_type(
+               struct bt_field_type *variant_field_type)
+{
+       return bt_get(bt_field_type_variant_borrow_tag_field_type(
+               variant_field_type));
+}
 
 /**
 @brief  Returns the tag name of the @varft \p variant_field_type.
@@ -2336,6 +2439,9 @@ extern int bt_field_type_variant_set_tag_name(
                struct bt_field_type *variant_field_type,
                const char *tag_name);
 
+extern struct bt_field_path *bt_field_type_variant_borrow_tag_field_path(
+               struct bt_field_type *variant_field_type);
+
 /**
 @brief  Returns the tag's CTF IR field path of the @varft
        \p variant_field_type.
@@ -2357,8 +2463,13 @@ resolving is performed (see \ref ctfirfieldtypes).
 @sa bt_field_type_variant_get_tag_name(): Returns the tag's
        name of a given variant field type.
 */
-extern struct bt_field_path *bt_field_type_variant_get_tag_field_path(
-               struct bt_field_type *variant_field_type);
+static inline
+struct bt_field_path *bt_field_type_variant_get_tag_field_path(
+               struct bt_field_type *variant_field_type)
+{
+       return bt_get(bt_field_type_variant_borrow_tag_field_path(
+               variant_field_type));
+}
 
 /**
 @brief Returns the number of fields (choices) contained in the @varft
@@ -2377,6 +2488,11 @@ extern struct bt_field_path *bt_field_type_variant_get_tag_field_path(
 extern int64_t bt_field_type_variant_get_field_count(
                struct bt_field_type *variant_field_type);
 
+extern int bt_field_type_variant_borrow_field_by_index(
+               struct bt_field_type *variant_field_type,
+               const char **field_name,
+               struct bt_field_type **field_type, uint64_t index);
+
 /**
 @brief Returns the field (choice) of the @varft \p variant_field_type
        at index \p index.
@@ -2410,10 +2526,26 @@ On success, the field's type is placed in \p *field_type if
 @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant
        field type's field by current tag value.
 */
-extern int bt_field_type_variant_get_field_by_index(
+static inline
+int bt_field_type_variant_get_field_by_index(
                struct bt_field_type *variant_field_type,
                const char **field_name,
-               struct bt_field_type **field_type, uint64_t index);
+               struct bt_field_type **field_type, uint64_t index)
+{
+       int ret = bt_field_type_variant_borrow_field_by_index(
+               variant_field_type, field_name, field_type, index);
+
+       if (ret == 0 && field_type) {
+               bt_get(*field_type);
+       }
+
+       return ret;
+}
+
+extern
+struct bt_field_type *bt_field_type_variant_borrow_field_type_by_name(
+               struct bt_field_type *variant_field_type,
+               const char *field_name);
 
 /**
 @brief  Returns the type of the field (choice) named \p field_name
@@ -2437,10 +2569,19 @@ extern int bt_field_type_variant_get_field_by_index(
 @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant
        field type's field by current tag value.
 */
-extern
+static inline
 struct bt_field_type *bt_field_type_variant_get_field_type_by_name(
                struct bt_field_type *variant_field_type,
-               const char *field_name);
+               const char *field_name)
+{
+       return bt_get(bt_field_type_variant_borrow_field_type_by_name(
+               variant_field_type, field_name));
+}
+
+extern
+struct bt_field_type *bt_field_type_variant_borrow_field_type_from_tag(
+               struct bt_field_type *variant_field_type,
+               struct bt_field *tag_field);
 
 /**
 @brief  Returns the type of the field (choice) selected by the value of
@@ -2473,10 +2614,14 @@ bt_field_type_variant_get_tag_field_type() for \p variant_field_type.
 @sa bt_field_type_variant_get_field_type_by_name(): Finds a variant
        field type's field by name.
 */
-extern
+static inline
 struct bt_field_type *bt_field_type_variant_get_field_type_from_tag(
                struct bt_field_type *variant_field_type,
-               struct bt_field *tag_field);
+               struct bt_field *tag_field)
+{
+       return bt_get(bt_field_type_variant_borrow_field_type_from_tag(
+               variant_field_type, tag_field));
+}
 
 /**
 @brief Adds a field (a choice) named \p field_name with the @ft
This page took 0.0297 seconds and 4 git commands to generate.