[Gnucash-changes] r13131 - gnucash/trunk/src - Convert Split from
QofEntity to QofInstance.
Chris Shoemaker
chris at cvs.gnucash.org
Mon Feb 6 12:12:41 EST 2006
Author: chris
Date: 2006-02-06 12:12:39 -0500 (Mon, 06 Feb 2006)
New Revision: 13131
Trac: http://svn.gnucash.org/trac/changeset/13131
Modified:
gnucash/trunk/src/backend/postgres/txn.c
gnucash/trunk/src/engine/Account.c
gnucash/trunk/src/engine/Period.c
gnucash/trunk/src/engine/Scrub2.c
gnucash/trunk/src/engine/Transaction.c
gnucash/trunk/src/engine/TransactionP.h
gnucash/trunk/src/engine/cap-gains.c
Log:
Convert Split from QofEntity to QofInstance.
Let QofInstance manage the book pointer and kvp frame instead of Split
managing its own.
Modified: gnucash/trunk/src/backend/postgres/txn.c
===================================================================
--- gnucash/trunk/src/backend/postgres/txn.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/backend/postgres/txn.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -176,7 +176,7 @@
{
Split *s = split_node->data;
- if (s && guid_equal (&s->entity.guid, &dti->guid))
+ if (s && guid_equal (&s->inst.entity.guid, &dti->guid))
{
pgendStoreAuditSplit (be, s, SQL_DELETE);
break;
Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/Account.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -793,7 +793,7 @@
if (!acc || !split || split->acc == acc) return;
/* check for book mix-up */
- g_return_if_fail (acc->inst.book == split->book);
+ g_return_if_fail (acc->inst.book == split->inst.book);
trans = xaccSplitGetParent (split);
ENTER ("(acc=%p, trans=%p, split=%p)", acc, trans, split);
Modified: gnucash/trunk/src/engine/Period.c
===================================================================
--- gnucash/trunk/src/engine/Period.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/Period.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -100,8 +100,8 @@
Split *s = node->data;
/* move the split into the new book ... */
- s->book = book;
- qof_collection_insert_entity(col, &s->entity);
+ s->inst.book = book;
+ qof_collection_insert_entity(col, &s->inst.entity);
/* find the twin account, and re-parent to that. */
twin = xaccAccountLookupTwin (s->acc, book);
@@ -161,10 +161,10 @@
Split *s = node->data;
/* Move the splits over (only if they haven't already been moved). */
- if (s->book != book)
+ if (s->inst.book != book)
{
- s->book = book;
- qof_collection_insert_entity (col, &s->entity);
+ s->inst.book = book;
+ qof_collection_insert_entity (col, &s->inst.entity);
}
/* Find the twin account, and re-parent to that. */
@@ -234,10 +234,10 @@
for (snode = lot->splits; snode; snode=snode->next)
{
Split *s = snode->data;
- if (s->book != book)
+ if (s->inst.book != book)
{
- s->book = book;
- qof_collection_insert_entity (col, &s->entity);
+ s->inst.book = book;
+ qof_collection_insert_entity (col, &s->inst.entity);
}
}
Modified: gnucash/trunk/src/engine/Scrub2.c
===================================================================
--- gnucash/trunk/src/engine/Scrub2.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/Scrub2.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -232,7 +232,7 @@
g_return_val_if_fail (split->parent, FALSE);
/* If there are no sub-splits, then there's nothing to do. */
- kval = kvp_frame_get_slot (split->kvp_data, "lot-split");
+ kval = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
if (!kval) return FALSE;
return TRUE;
@@ -320,27 +320,27 @@
KvpFrame *ksub;
/* Find and remove the matching guid's */
- ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->kvp_data, "lot-split",
- "peer_guid", &sb->entity.guid);
+ ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->inst.kvp_data, "lot-split",
+ "peer_guid", &sb->inst.entity.guid);
if (ksub)
{
- gnc_kvp_bag_remove_frame (sa->kvp_data, "lot-split", ksub);
+ gnc_kvp_bag_remove_frame (sa->inst.kvp_data, "lot-split", ksub);
kvp_frame_delete (ksub);
}
/* Now do it in the other direction */
- ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->kvp_data, "lot-split",
- "peer_guid", &sa->entity.guid);
+ ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->inst.kvp_data, "lot-split",
+ "peer_guid", &sa->inst.entity.guid);
if (ksub)
{
- gnc_kvp_bag_remove_frame (sb->kvp_data, "lot-split", ksub);
+ gnc_kvp_bag_remove_frame (sb->inst.kvp_data, "lot-split", ksub);
kvp_frame_delete (ksub);
}
/* Finally, merge b's lot-splits, if any, into a's */
/* This is an important step, if it got busted into many pieces. */
- gnc_kvp_bag_merge (sa->kvp_data, "lot-split",
- sb->kvp_data, "lot-split");
+ gnc_kvp_bag_merge (sa->inst.kvp_data, "lot-split",
+ sb->inst.kvp_data, "lot-split");
}
/* The merge_splits() routine causes the amount & value of sb
Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/Transaction.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -94,8 +94,6 @@
static void
xaccInitSplit(Split * split, QofBook *book)
{
- QofCollection *col;
-
/* fill in some sane defaults */
split->acc = NULL;
split->parent = NULL;
@@ -114,16 +112,12 @@
split->cleared_balance = gnc_numeric_zero();
split->reconciled_balance = gnc_numeric_zero();
- split->kvp_data = kvp_frame_new();
split->idata = 0;
- split->book = book;
-
split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = NULL;
- col = qof_book_get_collection (book, GNC_ID_SPLIT);
- qof_entity_init (&split->entity, GNC_ID_SPLIT, col);
+ qof_instance_init(&split->inst, GNC_ID_SPLIT, book);
}
void
@@ -147,9 +141,9 @@
split->cleared_balance = gnc_numeric_zero();
split->reconciled_balance = gnc_numeric_zero();
- if (split->kvp_data)
- kvp_frame_delete(split->kvp_data);
- split->kvp_data = kvp_frame_new();
+ if (split->inst.kvp_data)
+ kvp_frame_delete(split->inst.kvp_data);
+ split->inst.kvp_data = kvp_frame_new();
split->idata = 0;
split->gains = GAINS_STATUS_UNKNOWN;
@@ -189,10 +183,10 @@
* the cloned splits as something official. If we ever use this
* split, we'll have to fix this up.
*/
- split->entity.e_type = NULL;
- split->entity.guid = *guid_null();
- split->entity.collection = NULL;
- split->book = s->book;
+ split->inst.entity.e_type = NULL;
+ split->inst.entity.guid = *guid_null();
+ split->inst.entity.collection = NULL;
+ split->inst.book = s->inst.book;
split->parent = s->parent;
split->acc = s->acc;
@@ -201,7 +195,7 @@
split->memo = gnc_string_cache_insert(s->memo);
split->action = gnc_string_cache_insert(s->action);
- split->kvp_data = kvp_frame_copy (s->kvp_data);
+ split->inst.kvp_data = kvp_frame_copy (s->inst.kvp_data);
split->reconciled = s->reconciled;
split->date_reconciled = s->date_reconciled;
@@ -221,14 +215,11 @@
Split *
xaccSplitClone (const Split *s)
{
- QofCollection *col;
Split *split = g_new0 (Split, 1);
- split->book = s->book;
split->parent = NULL;
split->memo = gnc_string_cache_insert(s->memo);
split->action = gnc_string_cache_insert(s->action);
- split->kvp_data = kvp_frame_copy(s->kvp_data);
split->reconciled = s->reconciled;
split->date_reconciled = s->date_reconciled;
split->value = s->value;
@@ -241,8 +232,9 @@
split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = NULL;
- col = qof_book_get_collection (s->book, GNC_ID_SPLIT);
- qof_entity_init (&split->entity, GNC_ID_SPLIT, col);
+ qof_instance_init(&split->inst, GNC_ID_SPLIT, s->inst.book);
+ kvp_frame_delete(split->inst.kvp_data);
+ split->inst.kvp_data = kvp_frame_copy(s->inst.kvp_data);
xaccAccountInsertSplit(s->acc, split);
if (s->lot)
@@ -260,13 +252,13 @@
{
printf(" %s Split %p", tag, split);
printf(" GUID: %s\n", guid_to_string(&split->guid));
- printf(" Book: %p\n", split->book);
+ printf(" Book: %p\n", split->inst.book);
printf(" Account: %p\n", split->acc);
printf(" Lot: %p\n", split->lot);
printf(" Parent: %p\n", split->parent);
printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
printf(" Action: %s\n", split->action ? split->action : "(null)");
- printf(" KVP Data: %p\n", split->kvp_data);
+ printf(" KVP Data: %p\n", split->inst.kvp_data);
printf(" Recncld: %c (date %s)\n", split->reconciled,
gnc_print_date(split->date_reconciled));
printf(" Value: %s\n", gnc_numeric_to_string(split->value));
@@ -296,9 +288,6 @@
gnc_string_cache_remove(split->memo);
gnc_string_cache_remove(split->action);
- kvp_frame_delete (split->kvp_data);
- split->kvp_data = NULL;
-
/* Just in case someone looks up freed memory ... */
split->memo = (char *) 1;
split->action = NULL;
@@ -314,7 +303,7 @@
// Is this right?
if (split->gains_split) split->gains_split->gains_split = NULL;
- qof_entity_release (&split->entity);
+ qof_instance_release(&split->inst);
g_free(split);
}
@@ -360,7 +349,7 @@
if (sa == sb) return TRUE;
if (check_guids) {
- if (!guid_equal(&(sa->entity.guid), &(sb->entity.guid)))
+ if (!guid_equal(&(sa->inst.entity.guid), &(sb->inst.entity.guid)))
{
PWARN ("GUIDs differ");
return FALSE;
@@ -381,13 +370,13 @@
return FALSE;
}
- if (kvp_frame_compare(sa->kvp_data, sb->kvp_data) != 0)
+ if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
{
char *frame_a;
char *frame_b;
- frame_a = kvp_frame_to_string (sa->kvp_data);
- frame_b = kvp_frame_to_string (sb->kvp_data);
+ frame_a = kvp_frame_to_string (sa->inst.kvp_data);
+ frame_b = kvp_frame_to_string (sb->inst.kvp_data);
PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
@@ -530,17 +519,17 @@
return;
}
- val = kvp_frame_get_slot (split->kvp_data, "gains-source");
+ val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
if (!val)
{
// FIXME: This looks bogus.
other = xaccSplitGetOtherSplit (split);
if (other)
- val = kvp_frame_get_slot (other->kvp_data, "gains-source");
+ val = kvp_frame_get_slot (other->inst.kvp_data, "gains-source");
split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
} else {
QofCollection *col;
- col = qof_book_get_collection (split->book, GNC_ID_SPLIT);
+ col = qof_book_get_collection (split->inst.book, GNC_ID_SPLIT);
split->gains = GAINS_STATUS_GAINS;
other = (Split *) qof_collection_lookup_entity (col,
kvp_value_get_guid (val));
@@ -684,19 +673,16 @@
KvpFrame *
xaccSplitGetSlots (const Split * s)
{
- return s ? s->kvp_data : NULL;
+ return qof_instance_get_slots(QOF_INSTANCE(s));
}
void
xaccSplitSetSlots_nc(Split *s, KvpFrame *frm)
{
- if (!s || !frm || s->kvp_data == frm) return;
+ if (!s || !frm) return;
check_open (s->parent);
- if (s->kvp_data)
- kvp_frame_delete(s->kvp_data);
-
- s->kvp_data = frm;
+ qof_instance_set_slots(QOF_INSTANCE(s), frm);
}
/********************************************************************\
@@ -1956,11 +1942,11 @@
s->memo = so->memo;
so->memo = gnc_string_cache_insert("");
- kvp_frame_delete (s->kvp_data);
- s->kvp_data = so->kvp_data;
- if (!s->kvp_data)
- s->kvp_data = kvp_frame_new ();
- so->kvp_data = kvp_frame_new ();
+ kvp_frame_delete (s->inst.kvp_data);
+ s->inst.kvp_data = so->inst.kvp_data;
+ if (!s->inst.kvp_data)
+ s->inst.kvp_data = kvp_frame_new ();
+ so->inst.kvp_data = kvp_frame_new ();
s->reconciled = so->reconciled;
s->amount = so->amount;
@@ -2182,7 +2168,7 @@
xaccTransAppendSplit (Transaction *trans, Split *split)
{
if (!trans || !split) return;
- g_return_if_fail (trans->inst.book == split->book);
+ g_return_if_fail (trans->inst.book == split->inst.book);
qof_begin_edit(QOF_INSTANCE(trans));
@@ -2303,7 +2289,7 @@
DATE_CMP(sa,sb,date_reconciled);
/* else, sort on guid - keeps sort stable. */
- retval = guid_compare(&(sa->entity.guid), &(sb->entity.guid));
+ retval = guid_compare(&(sa->inst.entity.guid), &(sb->inst.entity.guid));
if (retval) return retval;
return 0;
@@ -3083,7 +3069,7 @@
QofBook *
xaccSplitGetBook (const Split *split)
{
- return split ? split->book : NULL;
+ return qof_instance_get_book(QOF_INSTANCE(split));
}
const char *
@@ -3092,7 +3078,7 @@
char *split_type;
if (!s) return NULL;
- split_type = kvp_frame_get_string(s->kvp_data, "split-type");
+ split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
return split_type ? split_type : "normal";
}
@@ -3104,7 +3090,7 @@
check_open (s->parent);
s->value = gnc_numeric_zero();
- kvp_frame_set_str(s->kvp_data, "split-type", "stock-split");
+ kvp_frame_set_str(s->inst.kvp_data, "split-type", "stock-split");
SET_GAINS_VDIRTY(s);
mark_split(s);
}
@@ -3202,14 +3188,14 @@
#endif
count = g_list_length (trans->splits);
- sva = kvp_frame_get_slot (split->kvp_data, "lot-split");
+ 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->kvp_data, "lot-split")) { --count; continue; }
+ if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split")) { --count; continue; }
other = s;
}
return (1 == count) ? other : NULL;
@@ -3257,7 +3243,7 @@
for (split_list = trans->splits; split_list; split_list = split_list->next)
{
Split * split = split_list->data;
- frame = split->kvp_data;
+ frame = split->inst.kvp_data;
kvp_frame_set_gnc_numeric(frame, void_former_amt_str,
xaccSplitGetAmount(split));
@@ -3291,14 +3277,14 @@
xaccSplitVoidFormerAmount(const Split *split)
{
g_return_val_if_fail(split, gnc_numeric_zero());
- return kvp_frame_get_numeric(split->kvp_data, void_former_amt_str);
+ return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
}
gnc_numeric
xaccSplitVoidFormerValue(const Split *split)
{
g_return_val_if_fail(split, gnc_numeric_zero());
- return kvp_frame_get_numeric(split->kvp_data, void_former_val_str);
+ return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
}
Timespec
@@ -3339,7 +3325,7 @@
for (split_list = trans->splits; split_list; split_list = split_list->next)
{
split = split_list->data;
- frame = split->kvp_data;
+ frame = split->inst.kvp_data;
val = kvp_frame_get_slot(frame, void_former_amt_str);
amt = kvp_value_get_numeric(val);
Modified: gnucash/trunk/src/engine/TransactionP.h
===================================================================
--- gnucash/trunk/src/engine/TransactionP.h 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/TransactionP.h 2006-02-06 17:12:39 UTC (rev 13131)
@@ -86,10 +86,8 @@
struct split_s
{
- QofEntity entity; /* globally unique id */
+ QofInstance inst;
- QofBook *book; /* The enitity table where this split is stored. */
-
Account *acc; /* back-pointer to debited/credited account */
GNCLot *lot; /* back-pointer to debited/credited lot */
@@ -110,10 +108,6 @@
*/
char * action; /* Buy, Sell, Div, etc. */
- /* kvp_data is a key-value pair database for storing simple
- * "extra" information in splits, transactions, and accounts.
- * it's NULL until accessed. */
- KvpFrame * kvp_data;
Timespec date_reconciled; /* date split was reconciled */
char reconciled; /* The reconciled field */
Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c 2006-02-06 16:18:52 UTC (rev 13130)
+++ gnucash/trunk/src/engine/cap-gains.c 2006-02-06 17:12:39 UTC (rev 13131)
@@ -535,11 +535,11 @@
/* Add kvp markup to indicate that these two splits used
* to be one before being 'split'
*/
- gnc_kvp_bag_add (split->kvp_data, "lot-split", now,
+ gnc_kvp_bag_add (split->inst.kvp_data, "lot-split", now,
"peer_guid", xaccSplitGetGUID (new_split),
NULL);
- gnc_kvp_bag_add (new_split->kvp_data, "lot-split", now,
+ gnc_kvp_bag_add (new_split->inst.kvp_data, "lot-split", now,
"peer_guid", xaccSplitGetGUID (split),
NULL);
@@ -633,13 +633,13 @@
if (!split) return NULL;
- val = kvp_frame_get_slot (split->kvp_data, "gains-split");
+ val = kvp_frame_get_slot (split->inst.kvp_data, "gains-split");
if (!val) return NULL;
gains_guid = kvp_value_get_guid (val);
if (!gains_guid) return NULL;
/* Both splits will be in the same collection, so seearch there. */
- gains_split = (Split*) qof_collection_lookup_entity (split->entity.collection, gains_guid);
+ gains_split = (Split*) qof_collection_lookup_entity (split->inst.entity.collection, gains_guid);
PINFO ("split=%p has gains-split=%p", split, gains_split);
return gains_split;
}
@@ -921,9 +921,9 @@
* that this is the gains transaction that corresponds
* to the gains source.
*/
- kvp_frame_set_guid (split->kvp_data, "gains-split",
+ kvp_frame_set_guid (split->inst.kvp_data, "gains-split",
xaccSplitGetGUID (lot_split));
- kvp_frame_set_guid (lot_split->kvp_data, "gains-source",
+ kvp_frame_set_guid (lot_split->inst.kvp_data, "gains-source",
xaccSplitGetGUID (split));
}
More information about the gnucash-changes
mailing list