r16025 - gnucash/trunk - Start putting an API in place for access to the members of the

David Hampton hampton at cvs.gnucash.org
Mon Apr 30 01:33:35 EDT 2007


Author: hampton
Date: 2007-04-30 01:33:33 -0400 (Mon, 30 Apr 2007)
New Revision: 16025
Trac: http://svn.gnucash.org/trac/changeset/16025

Modified:
   gnucash/trunk/lib/libqof/qof/qofinstance.c
   gnucash/trunk/lib/libqof/qof/qofinstance.h
   gnucash/trunk/src/backend/postgres/account.c
   gnucash/trunk/src/backend/postgres/price.c
   gnucash/trunk/src/backend/postgres/txn.c
   gnucash/trunk/src/business/business-core/gncAddress.c
   gnucash/trunk/src/business/business-core/gncBillTerm.c
   gnucash/trunk/src/business/business-core/gncCustomer.c
   gnucash/trunk/src/business/business-core/gncEmployee.c
   gnucash/trunk/src/business/business-core/gncEntry.c
   gnucash/trunk/src/business/business-core/gncInvoice.c
   gnucash/trunk/src/business/business-core/gncJob.c
   gnucash/trunk/src/business/business-core/gncOrder.c
   gnucash/trunk/src/business/business-core/gncTaxTable.c
   gnucash/trunk/src/business/business-core/gncVendor.c
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Scrub2.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/cap-gains.c
   gnucash/trunk/src/engine/gnc-budget.c
   gnucash/trunk/src/engine/gnc-pricedb.c
Log:
Start putting an API in place for access to the members of the
QofInstance object.


Modified: gnucash/trunk/lib/libqof/qof/qofinstance.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -132,13 +132,6 @@
 	return &(inst->guid);
 }
 
-QofBook *
-qof_instance_get_book (const QofInstance *inst)
-{
-	if (!inst) return NULL;
-	return inst->book;
-}
-
 void
 qof_instance_set_guid (QofInstance *ent, const GUID *guid)
 {
@@ -151,6 +144,20 @@
   qof_collection_insert_entity(col, ent);
 }
 
+const QofCollection *
+qof_instance_get_collection (gconstpointer ptr)
+{
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr), NULL);
+    return QOF_INSTANCE(ptr)->collection;
+}
+
+QofBook *
+qof_instance_get_book (const QofInstance *inst)
+{
+    if (!inst) return NULL;
+    return inst->book;
+}
+
 KvpFrame*
 qof_instance_get_slots (const QofInstance *inst)
 {
@@ -169,6 +176,38 @@
 	return inst->last_update;
 }
 
+gint
+qof_instance_get_editlevel (gconstpointer ptr)
+{
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr), 0);
+    return QOF_INSTANCE(ptr)->editlevel;
+}
+
+void qof_instance_increase_editlevel (gpointer ptr)
+{
+    g_return_if_fail(QOF_IS_INSTANCE(ptr));
+    QOF_INSTANCE(ptr)->editlevel++;
+}
+
+void qof_instance_decrease_editlevel (gpointer ptr)
+{
+    g_return_if_fail(QOF_IS_INSTANCE(ptr));
+    QOF_INSTANCE(ptr)->editlevel--;
+}
+
+void qof_instance_reset_editlevel (gpointer ptr)
+{
+    g_return_if_fail(QOF_IS_INSTANCE(ptr));
+    QOF_INSTANCE(ptr)->editlevel = 0;
+}
+
+gboolean
+qof_instance_check_edit(const  QofInstance *inst)
+{
+    g_return_val_if_fail(QOF_IS_INSTANCE(inst), FALSE);
+    return (inst->editlevel > 0);
+}
+
 int
 qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
 {
@@ -182,7 +221,28 @@
 	return 0;
 }
 
+gboolean
+qof_instance_get_destroying (gconstpointer ptr)
+{
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
+    return QOF_INSTANCE(ptr)->do_free;
+}
+
 void
