r15189 - gnucash/branches/gda-dev/src/engine - 1) Add GNC_SPLIT/GNC_IS_SPLIT and GNC_LOT/GNC_IS_LOT macros

Phil Longstaff plongstaff at cvs.gnucash.org
Thu Dec 7 09:32:47 EST 2006


Author: plongstaff
Date: 2006-12-07 09:32:46 -0500 (Thu, 07 Dec 2006)
New Revision: 15189
Trac: http://svn.gnucash.org/trac/changeset/15189

Modified:
   gnucash/branches/gda-dev/src/engine/Split.h
   gnucash/branches/gda-dev/src/engine/gnc-lot.c
   gnucash/branches/gda-dev/src/engine/gnc-lot.h
   gnucash/branches/gda-dev/src/engine/gnc-pricedb.c
   gnucash/branches/gda-dev/src/engine/gnc-pricedb.h
Log:
1) Add GNC_SPLIT/GNC_IS_SPLIT and GNC_LOT/GNC_IS_LOT macros
2) Make some arguments const where appropriate


Modified: gnucash/branches/gda-dev/src/engine/Split.h
===================================================================
--- gnucash/branches/gda-dev/src/engine/Split.h	2006-12-06 20:03:30 UTC (rev 15188)
+++ gnucash/branches/gda-dev/src/engine/Split.h	2006-12-07 14:32:46 UTC (rev 15189)
@@ -64,6 +64,9 @@
  * Splits
  *-----------------------------------------------------------------------*/
 
+#define GNC_IS_SPLIT(obj)  (QOF_CHECK_TYPE((obj), GNC_ID_SPLIT))
+#define GNC_SPLIT(obj)     (QOF_CHECK_CAST((obj), GNC_ID_SPLIT, Split))
+
 /** @name Split general getters/setters
 @{
 */

Modified: gnucash/branches/gda-dev/src/engine/gnc-lot.c
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-lot.c	2006-12-06 20:03:30 UTC (rev 15188)
+++ gnucash/branches/gda-dev/src/engine/gnc-lot.c	2006-12-07 14:32:46 UTC (rev 15189)
@@ -150,26 +150,26 @@
 }
 
 Account *
-gnc_lot_get_account (GNCLot *lot)
+gnc_lot_get_account (const GNCLot *lot)
 {
    if (!lot) return NULL;
    return lot->account;
 }
 
 KvpFrame *
-gnc_lot_get_slots (GNCLot *lot)
+gnc_lot_get_slots (const GNCLot *lot)
 {
     return qof_instance_get_slots(QOF_INSTANCE(lot));
 }
 
 SplitList *
-gnc_lot_get_split_list (GNCLot *lot)
+gnc_lot_get_split_list (const GNCLot *lot)
 {
    if (!lot) return NULL;
    return lot->splits;
 }
 
