diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-26 13:39:21 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-26 14:24:00 +0200 |
commit | b043619eb0d12ff998cc6485801241827f1c20d7 (patch) | |
tree | 9bdc73cf85a41425a5c71b477d62f94b10cc0983 /build-aux/templates | |
parent | b8c067d07aed3b82d95d88e2f3b17078ca878837 (diff) | |
download | external_libqmi-b043619eb0d12ff998cc6485801241827f1c20d7.zip external_libqmi-b043619eb0d12ff998cc6485801241827f1c20d7.tar.gz external_libqmi-b043619eb0d12ff998cc6485801241827f1c20d7.tar.bz2 |
build: autogenerate 64bit flags helpers
Diffstat (limited to 'build-aux/templates')
-rw-r--r-- | build-aux/templates/Makefile.am | 4 | ||||
-rw-r--r-- | build-aux/templates/qmi-flags64-types-template.c | 66 | ||||
-rw-r--r-- | build-aux/templates/qmi-flags64-types-template.h | 22 |
3 files changed, 91 insertions, 1 deletions
diff --git a/build-aux/templates/Makefile.am b/build-aux/templates/Makefile.am index 110e8e3..e1fcfd1 100644 --- a/build-aux/templates/Makefile.am +++ b/build-aux/templates/Makefile.am @@ -3,4 +3,6 @@ EXTRA_DIST = \ qmi-error-types-template.h \ qmi-error-types-template.c \ qmi-enum-types-template.h \ - qmi-enum-types-template.c + qmi-enum-types-template.c \ + qmi-flags64-types-template.h \ + qmi-flags64-types-template.c diff --git a/build-aux/templates/qmi-flags64-types-template.c b/build-aux/templates/qmi-flags64-types-template.c new file mode 100644 index 0000000..e8feb96 --- /dev/null +++ b/build-aux/templates/qmi-flags64-types-template.c @@ -0,0 +1,66 @@ +/*** BEGIN file-header ***/ + +typedef struct { + guint64 value; + const gchar *value_name; + const gchar *value_nick; +} GFlags64Value; + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +static const GFlags64Value @enum_name@_values[] = { +/*** END value-header ***/ +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } +}; + +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/qmi-flags64-types-template.h b/build-aux/templates/qmi-flags64-types-template.h new file mode 100644 index 0000000..20d44a7 --- /dev/null +++ b/build-aux/templates/qmi-flags64-types-template.h @@ -0,0 +1,22 @@ +/*** BEGIN file-header ***/ + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ + +gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); + +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +/*** END file-tail ***/ |