r16003 - gnucash/trunk/lib/libqof/qof - Collapse two functions into their only caller. Move a third function

David Hampton hampton at cvs.gnucash.org
Fri Apr 27 22:40:56 EDT 2007


Author: hampton
Date: 2007-04-27 22:40:54 -0400 (Fri, 27 Apr 2007)
New Revision: 16003
Trac: http://svn.gnucash.org/trac/changeset/16003

Modified:
   gnucash/trunk/lib/libqof/qof/qofid.c
   gnucash/trunk/lib/libqof/qof/qofid.h
   gnucash/trunk/lib/libqof/qof/qofinstance.c
   gnucash/trunk/lib/libqof/qof/qofinstance.h
Log:
Collapse two functions into their only caller.  Move a third function
to the same file.


Modified: gnucash/trunk/lib/libqof/qof/qofid.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.c	2007-04-27 16:54:47 UTC (rev 16002)
+++ gnucash/trunk/lib/libqof/qof/qofid.c	2007-04-28 02:40:54 UTC (rev 16003)
@@ -58,60 +58,6 @@
 
 /* =============================================================== */
 
-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)
 {

Modified: gnucash/trunk/lib/libqof/qof/qofid.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.h	2007-04-27 16:54:47 UTC (rev 16002)
+++ gnucash/trunk/lib/libqof/qof/qofid.h	2007-04-28 02:40:54 UTC (rev 16003)
@@ -134,9 +134,6 @@
 @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

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-04-27 16:54:47 UTC (rev 16002)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-04-28 02:40:54 UTC (rev 16003)
@@ -67,19 +67,49 @@
 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 @@
 	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)
 {

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-04-27 16:54:47 UTC (rev 16002)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-04-28 02:40:54 UTC (rev 16003)
@@ -119,6 +119,9 @@
 /** 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 *);
 



More information about the gnucash-changes mailing list