[couchdb-glib] Remove couchdb_document_foreach_attachment method, add couchdb_document_list_attachments



commit e4784f9cdeb498d7a4f253d02586881156b33671
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Feb 10 18:06:29 2011 +0100

    Remove couchdb_document_foreach_attachment method, add couchdb_document_list_attachments

 couchdb-glib/couchdb-document.c |   26 +++++++++++---------------
 couchdb-glib/couchdb-document.h |    8 +-------
 2 files changed, 12 insertions(+), 22 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index cdee82e..1a0a57e 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -583,35 +583,31 @@ couchdb_document_set_struct_field (CouchdbDocument *document, const char *field,
 }
 
 /**
- * couchdb_document_foreach_attachment:
+ * couchdb_document_list_attachments:
  * @document: A #CouchdbDocument object
- * @func: Callback function to be called for each attachment found
- * @user_data: Data to pass to callback function
  *
  * List all the attachments for the given document.
+ *
+ * Return value: A list containing the IDs of all the attachments for the
+ * given document. When no longer needed, the list should
+ * be freed by calling #g_slist_free.
  */
-void
-couchdb_document_foreach_attachment (CouchdbDocument *document,
-				     CouchdbDocumentForeachAttachmentFunc func,
-				     gpointer user_data)
+GSList *
+couchdb_document_list_attachments (CouchdbDocument *document)
 {
+	GSList *list = NULL;
 	CouchdbStructField *attachments;
 
-	g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
 
 	attachments = couchdb_document_get_struct_field (document, "_attachments");
 	if (attachments != NULL) {
-		GSList *list;
-
 		list = couchdb_struct_field_get_field_names (attachments);
-		while (list != NULL) {
-			func (document, (const gchar *) list->data, user_data);
-
-			list = g_slist_remove (list, list->data);
-		}
 
 		g_object_unref (G_OBJECT (attachments));
 	}
+
+	return list;
 }
 
 /**
diff --git a/couchdb-glib/couchdb-document.h b/couchdb-glib/couchdb-document.h
index 161b08a..a5cf391 100644
--- a/couchdb-glib/couchdb-document.h
+++ b/couchdb-glib/couchdb-document.h
@@ -77,13 +77,7 @@ void                couchdb_document_set_string_field (CouchdbDocument *document
 CouchdbStructField *couchdb_document_get_struct_field (CouchdbDocument *document, const char *field);
 void                couchdb_document_set_struct_field (CouchdbDocument *document, const char *field, CouchdbStructField *value);
 
-typedef void (* CouchdbDocumentForeachAttachmentFunc) (CouchdbDocument *document,
-						       const gchar *attachment_id,
-						       gpointer user_data);
-
-void                couchdb_document_foreach_attachment (CouchdbDocument *document,
-							 CouchdbDocumentForeachAttachmentFunc func,
-							 gpointer user_data);
+GSList             *couchdb_document_list_attachments (CouchdbDocument *document);
 
 char               *couchdb_document_to_string (CouchdbDocument *document);
 



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