[Gnucash-changes] r13487 - gnucash/trunk/src - Convert xaccTransGetSplit() and xaccTransCountSplits() to return the

Chris Shoemaker chris at cvs.gnucash.org
Sat Mar 4 23:14:38 EST 2006


Author: chris
Date: 2006-03-04 23:14:38 -0500 (Sat, 04 Mar 2006)
New Revision: 13487
Trac: http://svn.gnucash.org/trac/changeset/13487

Modified:
   gnucash/trunk/src/engine/Scrub.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/register/ledger-core/split-register-control.c
   gnucash/trunk/src/register/ledger-core/split-register-load.c
   gnucash/trunk/src/register/ledger-core/split-register.c
Log:
   Convert xaccTransGetSplit() and xaccTransCountSplits() to return the
   index and count reflective of any in-progress edit.
   Convert some split iterators from directly using the GList of Splits to 
   using xaccTransGetSplit().


Modified: gnucash/trunk/src/engine/Scrub.c
===================================================================
--- gnucash/trunk/src/engine/Scrub.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/engine/Scrub.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -345,6 +345,8 @@
   
   for (node = xaccTransGetSplitList (trans); node; node = node->next) {
     Split *split = node->data;
+
+    if (!xaccTransStillHasSplit(trans, split)) continue;
     if (gnc_numeric_equal(xaccSplitGetAmount (split),
                           xaccSplitGetValue (split))) {
 

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/engine/Split.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -1160,6 +1160,7 @@
     current_split = node->data;
     if (current_split == sa) continue;
 
+    if (!xaccTransStillHasSplit(sa->parent, current_split)) continue;
     current_value = xaccSplitGetValue (current_split);
     current_value_positive = gnc_numeric_positive_p(current_value);
     if ((sa_value_positive && !current_value_positive) || 
@@ -1581,9 +1582,9 @@
 Split *
 xaccSplitGetOtherSplit (const Split *split)
 {
-  SplitList *node;
+  int i;
   Transaction *trans;
-  int count;
+  int count, num_splits;
   Split *other = NULL;
   KvpValue *sva;
 
@@ -1602,16 +1603,17 @@
   return s1;
 #endif
 
-  count = g_list_length (trans->splits);
+  num_splits = xaccTransCountSplits(trans);
+  count = num_splits;
   sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
   if (!sva && (2 != count)) return NULL;
 
-  for (node = trans->splits; node; node = node->next)
-  {
-    Split *s = node->data;
-    if (s == split) { --count; continue; }
-    if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split")) { --count; continue; }
-    other = s;
+  for (i = 0; i < num_splits; i++) {
+      Split *s = xaccTransGetSplit(trans, i);
+      if (s == split) { --count; continue; }
+      if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split")) 
+          { --count; continue; }
+      other = s;
   }
   return (1 == count) ? other : NULL;
 }

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/engine/Transaction.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -717,8 +717,7 @@
                           xaccTransGetCurrency(txn)))
       return gnc_numeric_create(1, 1);
 
-  splits = xaccTransGetSplitList(txn);
-  for (; splits; splits = splits->next) {
+  for (splits = txn->splits; splits; splits = splits->next) {
     s = splits->data;
 
     if (!xaccTransStillHasSplit(txn, s))
@@ -763,7 +762,7 @@
   // Not really the appropriate error value.
   g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
 
-  for (node = xaccTransGetSplitList(trans); node; node = node->next)
+  for (node = trans->splits; node; node = node->next)
   {
     Split *split = node->data;
 
@@ -1442,9 +1441,11 @@
 Split *
 xaccTransGetSplit (const Transaction *trans, int i) 
 {
-   if (!trans || i < 0) return NULL;
+    int j = 0;
+    if (!trans || i < 0) return NULL;
 
-   return g_list_nth_data (trans->splits, i);
+    FOR_EACH_SPLIT(trans, { if (i == j) return s; j++; });
+    return NULL;
 }
 
 SplitList *
@@ -1456,7 +1457,9 @@
 int
 xaccTransCountSplits (const Transaction *trans)
 {
-   return trans ? g_list_length (trans->splits) : 0;
+    gint i = 0;
+    FOR_EACH_SPLIT(trans, i++);
+    return i;
 }
 
 const char *

Modified: gnucash/trunk/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-control.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/register/ledger-core/split-register-control.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -457,12 +457,10 @@
 gnc_find_split_in_trans_by_memo (Transaction *trans, const char *memo,
                                  gboolean unit_price)
 {
-  GList *node;
+  int i;
+  Split *split;
 
-  for (node = xaccTransGetSplitList (trans); node; node = node->next)
-  {
-    Split *split = node->data;
-
+  while (split = xaccTransGetSplit(trans, i)) {
     if (unit_price)
     {
       gnc_numeric price = xaccSplitGetSharePrice (split);
@@ -472,6 +470,7 @@
 
     if (safe_strcmp (memo, xaccSplitGetMemo (split)) == 0)
       return split;
+    i++;
   }
 
   return NULL;
@@ -695,21 +694,20 @@
         if (gnc_split_register_get_default_account (reg) != NULL)
         {
           Account *default_account;
-          GList *node;
+          Split *s;
+          int i;
 
           default_account = gnc_split_register_get_default_account (reg);
           blank_split = NULL;
 
-          for (node = xaccTransGetSplitList (trans); node; node = node->next)
-          {
-            Split *s = node->data;
-
+          while (s = xaccTransGetSplit(trans, i)) {
             if (default_account == xaccSplitGetAccount(s))
             {
               blank_split = s;
               info->blank_split_guid = *xaccSplitGetGUID(blank_split);
               break;
             }
+            i++;
           }
 
           if (blank_split == NULL)

Modified: gnucash/trunk/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -395,7 +395,8 @@
      * fill up the quickfill cells. */
     if (info->first_pass)
     {
-      GList *node;
+      Split *s;
+      int i;      
 
       gnc_quickfill_cell_add_completion
         ((QuickFillCell *)
@@ -413,14 +414,14 @@
            gnc_table_layout_get_cell (reg->table->layout, NUM_CELL),
            xaccTransGetNum (trans));
 
-      for (node = xaccTransGetSplitList (trans); node; node = node->next)
-      {
-        Split *s = node->data;
-        QuickFillCell *cell;
+      i = 0;
+      while (s = xaccTransGetSplit(trans, i)) {
+          QuickFillCell *cell;
 
-        cell = (QuickFillCell *)
-          gnc_table_layout_get_cell (reg->table->layout, MEMO_CELL);
-        gnc_quickfill_cell_add_completion (cell, xaccSplitGetMemo (s));
+          cell = (QuickFillCell *)
+              gnc_table_layout_get_cell (reg->table->layout, MEMO_CELL);
+          gnc_quickfill_cell_add_completion (cell, xaccSplitGetMemo (s));
+          i++;
       }
     }
 

Modified: gnucash/trunk/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.c	2006-03-05 01:29:43 UTC (rev 13486)
+++ gnucash/trunk/src/register/ledger-core/split-register.c	2006-03-05 04:14:38 UTC (rev 13487)
@@ -77,19 +77,14 @@
 static int
 gnc_trans_split_index (Transaction *trans, Split *split)
 {
-  GList *node;
-  int i;
+    Split *s;
+    int i = 0;
 
-  for (i = 0, node = xaccTransGetSplitList (trans); node;
-       i++, node = node->next)
-  {
-    Split *s = node->data;
-
-    if (s == split)
-      return i;
-  }
-
-  return -1;
+    while (s = xaccTransGetSplit(trans, i)) {
+        if (s == split) return i;
+        i++;
+    }
+    return -1;
 }
 
 /* Uses the scheme split copying routines */
@@ -1077,6 +1072,8 @@
   Transaction *trans;
   GList *splits;
   GList *node;
+  int i = 0;
+  Split *s;
 
   if ((reg == NULL)  || (split == NULL))
     return;
@@ -1084,12 +1081,12 @@
   gnc_suspend_gui_refresh ();
 
   trans = xaccSplitGetParent (split);
-  splits = g_list_copy (xaccTransGetSplitList (trans));
   xaccTransBeginEdit (trans);
-  for (node = splits; node; node = node->next)
-    if (node->data != split)
-      xaccSplitDestroy (node->data);
-  g_list_free (splits);
+  while (s = xaccTransGetSplit(trans, i)) {
+      if (s != split) 
+          xaccSplitDestroy(s);
+      i++;
+  }
 
   /* This is now the  pending transaction */
   info = gnc_split_register_get_info (reg);



More information about the gnucash-changes mailing list