From aee3597d533fe2853cf54b67210888cd9796b7eb Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 18 Oct 2003 14:12:59 +0000 Subject: [PATCH] add a book-foreach-collection routine git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9552 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/qofbook.c | 29 +++++++++++++++++++++++++++++ src/engine/qofbook.h | 7 ++++++- src/engine/qofid.h | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/engine/qofbook.c b/src/engine/qofbook.c index 81d09746c0..a21e34fe12 100644 --- a/src/engine/qofbook.c +++ b/src/engine/qofbook.c @@ -236,6 +236,35 @@ qof_book_get_collection (QofBook *book, QofIdType entity_type) return col; } +struct _iterate { + QofCollectionForeachCB fn; + gpointer data; +}; + +static void +foreach_cb (gpointer key, gpointer item, gpointer arg) +{ + struct _iterate *iter = arg; + QofCollection *col = item; + + iter->fn (col, iter->data); +} + +void +qof_book_foreach_collection (QofBook *book, + QofCollectionForeachCB cb, gpointer user_data) +{ + struct _iterate iter; + + g_return_if_fail (book); + g_return_if_fail (cb); + + iter.fn = cb; + iter.data = user_data; + + g_hash_table_foreach (book->hash_of_collections, foreach_cb, &iter); +} + /* ====================================================================== */ gint64 diff --git a/src/engine/qofbook.h b/src/engine/qofbook.h index 33fd7bda8c..503011336d 100644 --- a/src/engine/qofbook.h +++ b/src/engine/qofbook.h @@ -59,9 +59,13 @@ QofBook * qof_book_new (void); associated with it. */ void qof_book_destroy (QofBook *book); -/** \return The Entity table for the book. */ +/** \return The table of entities of the given type. */ QofCollection * qof_book_get_collection (QofBook *, QofIdType); +/** Invoke the indicated callback on each collection in the book. */ +typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data); +void qof_book_foreach_collection (QofBook *, QofCollectionForeachCB, gpointer); + /** \return The kvp data for the book */ KvpFrame * qof_book_get_slots (QofBook *book); @@ -77,6 +81,7 @@ gpointer qof_book_get_data (QofBook *book, const char *key); /** DOCUMENT ME! */ QofBackend *qof_book_get_backend (QofBook *book); + void qof_book_set_backend (QofBook *book, QofBackend *); /** qof_book_not_saved() will return TRUE if any diff --git a/src/engine/qofid.h b/src/engine/qofid.h index 0bf55cc2bd..a8ec4b7bfd 100644 --- a/src/engine/qofid.h +++ b/src/engine/qofid.h @@ -95,9 +95,10 @@ QofIdType qof_collection_get_type (QofCollection *); /** Find the entity going only from its guid */ QofEntity * qof_collection_lookup_entity (QofCollection *, const GUID *); -/* Callback type for qof_entity_foreach */ +/** Callback type for qof_entity_foreach */ typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data); +/** Call the callback for each entity in the collection. */ void qof_collection_foreach (QofCollection *, QofEntityForeachCB, gpointer user_data);