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

2011-11-21 Thread Christophe Fergeau
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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


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

2011-11-22 Thread Daniel P. Berrange
On Mon, Nov 21, 2011 at 07:04:07PM +0100, Christophe Fergeau wrote:
> 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(-)

ACK

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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