summaryrefslogtreecommitdiff
path: root/endless
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2013-09-04 14:25:01 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2013-09-04 14:25:01 +0100
commitf419efd50898862a63c9f31a61115c5b6de79fec (patch)
tree760ce7800ef002a364c3b918bfff16be888e6029 /endless
parent2632895f60791dee126bd7898cec748c47a8d72c (diff)
Add EOS_DEFINE_ENUM_TYPE macro
A simple macro that allows you to define a GEnum type. If we start getting a ton of enumeration types, then we should consider adding the various autotooling hooks for generating them through the glib-mkenums script.
Diffstat (limited to 'endless')
-rw-r--r--endless/eosmacros.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/endless/eosmacros.h b/endless/eosmacros.h
index 7d85c15..1dfa786 100644
--- a/endless/eosmacros.h
+++ b/endless/eosmacros.h
@@ -9,4 +9,25 @@
/* Shared preprocessor macros */
+#define EOS_ENUM_VALUE(value, nick) { value, #value, #nick },
+
+#define EOS_DEFINE_ENUM_TYPE(EnumType, enum_type, values) \
+GType \
+enum_type##_get_type (void) \
+{ \
+ static volatile gsize g_define_type_id__volatile = 0; \
+ if (g_once_init_enter (&g_define_type_id__volatile)) \
+ { \
+ static const GEnumValue v[] = { \
+ values \
+ { 0, NULL, NULL }, \
+ }; \
+ GType g_define_type_id = \
+ g_enum_register_static (g_intern_static_string (#EnumType), v); \
+\
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
+ } \
+ return g_define_type_id__volatile; \
+}
+
#endif /* EOS_MACROS_H */