[libvirt-gconfig PATCHv2 10/32] Add gvir_config_genum_get_nick helper

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

 



We will often need to convert from an enum to its string
representation, add an helper for that to avoid duplicating that
code.

--
v2: moved before gvir_config_clock_set_offset implementation since
it needs it
---
 libvirt-gconfig/libvirt-gconfig-helpers-private.h |    1 +
 libvirt-gconfig/libvirt-gconfig-helpers.c         |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
index c7a5d6a..59efd24 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
@@ -40,6 +40,7 @@ xmlChar * gvir_config_xml_get_child_element_content (xmlNode    *node,
                                                      const char *child_name);
 char *gvir_config_xml_get_child_element_content_glib (xmlNode    *node,
                                                       const char *child_name);
+const char *gvir_config_genum_get_nick (GType enum_type, gint value);
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_HELPERS_PRIVATE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 2e28429..d7e1140 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -178,3 +178,20 @@ gvir_config_xml_get_child_element_content_glib (xmlNode    *node,
 
         return copy;
 }
+
+const char *gvir_config_genum_get_nick (GType enum_type, gint value)
+{
+    GEnumClass *enum_class;
+    GEnumValue *enum_value;
+
+    g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
+
+    enum_class = g_type_class_ref(enum_type);
+    enum_value = g_enum_get_value(enum_class, value);
+    g_type_class_unref(enum_class);
+
+    if (enum_value != NULL)
+        return enum_value->value_nick;
+
+    g_return_val_if_reached(NULL);
+}
-- 
1.7.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]