From 80a0403ebb3f273a3bb373f47756c047f9c7834e Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sat, 28 Apr 2007 02:40:54 +0000 Subject: [PATCH] Collapse two functions into their only caller. Move a third function to the same file. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16003 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/qofid.c | 54 ------------------------------------ lib/libqof/qof/qofid.h | 3 -- lib/libqof/qof/qofinstance.c | 46 ++++++++++++++++++++++++++++-- lib/libqof/qof/qofinstance.h | 3 ++ 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/lib/libqof/qof/qofid.c b/lib/libqof/qof/qofid.c index 7eff69dd31..445777d3ad 100644 --- a/lib/libqof/qof/qofid.c +++ b/lib/libqof/qof/qofid.c @@ -58,60 +58,6 @@ qof_set_alt_dirty_mode (gboolean enabled) /* =============================================================== */ -void -qof_entity_init (QofInstance *ent, QofIdType type, QofCollection * tab) -{ - g_return_if_fail (NULL != tab); - - /* XXX We passed redundant info to this routine ... but I think that's - * OK, it might eliminate programming errors. */ - if (safe_strcmp(tab->e_type, type)) - { - PERR ("attempt to insert \"%s\" into \"%s\"", type, tab->e_type); - return; - } - ent->e_type = CACHE_INSERT (type); - - do - { - guid_new(&ent->guid); - - if (NULL == qof_collection_lookup_entity (tab, &ent->guid)) break; - - PWARN("duplicate id created, trying again"); - } while(1); - - ent->collection = tab; - - qof_collection_insert_entity (tab, ent); -} - -void -qof_entity_release (QofInstance *ent) -{ - if (!ent->collection) return; - qof_collection_remove_entity (ent); - CACHE_REMOVE (ent->e_type); - ent->e_type = NULL; -} - - -/* This is a restricted function, should be used only during - * read from file */ -void -qof_instance_set_guid (QofInstance *ent, const GUID *guid) -{ - QofCollection *col; - if (guid_equal (guid, &ent->guid)) return; - - col = ent->collection; - qof_collection_remove_entity (ent); - ent->guid = *guid; - qof_collection_insert_entity (col, ent); -} - -/* =============================================================== */ - static guint id_hash (gconstpointer key) { diff --git a/lib/libqof/qof/qofid.h b/lib/libqof/qof/qofid.h index 90106b8829..f78ff0f491 100644 --- a/lib/libqof/qof/qofid.h +++ b/lib/libqof/qof/qofid.h @@ -134,9 +134,6 @@ print error message if its bad */ @param data gpointer, place where object class can hang arbitrary data */ -void qof_entity_init (QofInstance *ent, QofIdType type, QofCollection * tab); -void qof_entity_release (QofInstance *ent); -void qof_instance_set_guid (QofInstance *ent, const GUID *guid); /** Is QOF operating in "alternate" dirty mode. In normal mode, * whenever an instance is dirtied, the collection (and therefore the diff --git a/lib/libqof/qof/qofinstance.c b/lib/libqof/qof/qofinstance.c index 62ae1a834e..9a13e1611b 100644 --- a/lib/libqof/qof/qofinstance.c +++ b/lib/libqof/qof/qofinstance.c @@ -67,19 +67,49 @@ void qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book) { QofCollection *col; + QofIdType col_type; + g_return_if_fail(QOF_IS_INSTANCE(inst)); g_return_if_fail(!inst->book); inst->book = book; col = qof_book_get_collection (book, type); - qof_entity_init (inst, type, col); + g_return_if_fail(col != NULL); + + /* XXX We passed redundant info to this routine ... but I think that's + * OK, it might eliminate programming errors. */ + + col_type = qof_collection_get_type(col); + if (safe_strcmp(col_type, type)) { + PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type); + return; + } + inst->e_type = CACHE_INSERT (type); + + do { + guid_new(&inst->guid); + + if (NULL == qof_collection_lookup_entity (col, &inst->guid)) + break; + + PWARN("duplicate id created, trying again"); + } while(1); + + inst->collection = col; + + qof_collection_insert_entity (col, inst); } static void qof_instance_dispose (GObject *instp) { QofInstance* inst = QOF_INSTANCE(instp); - qof_entity_release (inst); + + if (!inst->collection) + return; + qof_collection_remove_entity(inst); + CACHE_REMOVE(inst->e_type); + inst->e_type = NULL; G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp); } @@ -109,6 +139,18 @@ qof_instance_get_book (const QofInstance *inst) return inst->book; } +void +qof_instance_set_guid (QofInstance *ent, const GUID *guid) +{ + QofCollection *col; + if (guid_equal (guid, &ent->guid)) return; + + col = ent->collection; + qof_collection_remove_entity(ent); + ent->guid = *guid; + qof_collection_insert_entity(col, ent); +} + KvpFrame* qof_instance_get_slots (const QofInstance *inst) { diff --git a/lib/libqof/qof/qofinstance.h b/lib/libqof/qof/qofinstance.h index ceb2d83f09..a669638a16 100644 --- a/lib/libqof/qof/qofinstance.h +++ b/lib/libqof/qof/qofinstance.h @@ -119,6 +119,9 @@ QofBook * qof_instance_get_book (const QofInstance *); /** Return the GUID of this instance */ const GUID * qof_instance_get_guid (const QofInstance *); +/** Set the GUID of this instance */ +void qof_instance_set_guid (QofInstance *ent, const GUID *guid); + /** Return the pointer to the kvp_data */ KvpFrame* qof_instance_get_slots (const QofInstance *);