+qof_instance_set_destroying (gpointer ptr, gboolean value)
+{
+    g_return_if_fail(QOF_IS_INSTANCE(ptr));
+    QOF_INSTANCE(ptr)->do_free = value;
+}
+
+gboolean
+qof_instance_get_dirty_flag (gconstpointer ptr)
+{
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
+    return QOF_INSTANCE(ptr)->dirty;
+}
+
+void
 qof_instance_print_dirty (const QofInstance *entity, gpointer dummy)
 {
   QofInstance *inst = QOF_INSTANCE(entity);
@@ -219,13 +279,6 @@
 }
 
 gboolean
-qof_instance_check_edit(const  QofInstance *inst)
-{
-	if(inst->editlevel > 0) { return TRUE; }
-	return FALSE;
-}
-
-gboolean
 qof_instance_do_free(const QofInstance *inst)
 {
 	return inst->do_free;

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-04-30 05:33:33 UTC (rev 16025)
@@ -119,6 +119,9 @@
 /** Return the GUID of this instance */
 const GUID * qof_instance_get_guid (const QofInstance *);
 
+/** Return the collection this instance belongs to */
+const QofCollection* qof_instance_get_collection (gconstpointer inst);
+
 /** Set the GUID of this instance */
 void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
 
@@ -133,6 +136,11 @@
  */
 Timespec qof_instance_get_last_update (const QofInstance *inst);
 
+gint qof_instance_get_editlevel (gconstpointer ptr);
+void qof_instance_increase_editlevel (gpointer ptr);
+void qof_instance_decrease_editlevel (gpointer ptr);
+void qof_instance_reset_editlevel (gpointer ptr);
+
 /** Compare two instances, based on thier last update times. 
  *  Returns a negative, zero or positive value, respectively, 
  *  if 'left' is earlier, same as or later than 'right'.  
@@ -141,6 +149,37 @@
  */
 int qof_instance_version_cmp (const QofInstance *left, const QofInstance *right);
 
+/** Retrieve the flag that indicates whether or not this object is
+ *  about to be destroyed.
+ *
+ *  @param ptr The object whose flag should be retrieved.
+ *
+ *  @return TRUE if the object has been marked for destruction. FALSE
+ *  if the object is not marked for destruction, or if a bad parameter
+ *  is passed to the function. */
+gboolean qof_instance_get_destroying (gconstpointer ptr);
+
+/** Set the flag that indicates whether or not this object is about to
+ *  be destroyed.
+ *
+ *  @param ptr The object whose flag should be set.
+ *
+ *  @param value The new value to be set for this object. */
+void qof_instance_set_destroying (gpointer ptr, gboolean value);
+
+/** Retrieve the flag that indicates whether or not this object has
+ *  been modified.  This is specifically the flag on the object. It
+ *  does not perform any other checking which might normally be
+ *  performed when testing to see if an object is dirty.  If there is
+ *  any question, use the qof_instance_is_dirty() function instead.
+ *
+ *  @param ptr The object whose flag should be retrieved.
+ *
+ *  @return TRUE if the object has been modified and not saved. FALSE
+ *  if the object has not been modified, or if a bad parameter is
+ *  passed to the function. */
+gboolean qof_instance_get_dirty_flag (gconstpointer ptr);
+
 void qof_instance_print_dirty (const QofInstance *entity, gpointer dummy);
 
 /** Return value of is_dirty flag */

Modified: gnucash/trunk/src/backend/postgres/account.c
===================================================================
--- gnucash/trunk/src/backend/postgres/account.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/backend/postgres/account.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -81,7 +81,8 @@
    const gnc_commodity *com;
 
    if (!be || !acct) return;
-   if ((FALSE == do_mark) && (FALSE == acct->inst.dirty)) return;
+   if ((FALSE == do_mark) && (!qof_instance_get_dirty_flag(acct)))
+     return;
 
    ENTER ("acct=%p, mark=%d", acct, do_mark);
 
@@ -556,7 +557,7 @@
    ENTER ("be=%p, acct=%p", be, acct);
    if (!be || !acct) return;
 
-   if (FALSE == acct->inst.dirty)
+   if (!qof_instance_get_dirty_flag(acct))
    {
       LEAVE ("account not written because not dirty");
       return;
@@ -576,7 +577,7 @@
     * made changes, and we must roll back. */
    if (0 < pgendAccountCompareVersion (be, acct))
    {
-      acct->inst.do_free = FALSE;
+      qof_instance_set_destroying(acct, FALSE);
       p = "ROLLBACK;";
       SEND_QUERY (be,p,);
       FINISH_QUERY(be->connection);
@@ -593,7 +594,7 @@
    gnc_account_increment_version(acct);  /* be sure to update the version !! */
    gnc_account_set_version_check(acct, be->version_check);
 
-   if (acct->inst.do_free)
+   if (qof_instance_get_destroying(acct))
    {
       const GUID *guid = xaccAccountGetGUID(acct);
       pgendKVPDelete (be, acct->idata);

Modified: gnucash/trunk/src/backend/postgres/price.c
===================================================================
--- gnucash/trunk/src/backend/postgres/price.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/backend/postgres/price.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -452,7 +452,7 @@
 void
 pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr)
 {
-   if (pr && pr->db && pr->db->inst.dirty) 
+   if (pr && pr->db && qof_instance_get_dirty_flag(pr->db)) 
    {
       PERR ("price db is unexpectedly dirty");
    }
@@ -479,7 +479,7 @@
     * made changes, and we must roll back. */
    if (0 < pgendPriceCompareVersion (be, pr))
    {
-      pr->inst.do_free = FALSE;
+      qof_instance_set_destroying(pr, FALSE);
       bufp = "ROLLBACK;";
       SEND_QUERY (be,bufp,);
       FINISH_QUERY(be->connection);
@@ -496,7 +496,7 @@
    pr->version ++;   /* be sure to update the version !! */
    pr->version_check = be->version_check;
 
-   if (pr->inst.do_free) 
+   if (qof_instance_get_destroying(pr))
    {
       pgendStoreAuditPrice (be, pr, SQL_DELETE);
       bufp = be->buff; *bufp = 0;

Modified: gnucash/trunk/src/backend/postgres/txn.c
===================================================================
--- gnucash/trunk/src/backend/postgres/txn.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/backend/postgres/txn.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -211,8 +211,9 @@
    /* Update the rest */
    start = xaccTransGetSplitList(trans);
 
-   PINFO ("split-list=%p, do_free=%d", start, trans->inst.do_free);
-   if ((start) && !(trans->inst.do_free))
+   PINFO ("split-list=%p, destroying=%d", start,
+          qof_instance_get_destroying(trans));
+   if ((start) && !qof_instance_get_destroying(trans))
    {
       gnc_commodity *com;
 
@@ -977,7 +978,7 @@
                   "\ttransaction is '%s' %s\n",
                   xaccTransGetDescription (trans), buf);
             rollback = 0;
-            trans->inst.do_free = TRUE;
+            qof_instance_set_destroying(trans, TRUE);
          }
          else
          {

Modified: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncAddress.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -163,7 +163,7 @@
 gncAddressDestroy (GncAddress *addr)
 {
   if (!addr) return;
-  addr->inst.do_free = TRUE;
+  qof_instance_set_destroying(addr, TRUE);
   gncAddressCommitEdit (addr);
 }
 

Modified: gnucash/trunk/src/business/business-core/gncBillTerm.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -120,14 +120,14 @@
 static inline void
 gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
 {
-  g_return_if_fail(table->inst.do_free == FALSE);
+  g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
   table->children = g_list_prepend(table->children, child);
 }
 
 static inline void
 gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
 {
-  if (table->inst.do_free) return;
+  if (qof_instance_get_destroying(table)) return;
   table->children = g_list_remove(table->children, child);
 }
 
@@ -172,7 +172,7 @@
   if (!term) return;
   DEBUG("destroying bill term %s (%p)",
 	    guid_to_string(qof_instance_get_guid(&term->inst)), term);
-  term->inst.do_free = TRUE;
+  qof_instance_set_destroying(term, TRUE);
   qof_instance_set_dirty (&term->inst);
   gncBillTermCommitEdit (term);
 }
@@ -189,7 +189,7 @@
   CACHE_REMOVE (term->desc);
   remObj (term);
 
-  if (!term->inst.do_free)
+  if (!qof_instance_get_destroying(term))
     PERR("free a billterm without do_free set!");
 
   /* disconnect from parent */
@@ -592,7 +592,7 @@
 gboolean gncBillTermIsDirty (GncBillTerm *term)
 {
   if (!term) return FALSE;
-  return term->inst.dirty;
+  return qof_instance_get_dirty_flag(term);
 }
 
 /********************************************************/

Modified: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -181,7 +181,7 @@
 void gncCustomerDestroy (GncCustomer *cust)
 {
   if (!cust) return;
-  cust->inst.do_free = TRUE;
+  qof_instance_set_destroying(cust, TRUE);
   qof_instance_set_dirty (&cust->inst);
   gncCustomerCommitEdit (cust);
 }

Modified: gnucash/trunk/src/business/business-core/gncEmployee.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncEmployee.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -116,7 +116,7 @@
 void gncEmployeeDestroy (GncEmployee *employee)
 {
   if (!employee) return;
-  employee->inst.do_free = TRUE;
+  qof_instance_set_destroying(employee, TRUE);
   gncEmployeeCommitEdit(employee);
 }
 
@@ -362,7 +362,8 @@
 gboolean gncEmployeeIsDirty (GncEmployee *employee)
 {
   if (!employee) return FALSE;
-  return (employee->inst.dirty || gncAddressIsDirty (employee->addr));
+  return (qof_instance_get_dirty_flag(employee)
+          || gncAddressIsDirty (employee->addr));
 }
 
 void gncEmployeeBeginEdit (GncEmployee *employee)

Modified: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncEntry.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -233,7 +233,7 @@
 void gncEntryDestroy (GncEntry *entry)
 {
   if (!entry) return;
-  entry->inst.do_free = TRUE;
+  qof_instance_set_destroying(entry, TRUE);
   gncEntryCommitEdit(entry);
 }
 
@@ -1181,7 +1181,7 @@
 gboolean gncEntryIsOpen (GncEntry *entry)
 {
   if (!entry) return FALSE;
-  return (entry->inst.editlevel > 0);
+  return (qof_instance_get_editlevel(entry) > 0);
 }
 
 /* ================================================================ */

Modified: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -150,7 +150,7 @@
 void gncInvoiceDestroy (GncInvoice *invoice)
 {
   if (!invoice) return;
-  invoice->inst.do_free = TRUE;
+  qof_instance_set_destroying(invoice, TRUE);
   gncInvoiceCommitEdit (invoice);
 }
 
@@ -1522,7 +1522,7 @@
 
   g_return_val_if_fail (invoice, NULL);
 
-  if (invoice->inst.dirty || invoice->printname == NULL) {
+  if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL) {
     if (invoice->printname) g_free (invoice->printname);
 
     invoice->printname =

Modified: gnucash/trunk/src/business/business-core/gncJob.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncJob.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -131,7 +131,7 @@
 void gncJobDestroy (GncJob *job)
 {
   if (!job) return;
-  job->inst.do_free = TRUE;
+  qof_instance_set_destroying(job, TRUE);
   gncJobCommitEdit (job);
 }
 

Modified: gnucash/trunk/src/business/business-core/gncOrder.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncOrder.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -122,7 +122,7 @@
 void gncOrderDestroy (GncOrder *order)
 {
   if (!order) return;
-  order->inst.do_free = TRUE;
+  qof_instance_set_destroying(order, TRUE);
   gncOrderCommitEdit (order);
 }
 
@@ -408,7 +408,7 @@
 
   g_return_val_if_fail (order, NULL);
 
-  if (order->inst.dirty || order->printname == NULL) {
+  if (qof_instance_get_dirty_flag(order) || order->printname == NULL) {
     if (order->printname) g_free (order->printname);
 
     order->printname =

Modified: gnucash/trunk/src/business/business-core/gncTaxTable.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -188,7 +188,7 @@
 {
   g_return_if_fail(table);
   g_return_if_fail(child);
-  g_return_if_fail(table->inst.do_free == FALSE);
+  g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
 
   table->children = g_list_prepend(table->children, child);
 }
@@ -199,7 +199,7 @@
   g_return_if_fail(table);
   g_return_if_fail(child);
 
-  if (table->inst.do_free) return;
+  if (qof_instance_get_destroying(table)) return;
 
   table->children = g_list_remove(table->children, child);
 }
@@ -309,7 +309,7 @@
 gncTaxTableDestroy (GncTaxTable *table)
 {
   if (!table) return;
-  table->inst.do_free = TRUE;
+  qof_instance_set_destroying(table, TRUE);
   qof_instance_set_dirty (&table->inst);
   gncTaxTableCommitEdit (table);
 }
@@ -331,7 +331,7 @@
     gncTaxTableEntryDestroy (list->data);
   g_list_free (table->entries);
 
-  if (!table->inst.do_free)
+  if (!qof_instance_get_destroying(table))
     PERR("free a taxtable without do_free set!");
 
   /* disconnect from parent */

Modified: gnucash/trunk/src/business/business-core/gncVendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/business/business-core/gncVendor.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -121,7 +121,7 @@
 void gncVendorDestroy (GncVendor *vendor)
 {
   if (!vendor) return;
-  vendor->inst.do_free = TRUE;
+  qof_instance_set_destroying(vendor, TRUE);
   gncVendorCommitEdit (vendor);
 }
 
@@ -504,7 +504,8 @@
 gboolean gncVendorIsDirty (GncVendor *vendor)
 {
   if (!vendor) return FALSE;
-  return (vendor->inst.dirty || gncAddressIsDirty (vendor->addr));
+  return (qof_instance_get_dirty_flag(vendor)
+          || gncAddressIsDirty (vendor->addr));
 }
 
 /* ============================================================== */

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/Account.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -949,7 +949,7 @@
 {
     /* FIXME: this code is kind of hacky.  actually, all this code
      * seems to assume that the account edit levels are all 1. */
-    if (acc->inst.editlevel == 0)
+    if (qof_instance_get_editlevel(acc) == 0)
       xaccAccountBeginEdit(acc);
     xaccAccountDestroy(acc);
 }
@@ -1021,7 +1021,7 @@
     PERR (" instead of calling xaccFreeAccount(), please call \n"
           " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
   
-    acc->inst.editlevel = 0;
+    qof_instance_reset_editlevel(acc);
 
     slist = g_list_copy(priv->splits);
     for (lp = slist; lp; lp = lp->next) {
@@ -1113,12 +1113,12 @@
   /* If marked for deletion, get rid of subaccounts first,
    * and then the splits ... */
   priv = GET_PRIVATE(acc);
-  if (acc->inst.do_free)
+  if (qof_instance_get_destroying(acc))
   {
     GList *lp, *slist;
     QofCollection *col;
  
-    acc->inst.editlevel++;
+    qof_instance_increase_editlevel(acc);
 
     /* First, recursively free children */
     xaccFreeAccountChildren(acc);
@@ -1156,7 +1156,7 @@
     priv->lots = NULL;
 
     qof_instance_set_dirty(&acc->inst);
-    acc->inst.editlevel--;
+    qof_instance_decrease_editlevel(acc);
   }
   else 
   {
@@ -1171,7 +1171,7 @@
 {
   g_return_if_fail(GNC_IS_ACCOUNT(acc));
 
-  acc->inst.do_free = TRUE;
+  qof_instance_set_destroying(acc, TRUE);
 
   xaccAccountCommitEdit (acc);
 }
@@ -1499,7 +1499,7 @@
 
     g_return_if_fail(GNC_IS_ACCOUNT(acc));
 
-    if (acc->inst.do_free)
+    if (qof_instance_get_destroying(acc))
 	return;
 
     priv = GET_PRIVATE(acc);
@@ -1520,7 +1520,7 @@
 
     g_return_if_fail(GNC_IS_ACCOUNT(acc));
 
-    if (acc->inst.do_free)
+    if (qof_instance_get_destroying(acc))
 	return;
 
     priv = GET_PRIVATE(acc);
@@ -1558,7 +1558,7 @@
     if (node)
 	return FALSE;
 
-    if (acc->inst.editlevel == 0) {
+    if (qof_instance_get_editlevel(acc) == 0) {
 	priv->splits = g_list_insert_sorted(priv->splits, s,
 					   (GCompareFunc)xaccSplitOrder);
     } else {
@@ -1610,7 +1610,7 @@
     g_return_if_fail(GNC_IS_ACCOUNT(acc));
 
     priv = GET_PRIVATE(acc);
-    if (!priv->sort_dirty || (!force && acc->inst.editlevel > 0))
+    if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
         return;
     priv->splits = g_list_sort(priv->splits, (GCompareFunc)xaccSplitOrder);
     priv->sort_dirty = FALSE;
@@ -1892,9 +1892,9 @@
   if (NULL == acc) return;
 
   priv = GET_PRIVATE(acc);
-  if (acc->inst.editlevel > 0) return;
+  if (qof_instance_get_editlevel(acc) > 0) return;
   if (!priv->balance_dirty) return;
-  if (acc->inst.do_free) return;
+  if (qof_instance_get_destroying(acc)) return;
   if (qof_book_shutting_down(acc->inst.book)) return;
 
   balance            = priv->starting_balance;

Modified: gnucash/trunk/src/engine/Scrub2.c
===================================================================
--- gnucash/trunk/src/engine/Scrub2.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/Scrub2.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -412,7 +412,7 @@
       Split *s = node->data;
       if (xaccSplitGetLot (s) != lot) continue;
       if (s == split) continue;
-      if (s->inst.do_free) continue;
+      if (qof_instance_get_destroying(s)) continue;
 
       /* OK, this split is in the same lot (and thus same account)
        * as the indicated split.  Make sure it is really a subsplit

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/Split.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -173,7 +173,6 @@
    * have to fix this up.
    */
   split->inst.e_type = NULL;
-  split->inst.collection = NULL;
   split->inst.guid = s->inst.guid;
   split->inst.book = s->inst.book;
 
@@ -515,18 +514,18 @@
     acc = s->acc;
     /* Remove from lot (but only if it hasn't been moved to
        new lot already) */
-    if (s->lot && (s->lot->account != acc || s->inst.do_free))
+    if (s->lot && (s->lot->account != acc || qof_instance_get_destroying(s)))
         gnc_lot_remove_split (s->lot, s);
 
     /* Possibly remove the split from the original account... */
-    if (orig_acc && (orig_acc != acc || s->inst.do_free)) {
+    if (orig_acc && (orig_acc != acc || qof_instance_get_destroying(s))) {
         if (!gnc_account_remove_split(orig_acc, s)) {
           PERR("Account lost track of moved or deleted split.");
         }
     }
 
     /* ... and insert it into the new account if needed */
-    if (acc && (orig_acc != acc) && !s->inst.do_free) {
+    if (acc && (orig_acc != acc) && !qof_instance_get_destroying(s)) {
         if (gnc_account_insert_split(acc, s)) {
             /* If the split's lot belonged to some other account, we
                leave it so. */
@@ -563,7 +562,7 @@
         g_object_set(acc, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
         xaccAccountRecomputeBalance(acc);
     }
-    if (s->inst.do_free)
+    if (qof_instance_get_destroying(s))
         xaccFreeSplit(s);
 }
 
@@ -579,9 +578,9 @@
         s->acc = s->orig_acc;  
 
     /* Undestroy if needed */
-    if (s->inst.do_free && s->parent) {
+    if (qof_instance_get_destroying(s) && s->parent) {
         GncEventData ed;
-        s->inst.do_free = FALSE;
+        qof_instance_set_destroying(s, FALSE);
         ed.node = s;
         ed.idx = -1; /* unused */
         qof_event_gen(&s->parent->inst, GNC_EVENT_ITEM_ADDED, &ed);
@@ -1103,14 +1102,15 @@
 
    acc = split->acc;
    trans = split->parent;
-   if (acc && !acc->inst.do_free && xaccTransGetReadOnly (trans))
+   if (acc && !qof_instance_get_destroying(acc)
+       && xaccTransGetReadOnly(trans))
        return FALSE;
 
    xaccTransBeginEdit(trans);
    ed.node = split;
    ed.idx = xaccTransGetSplitIndex(trans, split);
    qof_instance_set_dirty(QOF_INSTANCE(split));
-   split->inst.do_free = TRUE;
+   qof_instance_set_destroying(split, TRUE);
    qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
    xaccTransCommitEdit(trans);
 

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/Transaction.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -178,7 +178,7 @@
 
 void check_open (const Transaction *trans)
 {
-  if (trans && 0 >= trans->inst.editlevel)
+  if (trans && 0 >= qof_instance_get_editlevel(trans))
     PERR ("transaction %p not open for editing", trans);
 }
 /********************************************************************\
@@ -186,7 +186,7 @@
 gboolean
 xaccTransStillHasSplit(const Transaction *trans, const Split *s)
 {
-    return (s->parent == trans && !s->inst.do_free);
+    return (s->parent == trans && !qof_instance_get_destroying(s));
 }
 
 /* Executes 'cmd_block' for each split currently in the transaction,
@@ -314,7 +314,7 @@
          gnc_commodity_get_printname(trans->common_currency));
   printf("    version:     %x\n", trans->version);
   printf("    version_chk: %x\n", trans->version_check);
-  printf("    editlevel:   %x\n", trans->editlevel);
+  printf("    editlevel:   %x\n", qof_instance_get_editlevel(trans));
   printf("    orig:        %p\n", trans->orig);
   printf("    idata:       %x\n", trans->idata);
   printf("    splits:      ");
@@ -397,10 +397,7 @@
    */
   trans->inst.e_type = NULL;
   trans->inst.guid = *guid_null();
-  trans->inst.collection = NULL;
   trans->inst.book = t->inst.book;
-  trans->inst.editlevel = 0;
-  trans->inst.do_free = FALSE;
   trans->inst.kvp_data = kvp_frame_copy (t->inst.kvp_data);
 
   return trans;
@@ -865,7 +862,7 @@
   if (!xaccTransGetReadOnly (trans) || 
       qof_book_shutting_down(trans->inst.book)) {
       xaccTransBeginEdit(trans);
-      trans->inst.do_free = TRUE;
+      qof_instance_set_destroying(trans, TRUE);
       xaccTransCommitEdit(trans);
   }
 }
@@ -965,7 +962,7 @@
         if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
             continue;
 
-        if ((s->parent != trans) || s->inst.do_free) {
+        if ((s->parent != trans) || qof_instance_get_destroying(s)) {
             /* Existing split either moved to another transaction or
                was destroyed, drop from list */
             GncEventData ed;
@@ -977,7 +974,7 @@
 
         if (s->parent == trans) {
             /* Split was either added, destroyed or just changed */
-            if (s->inst.do_free)
+            if (qof_instance_get_destroying(s))
                 qof_event_gen(&s->inst, QOF_EVENT_DESTROY, NULL);
             else qof_event_gen(&s->inst, QOF_EVENT_MODIFY, NULL);
             xaccSplitCommitEdit(s);
@@ -998,8 +995,8 @@
     xaccTransSortSplits(trans);
 
     /* Put back to zero. */
-    trans->inst.editlevel--;
-    g_assert(trans->inst.editlevel == 0);
+    qof_instance_decrease_editlevel(trans);
+    g_assert(qof_instance_get_editlevel(trans) == 0);
 
     gen_event_trans (trans); //TODO: could be conditional
     qof_event_gen (&trans->inst, QOF_EVENT_MODIFY, NULL);
@@ -1019,9 +1016,10 @@
    /* We increment this for the duration of the call
     * so other functions don't result in a recursive
     * call to xaccTransCommitEdit. */
-   trans->inst.editlevel++;
+   qof_instance_increase_editlevel(trans);
 
-   if (was_trans_emptied(trans)) trans->inst.do_free = TRUE;
+   if (was_trans_emptied(trans))
+     qof_instance_set_destroying(trans, TRUE);
 
    /* Before commiting the transaction, we're gonna enforce certain
     * constraints.  In particular, we want to enforce the cap-gains
@@ -1032,7 +1030,7 @@
     * can cause pointers to splits and transactions to disapear out
     * from under the holder.
     */
-   if (!(trans->inst.do_free) && scrub_data && 
+   if (!qof_instance_get_destroying(trans) && scrub_data && 
        !qof_book_shutting_down(xaccTransGetBook(trans))) {
      /* If scrubbing gains recurses through here, don't call it again. */
      scrub_data = 0; 
@@ -1201,10 +1199,10 @@
    xaccFreeTransaction (trans->orig);
 
    trans->orig = NULL;
-   trans->inst.do_free = FALSE;
+   qof_instance_set_destroying(trans, FALSE);
 
    /* Put back to zero. */
-   trans->inst.editlevel--;
+   qof_instance_decrease_editlevel(trans);
    /* FIXME: The register code seems to depend on the engine to
       generate an event during rollback, even though the state is just
       reverting to what it was. */
@@ -1216,7 +1214,7 @@
 gboolean
 xaccTransIsOpen (const Transaction *trans)
 {
-  return trans ? (0 < trans->inst.editlevel) : FALSE;
+  return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
 }
 
 /* Only used by postgres backend. Not sure if it should dirty the trans. */

Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/cap-gains.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -662,7 +662,7 @@
 
    /* Both splits will be in the same collection, so search there. */
    gains_split = (Split*) qof_collection_lookup_entity (
-       split->inst.collection, gains_guid);
+       qof_instance_get_collection(split), gains_guid);
    PINFO ("split=%p has gains-split=%p", split, gains_split);
    return gains_split;
 }
@@ -685,7 +685,7 @@
 
    /* Both splits will be in the same collection, so search there. */
    source_split = (Split*) qof_collection_lookup_entity(
-       split->inst.collection, source_guid);
+       qof_instance_get_collection(split), source_guid);
    PINFO ("split=%p has source-split=%p", split, source_split);
    return source_split;
 }

Modified: gnucash/trunk/src/engine/gnc-budget.c
===================================================================
--- gnucash/trunk/src/engine/gnc-budget.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/gnc-budget.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -146,7 +146,7 @@
     g_return_if_fail(GNC_IS_BUDGET(budget));
     gnc_budget_begin_edit(budget);
     qof_instance_set_dirty(&budget->inst);
-    budget->inst.do_free = TRUE;
+    qof_instance_set_destroying(budget, TRUE);
     gnc_budget_commit_edit(budget);
 }
 

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2007-04-29 18:32:53 UTC (rev 16024)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2007-04-30 05:33:33 UTC (rev 16025)
@@ -812,8 +812,9 @@
   GHashTable *currency_hash;
 
   if(!db || !p) return FALSE;
-  ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
-         db, p, p->inst.dirty, p->inst.do_free);
+  ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p));
 
   if (db->inst.book != p->inst.book)
   {
@@ -857,8 +858,9 @@
   p->db = db;
   qof_event_gen (&p->inst, QOF_EVENT_ADD, NULL);
 
-  LEAVE ("db=%p, pr=%p dirty=%d do-free=%d commodity=%s/%s currency_hash=%p",
-         db, p, p->inst.dirty, p->inst.do_free,
+  LEAVE ("db=%p, pr=%p dirty=%d dextroying=%d commodity=%s/%s currency_hash=%p",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p),
          gnc_commodity_get_namespace(p->commodity),
          gnc_commodity_get_mnemonic(p->commodity),
          currency_hash);
@@ -872,8 +874,9 @@
 {
   if(!db || !p) return FALSE;
 
-  ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
-         db, p, p->inst.dirty, p->inst.do_free);
+  ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p));
 
   if (FALSE == add_price(db, p)) 
   {
@@ -885,8 +888,9 @@
   qof_instance_set_dirty(&db->inst);
   gnc_pricedb_commit_edit(db);
 
-  LEAVE ("db=%p, pr=%p dirty=%d do-free=%d",
-         db, p, p->inst.dirty, p->inst.do_free);
+  LEAVE ("db=%p, pr=%p dirty=%d destroying=%d",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p));
 
   return TRUE;
 }
@@ -904,8 +908,9 @@
   GHashTable *currency_hash;
 
   if(!db || !p) return FALSE;
-  ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
-         db, p, p->inst.dirty, p->inst.do_free);
+  ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p));
 
   commodity = gnc_price_get_commodity(p);
   if(!commodity) { LEAVE (" no commodity"); return FALSE; }
@@ -958,8 +963,9 @@
 {
   gboolean rc;
   if(!db || !p) return FALSE;
-  ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
-         db, p, p->inst.dirty, p->inst.do_free);
+  ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
+         db, p, qof_instance_get_dirty_flag(p),
+         qof_instance_get_destroying(p));
 
   gnc_price_ref(p);
   rc = remove_price (db, p, TRUE);
@@ -969,7 +975,7 @@
 
   /* invoke the backend to delete this price */
   gnc_price_begin_edit (p);
-  p->inst.do_free = TRUE;
+  qof_instance_set_destroying(p, TRUE);
   gnc_price_commit_edit (p);
   p->db = NULL;
   gnc_price_unref(p);



More information about the gnucash-changes mailing list