From c1ef3fd6dba25663a2cab442861006d79064fa14 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Mon, 6 Feb 2006 17:12:39 +0000 Subject: [PATCH] Convert Split from QofEntity to QofInstance. Let QofInstance manage the book pointer and kvp frame instead of Split managing its own. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13131 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/postgres/txn.c | 2 +- src/engine/Account.c | 2 +- src/engine/Period.c | 16 +++---- src/engine/Scrub2.c | 18 +++---- src/engine/Transaction.c | 96 ++++++++++++++++---------------------- src/engine/TransactionP.h | 8 +--- src/engine/cap-gains.c | 12 ++--- 7 files changed, 67 insertions(+), 87 deletions(-) diff --git a/src/backend/postgres/txn.c b/src/backend/postgres/txn.c index 4015f30645d..b0015b84e40 100644 --- a/src/backend/postgres/txn.c +++ b/src/backend/postgres/txn.c @@ -176,7 +176,7 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, { 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; diff --git a/src/engine/Account.c b/src/engine/Account.c index aba12e3591b..921ec51cead 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -793,7 +793,7 @@ xaccAccountInsertSplit (Account *acc, Split *split) 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); diff --git a/src/engine/Period.c b/src/engine/Period.c index f2454e3ae8e..b3e6f5aacd7 100644 --- a/src/engine/Period.c +++ b/src/engine/Period.c @@ -100,8 +100,8 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) 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 @@ gnc_book_insert_trans (QofBook *book, Transaction *trans) 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 @@ gnc_book_insert_lot (QofBook *book, GNCLot *lot) 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); } } diff --git a/src/engine/Scrub2.c b/src/engine/Scrub2.c index e5d1197775d..feb66429b8e 100644 --- a/src/engine/Scrub2.c +++ b/src/engine/Scrub2.c @@ -232,7 +232,7 @@ is_subsplit (Split *split) 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 @@ remove_guids (Split *sa, Split *sb) 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 diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index cd2f5d2fe0c..b0ab774636e 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -94,8 +94,6 @@ void check_open (const Transaction *trans) static void xaccInitSplit(Split * split, QofBook *book) { - QofCollection *col; - /* fill in some sane defaults */ split->acc = NULL; split->parent = NULL; @@ -114,16 +112,12 @@ xaccInitSplit(Split * split, QofBook *book) 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 @@ xaccSplitReinit(Split * split) 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 @@ xaccDupeSplit (const Split *s) * 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 @@ xaccDupeSplit (const Split *s) 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 @@ xaccDupeSplit (const Split *s) 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 @@ xaccSplitClone (const Split *s) 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 @@ xaccSplitDump (const Split *split, const char *tag) { 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 @@ xaccFreeSplit (Split *split) 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 @@ xaccFreeSplit (Split *split) // 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 @@ xaccSplitEqual(const Split *sa, const Split *sb, 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 @@ xaccSplitEqual(const Split *sa, const Split *sb, 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 @@ xaccSplitDetermineGainStatus (Split *split) 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 @@ get_commodity_denom(const Split * s) 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 @@ xaccTransRollbackEdit (Transaction *trans) 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 @@ void 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 @@ xaccSplitDateOrder (const Split *sa, const Split *sb) 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 @@ xaccSplitGetSharePrice (const Split * split) QofBook * xaccSplitGetBook (const Split *split) { - return split ? split->book : NULL; + return qof_instance_get_book(QOF_INSTANCE(split)); } const char * @@ -3092,7 +3078,7 @@ xaccSplitGetType(const Split *s) 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 @@ xaccSplitMakeStockSplit(Split *s) 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 @@ xaccSplitGetOtherSplit (const Split *split) #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 @@ xaccTransVoid(Transaction *trans, const char *reason) 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 @@ gnc_numeric 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 @@ xaccTransUnvoid (Transaction *trans) 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); diff --git a/src/engine/TransactionP.h b/src/engine/TransactionP.h index 8b01bb34f31..deeba214fb4 100644 --- a/src/engine/TransactionP.h +++ b/src/engine/TransactionP.h @@ -86,9 +86,7 @@ struct split_s { - QofEntity entity; /* globally unique id */ - - QofBook *book; /* The enitity table where this split is stored. */ + QofInstance inst; Account *acc; /* back-pointer to debited/credited account */ @@ -110,10 +108,6 @@ struct split_s */ 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 */ diff --git a/src/engine/cap-gains.c b/src/engine/cap-gains.c index d071b3c6499..9ee49d767a7 100644 --- a/src/engine/cap-gains.c +++ b/src/engine/cap-gains.c @@ -535,11 +535,11 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot) /* 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 @@ xaccSplitGetCapGainsSplit (const Split *split) 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 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc) * 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)); }