[glib/ebassi/enum-type-macros: 8/9] Use varargs for enum types definition macros




commit c0766caf20360ce64f648f5fa42bd8f6e7509ac2
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Jun 29 17:57:32 2022 +0100

    Use varargs for enum types definition macros
    
    Makes the syntax a little bit better.

 gobject/genums.h      | 26 +++++++++++++-------------
 gobject/tests/enums.c | 10 +++++-----
 2 files changed, 18 insertions(+), 18 deletions(-)
---
diff --git a/gobject/genums.h b/gobject/genums.h
index 2cd5000f9c..a28758a728 100644
--- a/gobject/genums.h
+++ b/gobject/genums.h
@@ -288,13 +288,13 @@ void      g_flags_complete_type_info (GType              g_flags_type,
  *
  * Since: 2.74
  */
-#define G_DEFINE_ENUM_VALUE(EnumValue, EnumNick) { EnumValue, #EnumValue, EnumNick },
+#define G_DEFINE_ENUM_VALUE(EnumValue, EnumNick) { EnumValue, #EnumValue, EnumNick }
 
 /**
  * G_DEFINE_ENUM_TYPE:
  * @TypeName: the enumeration type, in `CamelCase`
  * @type_name: the enumeration type prefixed, in `snake_case`
- * @values: a list of enumeration values, defined using G_DEFINE_ENUM_VALUE()
+ * @...: a list of enumeration values, defined using G_DEFINE_ENUM_VALUE()
  *
  * A convenience macro for defining enumeration types.
  *
@@ -303,7 +303,7 @@ void        g_flags_complete_type_info (GType              g_flags_type,
  *
  * |[<!-- language="C" -->
  * G_DEFINE_ENUM_TYPE (GtkOrientation, gtk_orientation,
- *   G_DEFINE_ENUM_VALUE (GTK_ORIENTATION_HORIZONTAL, "horizontal")
+ *   G_DEFINE_ENUM_VALUE (GTK_ORIENTATION_HORIZONTAL, "horizontal"),
  *   G_DEFINE_ENUM_VALUE (GTK_ORIENTATION_VERTICAL, "vertical"))
  * ]|
  *
@@ -313,13 +313,13 @@ void      g_flags_complete_type_info (GType              g_flags_type,
  *
  * Since: 2.74
  */
-#define G_DEFINE_ENUM_TYPE(TypeName, type_name, values) \
+#define G_DEFINE_ENUM_TYPE(TypeName, type_name, ...) \
 GType \
 type_name ## _get_type (void) { \
   static gsize g_define_type__static = 0; \
   if (g_once_init_enter (&g_define_type__static)) { \
     static const GEnumValue enum_values[] = { \
-      values \
+      __VA_ARGS__ , \
       { 0, NULL, NULL }, \
     }; \
     GType g_define_type = g_enum_register_static (g_intern_static_string (#TypeName), enum_values); \
@@ -332,7 +332,7 @@ type_name ## _get_type (void) { \
  * G_DEFINE_FLAGS_TYPE:
  * @TypeName: the enumeration type, in `CamelCase`
  * @type_name: the enumeration type prefixed, in `snake_case`
- * @values: a list of enumeration values, defined using G_DEFINE_ENUM_VALUE()
+ * @...: a list of enumeration values, defined using G_DEFINE_ENUM_VALUE()
  *
  * A convenience macro for defining flag types.
  *
@@ -341,11 +341,11 @@ type_name ## _get_type (void) { \
  *
  * |[<!-- language="C" -->
  * G_DEFINE_FLAGS_TYPE (GSettingsBindFlags, g_settings_bind_flags,
- *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_DEFAULT, "default")
- *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_GET, "get")
- *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_SET, "set")
- *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_NO_SENSITIVITY, "no-sensitivity")
- *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_GET_NO_CHANGES, "get-no-changes")
+ *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_DEFAULT, "default"),
+ *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_GET, "get"),
+ *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_SET, "set"),
+ *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_NO_SENSITIVITY, "no-sensitivity"),
+ *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_GET_NO_CHANGES, "get-no-changes"),
  *   G_DEFINE_ENUM_VALUE (G_SETTINGS_BIND_INVERT_BOOLEAN, "invert-boolean"))
  * ]|
  *
@@ -355,13 +355,13 @@ type_name ## _get_type (void) { \
  *
  * Since: 2.74
  */
-#define G_DEFINE_FLAGS_TYPE(TypeName, type_name, values) \
+#define G_DEFINE_FLAGS_TYPE(TypeName, type_name, ...) \
 GType \
 type_name ## _get_type (void) { \
   static gsize g_define_type__static = 0; \
   if (g_once_init_enter (&g_define_type__static)) { \
     static const GFlagsValue flags_values[] = { \
-      values \
+      __VA_ARGS__ , \
       { 0, NULL, NULL }, \
     }; \
     GType g_define_type = g_flags_register_static (g_intern_static_string (#TypeName), flags_values); \
diff --git a/gobject/tests/enums.c b/gobject/tests/enums.c
index 0c465172db..9ec1666d08 100644
--- a/gobject/tests/enums.c
+++ b/gobject/tests/enums.c
@@ -167,8 +167,8 @@ typedef enum {
 GType test_enum_get_type (void);
 
 G_DEFINE_ENUM_TYPE (TestEnum, test_enum,
-  G_DEFINE_ENUM_VALUE (TEST_ENUM_FIRST_VALUE, "first-value")
-  G_DEFINE_ENUM_VALUE (TEST_ENUM_SECOND_VALUE, "second-value")
+  G_DEFINE_ENUM_VALUE (TEST_ENUM_FIRST_VALUE, "first-value"),
+  G_DEFINE_ENUM_VALUE (TEST_ENUM_SECOND_VALUE, "second-value"),
   G_DEFINE_ENUM_VALUE (TEST_ENUM_THIRD_VALUE, "third-value"))
 
 static void
@@ -200,9 +200,9 @@ typedef enum {
 GType test_flags_get_type (void);
 
 G_DEFINE_FLAGS_TYPE (TestFlags, test_flags,
-  G_DEFINE_ENUM_VALUE (TEST_FLAGS_DEFAULT, "default")
-  G_DEFINE_ENUM_VALUE (TEST_FLAGS_FIRST, "first")
-  G_DEFINE_ENUM_VALUE (TEST_FLAGS_SECOND, "second")
+  G_DEFINE_ENUM_VALUE (TEST_FLAGS_DEFAULT, "default"),
+  G_DEFINE_ENUM_VALUE (TEST_FLAGS_FIRST, "first"),
+  G_DEFINE_ENUM_VALUE (TEST_FLAGS_SECOND, "second"),
   G_DEFINE_ENUM_VALUE (TEST_FLAGS_THIRD, "third"))
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]