soylent r263 - trunk/libsoylent



Author: svenp
Date: Mon Aug  4 17:30:24 2008
New Revision: 263
URL: http://svn.gnome.org/viewvc/soylent?rev=263&view=rev

Log:
added utility functions for printing lists and hash-tables
added utility functions to compare lists

Modified:
   trunk/libsoylent/sl-priv-util.c
   trunk/libsoylent/sl-priv-util.h

Modified: trunk/libsoylent/sl-priv-util.c
==============================================================================
--- trunk/libsoylent/sl-priv-util.c	(original)
+++ trunk/libsoylent/sl-priv-util.c	Mon Aug  4 17:30:24 2008
@@ -22,6 +22,9 @@
  */
 
 #include "sl-priv-util.h"
+#include "sl-attribute-eds.h"
+
+static GEqualFunc compare_equal;
 
 ESource *
 sl_priv_util_get_source (ESourceList *source_tree, const gchar *name)
@@ -54,3 +57,85 @@
   g_assert (groups != NULL);
   return groups->data;
 }
+
+gboolean sl_priv_util_lists_equal (GList *a, GList *b, GEqualFunc equal)
+{
+  while (a != NULL && b != NULL)
+    {
+      if (!equal (a->data, b->data))
+        {
+          return FALSE;
+        }
+      a = a->next;
+      b = b->next;
+    }
+  
+  return (a == b);
+}
+
+static gint
+sl_priv_util_compare_by_equal (gconstpointer a, gconstpointer b)
+{
+  return !compare_equal (a, b);
+}
+
+gboolean
+sl_priv_util_list_contains (GList *list, gpointer data, GEqualFunc equal)
+{
+  compare_equal = equal;
+  return (g_list_find_custom (list, data, sl_priv_util_compare_by_equal) != NULL);
+}
+
+void
+sl_priv_util_list_print (GList *list, const gchar *title)
+{
+  g_print ("%s (%d):\n", title, g_list_length (list));
+  for (; list != NULL; list = list->next)
+    {
+      g_print (" * %s\n", (gchar *) list->data);
+    }
+}
+
+void
+sl_priv_util_eattribute_list_print (GList *eattributes, const gchar *title)
+{
+  g_print ("%s (%d):\n", title, g_list_length (eattributes));
+  for (; eattributes != NULL; eattributes = eattributes->next)
+    {
+      EVCardAttribute *eattr = eattributes->data;
+      g_print (" * %s\n", e_vcard_attribute_get_name (eattr));
+    }
+}
+
+void
+sl_priv_util_attribute_list_print (GList *attributes, const gchar *title)
+{
+  g_print ("%s (%d):\n", title, g_list_length (attributes));
+  for (; attributes != NULL; attributes = attributes->next)
+    {
+      SlAttribute *attr = attributes->data;
+      g_print (" * %s\n", sl_attribute_get_name (attr));
+    }
+}
+
+void
+sl_priv_util_hash_table_print (GHashTable *table, const gchar *title)
+{
+  GHashTableIter iter;
+  gpointer key = NULL;
+  gpointer value = NULL;
+  g_hash_table_iter_init (&iter, table);
+  g_print ("%s:\n", title);
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      g_print (" * %s : %.8x\n", (gchar *) key, (guint) value);
+    }
+}
+
+void
+sl_priv_util_hash_table_print_keys (GHashTable *table, const gchar *title)
+{
+  GList *keys = g_hash_table_get_keys (table);
+  sl_priv_util_list_print (keys, title);
+  g_list_free (keys);
+}

Modified: trunk/libsoylent/sl-priv-util.h
==============================================================================
--- trunk/libsoylent/sl-priv-util.h	(original)
+++ trunk/libsoylent/sl-priv-util.h	Mon Aug  4 17:30:24 2008
@@ -34,4 +34,12 @@
 ESourceGroup *sl_priv_util_source_tree_get_default_group
   (ESourceList *source_tree);
 
+gboolean sl_priv_util_lists_equal (GList *a, GList *b, GEqualFunc equal);
+gboolean sl_priv_util_list_contains (GList *list, gpointer data, GEqualFunc equal);
+void sl_priv_util_hash_table_print (GHashTable *table, const gchar *title);
+void sl_priv_util_hash_table_print_keys (GHashTable *table, const gchar *title);
+void sl_priv_util_list_print (GList *list, const gchar *title);
+void sl_priv_util_eattribute_list_print (GList *eattributes, const gchar *title);
+void sl_priv_util_attribute_list_print (GList *attributes, const gchar *title);
+
 #endif



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