diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2023-04-27 12:19:18 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2023-04-27 12:23:04 +0000 |
commit | bf2843ad77732f5fbe1ee04e7ad5415a60bf5eeb (patch) | |
tree | d9be783f8a8e239652ea7837700d98dc6359765f /build-aux | |
parent | fdf03f9b2ccbc4a6a0a8102d44a991f78673e5a1 (diff) |
libmm-glib: separate files for flags and enums types
This allows us to skip needing to include the non-existent
build_string_from_mask() or get_string() counterparts in the
documentation index.
Diffstat (limited to 'build-aux')
-rw-r--r-- | build-aux/templates/mm-enums-types.c.template | 64 | ||||
-rw-r--r-- | build-aux/templates/mm-enums-types.h.template | 19 | ||||
-rw-r--r-- | build-aux/templates/mm-flags-types.c.template | 75 | ||||
-rw-r--r-- | build-aux/templates/mm-flags-types.h.template | 33 |
4 files changed, 116 insertions, 75 deletions
diff --git a/build-aux/templates/mm-enums-types.c.template b/build-aux/templates/mm-enums-types.c.template index 2a7f264b..e09d0c91 100644 --- a/build-aux/templates/mm-enums-types.c.template +++ b/build-aux/templates/mm-enums-types.c.template @@ -16,11 +16,6 @@ static const G@Type@Value @enum_name@_values[] = { { 0, NULL, NULL } }; -/* Define type-specific symbols */ -#undef __MM_IS_ENUM__ -#undef __MM_IS_FLAGS__ -#define __MM_IS_@TYPE@__ - GType @enum_name@_get_type (void) { @@ -36,15 +31,6 @@ GType return g_define_type_id_initialized; } -/** - * @enum_name@_get_string: - * @val: a @EnumName@. - * - * Gets the nickname string for the #@EnumName@ specified at @val. - * - * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value. - */ -#if defined __MM_IS_ENUM__ const gchar * @enum_name@_get_string (@EnumName@ val) { @@ -57,56 +43,6 @@ const gchar * return NULL; } -#endif /* __MM_IS_ENUM_ */ - -/** - * @enum_name@_build_string_from_mask: - * @mask: bitmask of @EnumName@ values. - * - * Builds a string containing a comma-separated list of nicknames for - * each #@EnumName@ in @mask. - * - * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free(). - */ -#if defined __MM_IS_FLAGS__ -gchar * -@enum_name@_build_string_from_mask (@EnumName@ mask) -{ - guint i; - gboolean first = TRUE; - GString *str = NULL; - - for (i = 0; @enum_name@_values[i].value_nick; i++) { - /* We also look for exact matches */ - if (mask == @enum_name@_values[i].value) { - if (str) - g_string_free (str, TRUE); - return g_strdup (@enum_name@_values[i].value_nick); - } - - /* Build list with single-bit masks */ - if (mask & @enum_name@_values[i].value) { - guint c; - gulong number = @enum_name@_values[i].value; - - for (c = 0; number; c++) - number &= number - 1; - - if (c == 1) { - if (!str) - str = g_string_new (""); - g_string_append_printf (str, "%s%s", - first ? "" : ", ", - @enum_name@_values[i].value_nick); - if (first) - first = FALSE; - } - } - } - - return (str ? g_string_free (str, FALSE) : NULL); -} -#endif /* __MM_IS_FLAGS__ */ /*** END value-tail ***/ diff --git a/build-aux/templates/mm-enums-types.h.template b/build-aux/templates/mm-enums-types.h.template index 24d18a9d..4c99eb9f 100644 --- a/build-aux/templates/mm-enums-types.h.template +++ b/build-aux/templates/mm-enums-types.h.template @@ -14,18 +14,15 @@ G_BEGIN_DECLS GType @enum_name@_get_type (void) G_GNUC_CONST; #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) -/* Define type-specific symbols */ -#undef __MM_IS_ENUM__ -#undef __MM_IS_FLAGS__ -#define __MM_IS_@TYPE@__ - -#if defined __MM_IS_ENUM__ +/** + * @enum_name@_get_string: + * @val: a @EnumName@. + * + * Gets the nickname string for the #@EnumName@ specified at @val. + * + * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value. + */ const gchar *@enum_name@_get_string (@EnumName@ val); -#endif - -#if defined __MM_IS_FLAGS__ -gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); -#endif /*** END value-header ***/ diff --git a/build-aux/templates/mm-flags-types.c.template b/build-aux/templates/mm-flags-types.c.template new file mode 100644 index 00000000..dce00905 --- /dev/null +++ b/build-aux/templates/mm-flags-types.c.template @@ -0,0 +1,75 @@ +/*** BEGIN file-header ***/ + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +static const G@Type@Value @enum_name@_values[] = { +/*** END value-header ***/ +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } +}; + +GType +@enum_name@_get_type (void) +{ + static gsize g_define_type_id_initialized = 0; + + if (g_once_init_enter (&g_define_type_id_initialized)) { + GType g_define_type_id = + g_@type@_register_static (g_intern_static_string ("@EnumName@"), + @enum_name@_values); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); + } + + return g_define_type_id_initialized; +} + +gchar * +@enum_name@_build_string_from_mask (@EnumName@ mask) +{ + guint i; + gboolean first = TRUE; + GString *str = NULL; + + for (i = 0; @enum_name@_values[i].value_nick; i++) { + /* We also look for exact matches */ + if (mask == @enum_name@_values[i].value) { + if (str) + g_string_free (str, TRUE); + return g_strdup (@enum_name@_values[i].value_nick); + } + + /* Build list with single-bit masks */ + if (mask & @enum_name@_values[i].value) { + guint c; + gulong number = @enum_name@_values[i].value; + + for (c = 0; number; c++) + number &= number - 1; + + if (c == 1) { + if (!str) + str = g_string_new (""); + g_string_append_printf (str, "%s%s", + first ? "" : ", ", + @enum_name@_values[i].value_nick); + if (first) + first = FALSE; + } + } + } + + return (str ? g_string_free (str, FALSE) : NULL); +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/build-aux/templates/mm-flags-types.h.template b/build-aux/templates/mm-flags-types.h.template new file mode 100644 index 00000000..b7ac597e --- /dev/null +++ b/build-aux/templates/mm-flags-types.h.template @@ -0,0 +1,33 @@ +/*** BEGIN file-header ***/ + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) + +/** + * @enum_name@_build_string_from_mask: + * @mask: bitmask of @EnumName@ values. + * + * Builds a string containing a comma-separated list of nicknames for + * each #@EnumName@ in @mask. + * + * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free(). + */ +gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); + +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +/*** END file-tail ***/ |