r15933 - gnucash/trunk/src/engine - Finish moving account specific properties from the public data

David Hampton hampton at cvs.gnucash.org
Thu Apr 19 00:16:40 EDT 2007


Author: hampton
Date: 2007-04-19 00:16:39 -0400 (Thu, 19 Apr 2007)
New Revision: 15933
Trac: http://svn.gnucash.org/trac/changeset/15933

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/AccountP.h
   gnucash/trunk/src/engine/Scrub.c
   gnucash/trunk/src/engine/Scrub3.c
   gnucash/trunk/src/engine/cap-gains.c
Log:
Finish moving account specific properties from the public data
structure to a private data structure.


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2007-04-19 00:58:51 UTC (rev 15932)
+++ gnucash/trunk/src/engine/Account.c	2007-04-19 04:16:39 UTC (rev 15933)
@@ -113,14 +113,14 @@
      */
     GNCAccountType type;
 
-//    /* 
-//     * The commodity field denotes the kind of 'stuff' stored 
-//     * in this account.  The 'amount' field of a split indicates
-//     * how much of the 'stuff' there is.
-//     */
-//    gnc_commodity * commodity;
-//    int commodity_scu;
-//    gboolean non_standard_scu;
+    /* 
+     * The commodity field denotes the kind of 'stuff' stored 
+     * in this account.  The 'amount' field of a split indicates
+     * how much of the 'stuff' there is.
+     */
+    gnc_commodity * commodity;
+    int commodity_scu;
+    gboolean non_standard_scu;
 
     /* The parent and children pointers are used to implement an account
      * hierarchy, of accounts that have sub-accounts ("detail accounts").
@@ -244,9 +244,9 @@
     priv->policy = xaccGetFIFOPolicy();
     priv->lots = NULL;
 
-//    priv->commodity = NULL;
-//    priv->commodity_scu = 0;
-//    priv->non_standard_scu = FALSE;
+    priv->commodity = NULL;
+    priv->commodity_scu = 0;
+    priv->non_standard_scu = FALSE;
 
     priv->balance = gnc_numeric_zero();
     priv->cleared_balance = gnc_numeric_zero();
@@ -305,6 +305,15 @@
 	    // NEED TO BE CONVERTED TO A G_TYPE_ENUM
 	    g_value_set_int(value, priv->type);
 	    break;
+	case PROP_COMMODITY:
+	    g_value_set_object(value, priv->commodity);
+	    break;
+	case PROP_COMMODITY_SCU:
+	    g_value_set_int(value, priv->commodity_scu);
+	    break;
+	case PROP_NON_STD_SCU:
+	    g_value_set_boolean(value, priv->non_standard_scu);
+	    break;
 	case PROP_SORT_DIRTY:
 	    g_value_set_boolean(value, priv->sort_dirty);
 	    break;
@@ -388,6 +397,12 @@
 	    // NEED TO BE CONVERTED TO A G_TYPE_ENUM
 	    xaccAccountSetType(account, g_value_get_int(value));
 	    break;
+	case PROP_COMMODITY:
+	    xaccAccountSetCommodity(account, g_value_get_object(value));
+	    break;
+	case PROP_COMMODITY_SCU:
+	    xaccAccountSetCommoditySCU(account, g_value_get_int(value));
+	    break;
 	case PROP_SORT_DIRTY:
 	    gnc_account_set_sort_dirty(account);
 	    break;
@@ -522,6 +537,45 @@
 			   G_PARAM_READWRITE));
 
     g_object_class_install_property
+        (gobject_class,
+         PROP_COMMODITY,
+         g_param_spec_object ("commodity",
+                              "Commodity",
+                              "The commodity field denotes the kind of "
+                              "'stuff' stored  in this account, whether "
+                              "it is USD, gold, stock, etc.",
+                              GNC_TYPE_COMMODITY,
+                              G_PARAM_READWRITE));
+
+    g_object_class_install_property
+        (gobject_class,
+         PROP_COMMODITY_SCU,
+         g_param_spec_int ("commodity-scu",
+                           "Commodity SCU",
+                           "The smallest fraction of the commodity that is "
+                           "tracked.  This number is used as the denominator "
+                           "value in 1/x, so a value of 100 says that the "
+                           "commodity can be divided into hundreths.  E.G."
+                           "1 USD can be divided into 100 cents.",
+                           0,
+                           G_MAXINT32,
+                           1000000,
+                           G_PARAM_READWRITE));
+
+    g_object_class_install_property
+        (gobject_class,
+         PROP_NON_STD_SCU,
+         g_param_spec_boolean ("non-std-scu",
+                               "Non-std SCU",
+                               "TRUE id the account SCU doesn't match "
+                               "the commodity SCU.  This indicates a case "
+                               "where the two were accidentally set to "
+                               "mismatched values in older versions of "
+                               "GnuCash.",
+                               FALSE,
+                               G_PARAM_READWRITE));
+
+    g_object_class_install_property
 	(gobject_class,
 	 PROP_SORT_DIRTY,
 	 g_param_spec_boolean("sort-dirty",
@@ -716,13 +770,12 @@
 
   acc->idata = 0;
 
-  acc->commodity = NULL;
-  acc->commodity_scu = 0;
-  acc->non_standard_scu = FALSE;
-
   LEAVE ("account=%p\n", acc);
 }
 
+/********************************************************************\
+\********************************************************************/
+
 QofBook *
 gnc_account_get_book(const Account *account)
 {
@@ -861,10 +914,10 @@
 
     /* The new book should contain a commodity that matches
      * the one in the old book. Find it, use it. */
-    ret->commodity = gnc_commodity_obtain_twin (from->commodity, book);
+    priv->commodity = gnc_commodity_obtain_twin(from_priv->commodity, book);
 
-    ret->commodity_scu = from->commodity_scu;
-    ret->non_standard_scu = from->non_standard_scu;
+    priv->commodity_scu = from_priv->commodity_scu;
+    priv->non_standard_scu = from_priv->non_standard_scu;
 
     LEAVE (" ");
     return ret;
@@ -929,7 +982,7 @@
   AccountPrivate *priv;
   GList *lp;
 
-  if (!acc) return;
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
 
   priv = GET_PRIVATE(acc);
   qof_event_gen (&acc->inst, QOF_EVENT_DESTROY, NULL);
@@ -987,7 +1040,6 @@
   /* zero out values, just in case stray 
    * pointers are pointing here. */
 
-  acc->commodity = NULL;
   priv->parent = NULL;
   priv->children = NULL;
 
@@ -996,7 +1048,7 @@
   priv->reconciled_balance = gnc_numeric_zero();
 
   priv->type = ACCT_TYPE_NONE;
-  acc->commodity = NULL;
+  priv->commodity = NULL;
 
   priv->version = 0;
   priv->balance_dirty = FALSE;
@@ -1117,7 +1169,8 @@
 void 
 xaccAccountDestroy (Account *acc) 
 {
-  if (!acc) return;
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
   acc->inst.do_free = TRUE;
 
   xaccAccountCommitEdit (acc);
@@ -1225,11 +1278,8 @@
 
   if(!aa && !ab) return TRUE;
 
-  if(!aa || !ab)
-  {
-    PWARN ("one is NULL");
-    return FALSE;
-  }
+  g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
+  g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
 
   priv_aa = GET_PRIVATE(aa);
   priv_ab = GET_PRIVATE(ab);
@@ -1257,7 +1307,7 @@
     return FALSE;
   }
 
-  if (!gnc_commodity_equal(aa->commodity, ab->commodity))
+  if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
   {
     PWARN ("commodities differ");
     return FALSE;
@@ -1584,7 +1634,8 @@
 void 
 xaccAccountSetGUID (Account *acc, const GUID *guid)
 {
-  if (!acc || !guid) return;
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+  g_return_if_fail(guid);
 
   /* XXX this looks fishy and weird to me ... */
   PINFO("acct=%p", acc);
@@ -2056,8 +2107,10 @@
 {
 	Account *parent_acc;
 	
-	if (!acc || !parent) return;
-	parent_acc = (Account*)parent;
+	g_return_if_fail(GNC_IS_ACCOUNT(acc));
+	g_return_if_fail(GNC_IS_ACCOUNT(parent));
+
+	parent_acc = GNC_ACCOUNT(parent);
 	xaccAccountBeginEdit(acc);
 	xaccAccountBeginEdit(parent_acc);
 	gnc_account_append_child(parent_acc, acc);
@@ -2090,15 +2143,21 @@
 {
   AccountPrivate *priv;
   GList *lp;
-  if (!acc || !com || com == acc->commodity) return;
 
+  /* errors */
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+  g_return_if_fail(GNC_IS_COMMODITY(com));
+
+  /* optimizations */
   priv = GET_PRIVATE(acc);
+  if (com == priv->commodity)
+      return;
+
   xaccAccountBeginEdit(acc);
+  priv->commodity = com;
+  priv->commodity_scu = gnc_commodity_get_fraction(com);
+  priv->non_standard_scu = FALSE;
 
-  acc->commodity = com;
-  acc->commodity_scu = gnc_commodity_get_fraction(com);
-  acc->non_standard_scu = FALSE;
-
   /* iterate over splits */
   for (lp = priv->splits; lp; lp = lp->next)
   {
@@ -2135,12 +2194,15 @@
 void
 xaccAccountSetCommoditySCU (Account *acc, int scu)
 {
-  if (!acc) return;
+  AccountPrivate *priv;
 
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
+  priv = GET_PRIVATE(acc);
   xaccAccountBeginEdit(acc);
-  acc->commodity_scu = scu;
-  if (scu != gnc_commodity_get_fraction(acc->commodity))
-      acc->non_standard_scu = TRUE;
+  priv->commodity_scu = scu;
+  if (scu != gnc_commodity_get_fraction(priv->commodity))
+      priv->non_standard_scu = TRUE;
   mark_account(acc);
   xaccAccountCommitEdit(acc);
 }
@@ -2148,26 +2210,35 @@
 int
 xaccAccountGetCommoditySCUi (const Account * acc)
 {
-  return acc ? acc->commodity_scu : 0;
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
+    return GET_PRIVATE(acc)->commodity_scu;
 }
 
 int
 xaccAccountGetCommoditySCU (const Account * acc)
 {
-  if (!acc) return 0;
+    AccountPrivate *priv;
 
-  if (acc->non_standard_scu || !acc->commodity)
-    return acc->commodity_scu;
-  return gnc_commodity_get_fraction(acc->commodity);
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
+
+    priv = GET_PRIVATE(acc);
+    if (priv->non_standard_scu || !priv->commodity)
+	return priv->commodity_scu;
+    return gnc_commodity_get_fraction(priv->commodity);
 }
 
 void
 xaccAccountSetNonStdSCU (Account *acc, gboolean flag)
 {
-  if (!acc || acc->non_standard_scu == flag) return;
+  AccountPrivate *priv;
 
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
+  priv = GET_PRIVATE(acc);
+  if (priv->non_standard_scu == flag)
+      return;
   xaccAccountBeginEdit(acc);
-  acc->non_standard_scu = flag;
+  priv->non_standard_scu = flag;
   mark_account (acc);
   xaccAccountCommitEdit(acc);
 }
@@ -2175,7 +2246,8 @@
 gboolean
 xaccAccountGetNonStdSCU (const Account * acc)
 {
-  return acc ? acc->non_standard_scu : 0;
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
+    return GET_PRIVATE(acc)->non_standard_scu;
 }
 
 /********************************************************************\
@@ -2521,7 +2593,7 @@
   Account *found;
   GList *node;
 
-  g_return_val_if_fail(parent, NULL);
+  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
   g_return_val_if_fail(names, NULL);
 
   /* Look for the first name in the children. */
@@ -2777,7 +2849,8 @@
 gnc_commodity * 
 xaccAccountGetCommodity (const Account *acc)
 {
-  return acc ? acc->commodity : NULL;
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+    return GET_PRIVATE(acc)->commodity;
 }
 
 /********************************************************************\
@@ -2875,7 +2948,7 @@
   gnc_numeric lowest = gnc_numeric_zero ();
   int seen_a_transaction = 0;
 
-  if (!acc) return gnc_numeric_zero ();
+  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
 
   priv = GET_PRIVATE(acc);
   today = gnc_timet_get_today_end();
@@ -2917,7 +2990,7 @@
   gboolean found = FALSE;
   gnc_numeric balance;
 
-  if (!acc) return gnc_numeric_zero ();
+  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
 
   xaccAccountSortSplits (acc, TRUE); /* just in case, normally a noop */
   xaccAccountRecomputeBalance (acc); /* just in case, normally a noop */
@@ -2986,7 +3059,7 @@
   GList *node;
   time_t today;
 
-  g_return_val_if_fail(acc, gnc_numeric_zero());
+  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
 
   priv = GET_PRIVATE(acc);
   today = gnc_timet_get_today_end();
@@ -3074,14 +3147,19 @@
 				    xaccGetBalanceFn fn,
 				    const gnc_commodity *report_currency)
 {
-  gnc_numeric balance;
+    AccountPrivate *priv;
+    gnc_numeric balance;
 
-  if (!acc || !fn || !report_currency) return gnc_numeric_zero ();
-  balance = fn(acc);
-  balance = xaccAccountConvertBalanceToCurrency(acc, balance,
-                                                acc->commodity,
-                                                report_currency);
-  return balance;
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+    g_return_val_if_fail(fn, gnc_numeric_zero());
+    g_return_val_if_fail(GNC_IS_COMMODITY(report_currency), gnc_numeric_zero());
+
+    priv = GET_PRIVATE(acc);
+    balance = fn(acc);
+    balance = xaccAccountConvertBalanceToCurrency(acc, balance,
+						  priv->commodity,
+						  report_currency);
+    return balance;
 }
 
 static gnc_numeric
@@ -3089,9 +3167,15 @@
                                            xaccGetBalanceAsOfDateFn fn,
                                            const gnc_commodity *report_commodity)
 {
-    g_return_val_if_fail(acc && fn && report_commodity, gnc_numeric_zero());
+    AccountPrivate *priv;
+
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+    g_return_val_if_fail(fn, gnc_numeric_zero());
+    g_return_val_if_fail(GNC_IS_COMMODITY(report_commodity), gnc_numeric_zero());
+
+    priv = GET_PRIVATE(acc);
     return xaccAccountConvertBalanceToCurrency(
-        acc, fn(acc, date), acc->commodity, report_commodity);
+        acc, fn(acc, date), priv->commodity, report_commodity);
 }
 
 /*
@@ -4244,7 +4328,7 @@
 	continue;
       if (0 != safe_strcmp(priv_a->description, priv_b->description))
 	continue;
-      if (!gnc_commodity_equiv(acc_a->commodity, acc_b->commodity))
+      if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
 	continue;
       if (0 != safe_strcmp(xaccAccountGetNotes(acc_a),
 			   xaccAccountGetNotes(acc_b)))

Modified: gnucash/trunk/src/engine/AccountP.h
===================================================================
--- gnucash/trunk/src/engine/AccountP.h	2007-04-19 00:58:51 UTC (rev 15932)
+++ gnucash/trunk/src/engine/AccountP.h	2007-04-19 04:16:39 UTC (rev 15933)
@@ -56,15 +56,6 @@
 {
   QofInstance inst;
 
-  /* 
-   * The commodity field denotes the kind of 'stuff' stored 
-   * in this account.  The 'amount' field of a split indicates
-   * how much of the 'stuff' there is.
-   */
-  gnc_commodity * commodity;
-  int commodity_scu;
-  gboolean non_standard_scu;
-
   /* -------------------------------------------------------------- */
   /* Backend private expansion data */
   guint32  idata;     /* used by the sql backend for kvp management */

Modified: gnucash/trunk/src/engine/Scrub.c
===================================================================
--- gnucash/trunk/src/engine/Scrub.c	2007-04-19 00:58:51 UTC (rev 15932)
+++ gnucash/trunk/src/engine/Scrub.c	2007-04-19 04:16:39 UTC (rev 15933)
@@ -166,7 +166,7 @@
   Account *account;
   Transaction *trans;
   gnc_numeric value, amount;
-  gnc_commodity *currency;
+  gnc_commodity *currency, *acc_commodity;
   int scu;
 
   if (!split) return;
@@ -220,12 +220,12 @@
   /* If the account doesn't have a commodity, 
    * we should attempt to fix that first. 
   */
-  if (!account->commodity)
+  acc_commodity = xaccAccountGetCommodity(account);
+  if (!acc_commodity)
   {
     xaccAccountScrubCommodity (account);
   }
-  if (!account->commodity || 
-      !gnc_commodity_equiv (account->commodity, currency))
+  if (!acc_commodity || !gnc_commodity_equiv(acc_commodity, currency))
   {
     LEAVE ("(split=%p) inequiv currency", split);
     return;
@@ -620,7 +620,9 @@
     if (!gnc_numeric_equal(xaccSplitGetAmount (sp), 
         xaccSplitGetValue (sp))) 
     {
-      gnc_commodity *acc_currency = xaccAccountGetCommodity (sp->acc);
+      gnc_commodity *acc_currency;
+
+      acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : NULL;
       if (acc_currency == currency) 
       {
         /* This Split needs fixing: The transaction-currency equals

Modified: gnucash/trunk/src/engine/Scrub3.c
===================================================================
--- gnucash/trunk/src/engine/Scrub3.c	2007-04-19 00:58:51 UTC (rev 15932)
+++ gnucash/trunk/src/engine/Scrub3.c	2007-04-19 04:16:39 UTC (rev 15933)
@@ -62,6 +62,7 @@
   Account *acc;
   Split *split;
   gboolean comeq;
+  gnc_commodity *acc_commodity;
 
   acc = gnc_lot_get_account (lot);
 
@@ -69,7 +70,8 @@
   if (!node) return FALSE;
   split = node->data;
 
-  comeq = gnc_commodity_equiv (acc->commodity, split->parent->common_currency);
+  acc_commodity = xaccAccountGetCommodity(acc);
+  comeq = gnc_commodity_equiv (acc_commodity, split->parent->common_currency);
   return (FALSE == comeq);
 }
 

Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c	2007-04-19 00:58:51 UTC (rev 15932)
+++ gnucash/trunk/src/engine/cap-gains.c	2007-04-19 04:16:39 UTC (rev 15933)
@@ -86,7 +86,7 @@
    if (xaccAccountIsPriced (acc))
       return TRUE;
       
-   acc_comm = acc->commodity;
+   acc_comm = xaccAccountGetCommodity(acc);
 
    splits = xaccAccountGetSplitList(acc);
    for (node=splits; node; node=node->next)
@@ -271,6 +271,7 @@
   KvpFrame *cwd;
   KvpValue *vvv;
   const char * cur_name;
+  gnc_commodity *acc_comm;
 
   if (!acc || !gain_acct) return;
 
@@ -278,7 +279,8 @@
   cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
 
   /* Accounts are indexed by thier unique currency name */
-  cur_name = gnc_commodity_get_unique_name (acc->commodity);
+  acc_comm = xaccAccountGetCommodity(acc);
+  cur_name = gnc_commodity_get_unique_name (acc_comm);
 
   xaccAccountBeginEdit (acc);
   vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));



More information about the gnucash-changes mailing list