summaryrefslogtreecommitdiff
path: root/libdevkit-power
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-29 12:56:52 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-29 12:56:52 +0100
commit9ef076ef694409ae19eef1880ee37c23e9cc7c8a (patch)
tree30d656af82b7c20dac966795a9541a1f4e3694ab /libdevkit-power
parent38a050b01f1362aebbbfa9b303b5c99cb938d5bf (diff)
trivial: add some functionality to the EggObjList
Diffstat (limited to 'libdevkit-power')
-rw-r--r--libdevkit-power/egg-obj-list.c61
-rw-r--r--libdevkit-power/egg-obj-list.h7
2 files changed, 68 insertions, 0 deletions
diff --git a/libdevkit-power/egg-obj-list.c b/libdevkit-power/egg-obj-list.c
index cd12df2..31cd552 100644
--- a/libdevkit-power/egg-obj-list.c
+++ b/libdevkit-power/egg-obj-list.c
@@ -35,6 +35,8 @@ struct EggObjListPrivate
EggObjListNewFunc func_new;
EggObjListCopyFunc func_copy;
EggObjListFreeFunc func_free;
+ EggObjListToStringFunc func_to_string;
+ EggObjListFromStringFunc func_from_string;
GPtrArray *array;
};
@@ -83,6 +85,34 @@ egg_obj_list_set_free (EggObjList *list, EggObjListFreeFunc func)
}
/**
+ * egg_obj_list_set_to_string:
+ * @list: a valid #EggObjList instance
+ * @func: typedef'd function
+ *
+ * Adds a to string func
+ **/
+void
+egg_obj_list_set_to_string (EggObjList *list, EggObjListToStringFunc func)
+{
+ g_return_if_fail (EGG_IS_OBJ_LIST (list));
+ list->priv->func_to_string = func;
+}
+
+/**
+ * egg_obj_list_set_from_string:
+ * @list: a valid #EggObjList instance
+ * @func: typedef'd function
+ *
+ * Adds a from string func
+ **/
+void
+egg_obj_list_set_from_string (EggObjList *list, EggObjListFromStringFunc func)
+{
+ g_return_if_fail (EGG_IS_OBJ_LIST (list));
+ list->priv->func_from_string = func;
+}
+
+/**
* egg_obj_list_clear:
* @list: a valid #EggObjList instance
*
@@ -110,6 +140,35 @@ egg_obj_list_clear (EggObjList *list)
}
/**
+ * egg_obj_list_print:
+ * @list: a valid #EggObjList instance
+ *
+ * Prints the package list
+ **/
+void
+egg_obj_list_print (EggObjList *list)
+{
+ guint i;
+ gpointer obj;
+ GPtrArray *array;
+ gchar *text;
+ EggObjListToStringFunc func_to_string;
+
+ g_return_if_fail (list->priv->func_to_string != NULL);
+ g_return_if_fail (EGG_IS_OBJ_LIST (list));
+
+ array = list->priv->array;
+ func_to_string = list->priv->func_to_string;
+ for (i=0; i<array->len; i++) {
+ obj = g_ptr_array_index (array, i);
+ text = func_to_string (obj);
+ g_print ("%s\n", text);
+ g_free (text);
+ }
+ list->len = 0;
+}
+
+/**
* egg_obj_list_add:
* @list: a valid #EggObjList instance
* @obj: a valid #gpointer object
@@ -201,6 +260,8 @@ egg_obj_list_init (EggObjList *list)
list->priv->func_new = NULL;
list->priv->func_copy = NULL;
list->priv->func_free = NULL;
+ list->priv->func_to_string = NULL;
+ list->priv->func_from_string = NULL;
list->priv->array = g_ptr_array_new ();
list->len = list->priv->array->len;
}
diff --git a/libdevkit-power/egg-obj-list.h b/libdevkit-power/egg-obj-list.h
index d936b57..b712e55 100644
--- a/libdevkit-power/egg-obj-list.h
+++ b/libdevkit-power/egg-obj-list.h
@@ -50,6 +50,8 @@ typedef struct
typedef gpointer (*EggObjListNewFunc) (void);
typedef gpointer (*EggObjListCopyFunc) (const gpointer data);
typedef void (*EggObjListFreeFunc) (gpointer data);
+typedef gpointer (*EggObjListFromStringFunc) (const gchar *data);
+typedef gchar *(*EggObjListToStringFunc) (gpointer data);
GType egg_obj_list_get_type (void) G_GNUC_CONST;
EggObjList *egg_obj_list_new (void);
@@ -60,7 +62,12 @@ void egg_obj_list_set_copy (EggObjList *list,
EggObjListCopyFunc func);
void egg_obj_list_set_free (EggObjList *list,
EggObjListFreeFunc func);
+void egg_obj_list_set_to_string (EggObjList *list,
+ EggObjListToStringFunc func);
+void egg_obj_list_set_from_string (EggObjList *list,
+ EggObjListFromStringFunc func);
void egg_obj_list_clear (EggObjList *list);
+void egg_obj_list_print (EggObjList *list);
void egg_obj_list_add (EggObjList *list,
const gpointer data);
const gpointer egg_obj_list_index (EggObjList *list,