-gint gnc_lot_count_splits (GNCLot *lot)
+gint gnc_lot_count_splits (const GNCLot *lot)
 {
    if (!lot) return 0;
    return g_list_length (lot->splits);
@@ -179,14 +179,14 @@
 /* Hmm, we should probably inline these. */
 
 const char * 
-gnc_lot_get_title (GNCLot *lot)
+gnc_lot_get_title (const GNCLot *lot)
 {
    if (!lot) return NULL;
    return kvp_frame_get_string (lot->inst.kvp_data, "/title");
 }
 
 const char * 
-gnc_lot_get_notes (GNCLot *lot)
+gnc_lot_get_notes (const GNCLot *lot)
 {
    if (!lot) return NULL;
    return kvp_frame_get_string (lot->inst.kvp_data, "/notes");
@@ -254,7 +254,7 @@
 /* ============================================================= */
 
 void
-gnc_lot_get_balance_before (GNCLot *lot, Split *split,
+gnc_lot_get_balance_before (const GNCLot *lot, const Split *split,
                             gnc_numeric *amount, gnc_numeric *value)
 {
    GList *node;
@@ -265,7 +265,7 @@
    if (lot && lot->splits)
    {
       Transaction *ta, *tb;
-      Split *target;
+      const Split *target;
       /* If this is a gains split, find the source of the gains and use
          its transaction for the comparison.  Gains splits are in separate
          transactions that may sort after non-gains transactions.  */
@@ -368,7 +368,7 @@
 /* Utility function, get earliest split in lot */
 
 Split *
-gnc_lot_get_earliest_split (GNCLot *lot)
+gnc_lot_get_earliest_split (const GNCLot *lot)
 {
    SplitList *node;
    Timespec ts;
@@ -397,7 +397,7 @@
 }
 
 Split *
-gnc_lot_get_latest_split (GNCLot *lot)
+gnc_lot_get_latest_split (const GNCLot *lot)
 {
    SplitList *node;
    Timespec ts;

Modified: gnucash/branches/gda-dev/src/engine/gnc-lot.h
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-lot.h	2006-12-06 20:03:30 UTC (rev 15188)
+++ gnucash/branches/gda-dev/src/engine/gnc-lot.h	2006-12-07 14:32:46 UTC (rev 15189)
@@ -62,6 +62,9 @@
 #include "qof.h"
 #include "gnc-lot-p.h"
 
+#define GNC_IS_LOT(obj)  (QOF_CHECK_TYPE((obj), GNC_ID_LOT))
+#define GNC_LOT(obj)     (QOF_CHECK_CAST((obj), GNC_ID_LOT, GNCLot))
+
 GNCLot * gnc_lot_new (QofBook *);
 void gnc_lot_destroy (GNCLot *);
 
@@ -88,12 +91,12 @@
  *    either gnc_lot_add_split() or gnc_lot_remove_split() will
  *    invalidate the returned pointer.
  */
-SplitList * gnc_lot_get_split_list (GNCLot *);
-gint gnc_lot_count_splits (GNCLot *);
+SplitList * gnc_lot_get_split_list (const GNCLot *);
+gint gnc_lot_count_splits (const GNCLot *);
 
 /** The gnc_lot_get_account() routine returns the account with which 
  *    this lot is associated. */
-Account * gnc_lot_get_account (GNCLot *);
+Account * gnc_lot_get_account (const GNCLot *);
 
 /** The gnc_lot_get_balance() routine returns the balance of the lot. 
  *    The commodity in which this balance is expressed is the commodity 
@@ -104,7 +107,7 @@
  *  value in the lot considering only splits in transactions prior to the
  *  one containing the given split or other splits in the same transaction.
  *  The first return value is the amount and the second is the value. */
-void gnc_lot_get_balance_before (GNCLot *, Split *,
+void gnc_lot_get_balance_before (const GNCLot *, const Split *,
                                  gnc_numeric *, gnc_numeric *);
 
 /** The gnc_lot_is_closed() routine returns a boolean flag: is this 
@@ -119,25 +122,25 @@
  *    loops over all of the splits in the lot, and returns the split
  *    with the earliest split->transaction->date_posted.
  */
-Split * gnc_lot_get_earliest_split (GNCLot *lot);
+Split * gnc_lot_get_earliest_split (const GNCLot *lot);
 
 /** The gnc_lot_get_latest_split() routine is a convenience routine
  *    that helps identify the date this lot was closed.   It simply
  *    loops over all of the splits in the lot, and returns the split
  *    with the latest split->transaction->date_posted.
  */
-Split * gnc_lot_get_latest_split (GNCLot *lot);
+Split * gnc_lot_get_latest_split (const GNCLot *lot);
 
 /** Get and set the account title, or the account notes. */
-const char * gnc_lot_get_title (GNCLot *);
-const char * gnc_lot_get_notes (GNCLot *);
+const char * gnc_lot_get_title (const GNCLot *);
+const char * gnc_lot_get_notes (const GNCLot *);
 void gnc_lot_set_title (GNCLot *, const char *);
 void gnc_lot_set_notes (GNCLot *, const char *);
 
 /** Every lot has a place to hang kvp data.  This routine returns that
  *     place. 
  * */
-KvpFrame * gnc_lot_get_slots (GNCLot *);
+KvpFrame * gnc_lot_get_slots (const GNCLot *);
 
 #define gnc_lot_get_guid(X)  qof_entity_get_guid(QOF_ENTITY(X))
 

Modified: gnucash/branches/gda-dev/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-pricedb.c	2006-12-06 20:03:30 UTC (rev 15188)
+++ gnucash/branches/gda-dev/src/engine/gnc-pricedb.c	2006-12-07 14:32:46 UTC (rev 15189)
@@ -313,14 +313,14 @@
 }
 
 gnc_commodity *
-gnc_price_get_commodity(GNCPrice *p)
+gnc_price_get_commodity(const GNCPrice *p)
 {
   if(!p) return NULL;
   return p->commodity;
 }
 
 Timespec
-gnc_price_get_time(GNCPrice *p)
+gnc_price_get_time(const GNCPrice *p)
 {
   if(!p) {
     Timespec result;
@@ -332,21 +332,21 @@
 }
 
 const char *
-gnc_price_get_source(GNCPrice *p)
+gnc_price_get_source(const GNCPrice *p)
 {
   if(!p) return NULL;
   return p->source;
 }
 
 const char *
-gnc_price_get_type(GNCPrice *p)
+gnc_price_get_type(const GNCPrice *p)
 {
   if(!p) return NULL;
   return p->type;
 }
 
 gnc_numeric
-gnc_price_get_value(GNCPrice *p)
+gnc_price_get_value(const GNCPrice *p)
 {
   if(!p) {
     PERR("price NULL.\n");
@@ -356,21 +356,21 @@
 }
 
 gnc_commodity *
-gnc_price_get_currency(GNCPrice *p)
+gnc_price_get_currency(const GNCPrice *p)
 {
   if(!p) return NULL;
   return p->currency;
 }
 
 gint32
-gnc_price_get_version(GNCPrice *p)
+gnc_price_get_version(const GNCPrice *p)
 {
   if(!p) return 0;
   return (p->version);
 }
 
 gboolean
-gnc_price_equal (GNCPrice *p1, GNCPrice *p2)
+gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2)
 {
   Timespec ts1;
   Timespec ts2;

Modified: gnucash/branches/gda-dev/src/engine/gnc-pricedb.h
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-pricedb.h	2006-12-06 20:03:30 UTC (rev 15188)
+++ gnucash/branches/gda-dev/src/engine/gnc-pricedb.h	2006-12-07 14:32:46 UTC (rev 15189)
@@ -188,14 +188,14 @@
 /** As mentioned above all of the getters return data that's internal
    to the GNCPrice, not copies, so don't free these values. */
 GNCPrice *      gnc_price_lookup (const GUID *guid, QofBook *book);
-gnc_commodity * gnc_price_get_commodity(GNCPrice *p);
-gnc_commodity * gnc_price_get_currency(GNCPrice *p);
-Timespec        gnc_price_get_time(GNCPrice *p);
-const char *    gnc_price_get_source(GNCPrice *p);
-const char *    gnc_price_get_type(GNCPrice *p);
-gnc_numeric     gnc_price_get_value(GNCPrice *p);
-gint32          gnc_price_get_version(GNCPrice *p);
-gboolean        gnc_price_equal(GNCPrice *p1, GNCPrice *p2);
+gnc_commodity * gnc_price_get_commodity(const GNCPrice *p);
+gnc_commodity * gnc_price_get_currency(const GNCPrice *p);
+Timespec        gnc_price_get_time(const GNCPrice *p);
+const char *    gnc_price_get_source(const GNCPrice *p);
+const char *    gnc_price_get_type(const GNCPrice *p);
+gnc_numeric     gnc_price_get_value(const GNCPrice *p);
+gint32          gnc_price_get_version(const GNCPrice *p);
+gboolean        gnc_price_equal(const GNCPrice *p1, const GNCPrice *p2);
 
 #define gnc_price_get_guid(X)    qof_entity_get_guid(QOF_ENTITY(X))
 #define gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_ENTITY(X))))



More information about the gnucash-changes mailing list