[devhelp/wip/book-list] BookList: ensure that each book ID is unique



commit 07a912e4505a5f447b80e92a1d30d71bf946fbec
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Apr 25 17:08:08 2018 +0200

    BookList: ensure that each book ID is unique
    
    And document it.

 devhelp/dh-book-list.c |   14 +++++++++++++-
 devhelp/dh-book-list.h |    3 ++-
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/devhelp/dh-book-list.c b/devhelp/dh-book-list.c
index f0785f2..eb24276 100644
--- a/devhelp/dh-book-list.c
+++ b/devhelp/dh-book-list.c
@@ -47,6 +47,15 @@ static guint signals[N_SIGNALS] = { 0 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (DhBookList, dh_book_list, G_TYPE_OBJECT)
 
+static gboolean
+book_id_present_in_list (DhBookList *book_list,
+                         DhBook     *book)
+{
+        return g_list_find_custom (book_list->priv->books,
+                                   book,
+                                   (GCompareFunc) dh_book_cmp_by_id) != NULL;
+}
+
 static void
 dh_book_list_dispose (GObject *object)
 {
@@ -62,7 +71,7 @@ static void
 dh_book_list_add_book_default (DhBookList *book_list,
                                DhBook     *book)
 {
-        g_return_if_fail (g_list_find (book_list->priv->books, book) == NULL);
+        g_return_if_fail (!book_id_present_in_list (book_list, book));
 
         book_list->priv->books = g_list_prepend (book_list->priv->books,
                                                  g_object_ref (book));
@@ -159,6 +168,9 @@ dh_book_list_init (DhBookList *book_list)
  * dh_book_list_get_books:
  * @book_list: a #DhBookList.
  *
+ * Gets the list of #DhBook's part of @book_list. Each book ID in the list is
+ * unique (see dh_book_get_id()).
+ *
  * Returns: (transfer none) (element-type DhBook): the #GList of #DhBook's part
  * of @book_list.
  * Since: 3.30
diff --git a/devhelp/dh-book-list.h b/devhelp/dh-book-list.h
index 8e27a97..c2c7c4b 100644
--- a/devhelp/dh-book-list.h
+++ b/devhelp/dh-book-list.h
@@ -50,7 +50,8 @@ struct _DhBookList {
  * @remove_book: Virtual function pointer for the #DhBookList::remove-book
  *   signal.
  * @get_books: Virtual function pointer for dh_book_list_get_books(). Returns
- *   the #DhBookList internal #GList by default.
+ *   the #DhBookList internal #GList by default. If you override this vfunc
+ *   ensure that each book ID is unique in the returned list.
  */
 struct _DhBookListClass {
         GObjectClass parent_class;


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