[grilo] Add function to get a GList from a varadic list of pointers



commit a6d3c05ed90c84bffee0c5d36655db98f3d03abf
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Fri Jul 2 13:17:08 2010 +0200

    Add function to get a GList from a varadic list of pointers
    
    grl_metadata_key_list_new() is defined as a macro for this function.
    
    It can be useful to create quickly a list of sources, metadata keys, etc.

 src/grl-metadata-key.c |   18 ------------------
 src/grl-metadata-key.h |   14 ++++++--------
 src/grl-util.c         |   26 ++++++++++++++++++++++++++
 src/grl-util.h         |    2 ++
 4 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index 6e2931f..5774180 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -52,24 +52,6 @@ GrlKeyID GRL_METADATA_KEY_WIDTH = NULL;
 GrlKeyID GRL_METADATA_KEY_FRAMERATE = NULL;
 GrlKeyID GRL_METADATA_KEY_RATING = NULL;
 
-GList *
-grl_metadata_key_list_new (GrlKeyID first_key, ...)
-{
-  GList *keylist = NULL;
-  GrlKeyID key;
-  va_list vakeys;
-
-  key = first_key;
-  va_start (vakeys, first_key);
-  while (key) {
-    keylist = g_list_prepend (keylist, key);
-    key = va_arg (vakeys, GrlKeyID);
-  }
-  va_end (vakeys);
-
-  return g_list_reverse (keylist);
-}
-
 void
 grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
 {
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index dc3f45b..2b07ad2 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -37,6 +37,12 @@
 
 #define GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN -1
 
+#define GRL_KEYID_FORMAT "p"
+
+#define grl_metadata_key_list_new(first_key, ...)       \
+  grl_list_from_va(first_key, ##__VA_ARGS__)
+
+
 typedef GParamSpec* GrlKeyID;
 
 extern GrlKeyID GRL_METADATA_KEY_TITLE;
@@ -64,12 +70,4 @@ extern GrlKeyID GRL_METADATA_KEY_PLAY_COUNT;
 extern GrlKeyID GRL_METADATA_KEY_LAST_PLAYED;
 extern GrlKeyID GRL_METADATA_KEY_LAST_POSITION;
 
-#define GRL_KEYID_FORMAT "p"
-
-G_BEGIN_DECLS
-
-GList *grl_metadata_key_list_new (GrlKeyID first_key, ...);
-
-G_END_DECLS
-
 #endif /* _GRL_METADATA_KEY_H_ */
diff --git a/src/grl-util.c b/src/grl-util.c
index 7807813..6b60a87 100644
--- a/src/grl-util.c
+++ b/src/grl-util.c
@@ -83,3 +83,29 @@ void grl_paging_translate (guint skip,
     *internal_offset = skip%_page_size;
   }
 }
+
+/**
+ * grl_list_from_va:
+ * @p: first pointer
+ *
+ * Returns a #GList containing the va_list pointers. Use @NULL to finalize them,
+ *
+ * Returns: a #GList.
+ **/
+GList *
+grl_list_from_va (gpointer p, ...)
+{
+  GList *pointer_list = NULL;
+  gpointer next_pointer;
+  va_list va_pointers;
+
+  va_start (va_pointers, p);
+  next_pointer = p;
+  while (next_pointer) {
+    pointer_list = g_list_prepend (pointer_list, next_pointer);
+    next_pointer = va_arg (va_pointers, gpointer);
+  }
+  va_end (va_pointers);
+
+  return g_list_reverse (pointer_list);
+}
diff --git a/src/grl-util.h b/src/grl-util.h
index a3f81ee..2d27ba3 100644
--- a/src/grl-util.h
+++ b/src/grl-util.h
@@ -38,6 +38,8 @@ void grl_paging_translate (guint skip,
                            guint *page_number,
                            guint *internal_offset);
 
+GList *grl_list_from_va (gpointer p, ...);
+
 G_END_DECLS
 
 #endif /* _GRL_UTIL_H_ */



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