diff --git a/lib/libqof/backend/file/qsf-backend.c b/lib/libqof/backend/file/qsf-backend.c index 7de96b7804..1cb799c541 100644 --- a/lib/libqof/backend/file/qsf-backend.c +++ b/lib/libqof/backend/file/qsf-backend.c @@ -739,7 +739,7 @@ reference_list_lookup(gpointer data, gpointer user_data) g_free(ref_name); } else { - ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param); + ent = QOF_ENTITY(ref_param->param_getfcn(ent, ref_param)); if(!ent) { return; } if((0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) || (0 == safe_strcmp(ref_param->param_type, QOF_TYPE_CHOICE))) @@ -827,7 +827,7 @@ qsf_entity_foreach(QofEntity *ent, gpointer data) if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_CHOICE)) { /** \todo use the reference list here. */ - choice_ent = (QofEntity*)qof_param->param_getfcn(ent, qof_param); + choice_ent = QOF_ENTITY(qof_param->param_getfcn(ent, qof_param)); if(!choice_ent) { param_list = g_slist_next(param_list); continue; diff --git a/lib/libqof/backend/file/qsf-xml.c b/lib/libqof/backend/file/qsf-xml.c index cd17e2ad1e..a4fe8977e1 100644 --- a/lib/libqof/backend/file/qsf-xml.c +++ b/lib/libqof/backend/file/qsf-xml.c @@ -355,7 +355,7 @@ qsf_book_node_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params) DEBUG (" trying to set book GUID"); buffer = g_strdup((gchar*)xmlNodeGetContent(child_node)); g_return_if_fail(TRUE == string_to_guid(buffer, &book_guid)); - qof_entity_set_guid((QofEntity*)params->book, &book_guid); + qof_entity_set_guid(QOF_ENTITY(params->book), &book_guid); xmlNewChild(params->output_node, params->qsf_ns, BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer); g_free(buffer); diff --git a/lib/libqof/qof/qofid.c b/lib/libqof/qof/qofid.c index 672a1d25b2..563764de53 100644 --- a/lib/libqof/qof/qofid.c +++ b/lib/libqof/qof/qofid.c @@ -58,67 +58,6 @@ qof_set_alt_dirty_mode (gboolean enabled) /* =============================================================== */ -static void qof_collection_remove_entity (QofEntity *ent); - -void -qof_entity_init (QofEntity *ent, QofIdType type, QofCollection * tab) -{ - g_return_if_fail (NULL != tab); - - /* XXX We passed redundant info to this routine ... but I think that's - * OK, it might eliminate programming errors. */ - if (safe_strcmp(tab->e_type, type)) - { - PERR ("attempt to insert \"%s\" into \"%s\"", type, tab->e_type); - return; - } - ent->e_type = CACHE_INSERT (type); - - do - { - guid_new(&ent->guid); - - if (NULL == qof_collection_lookup_entity (tab, &ent->guid)) break; - - PWARN("duplicate id created, trying again"); - } while(1); - - ent->collection = tab; - - qof_collection_insert_entity (tab, ent); -} - -void -qof_entity_release (QofEntity *ent) -{ - if (!ent->collection) return; - qof_collection_remove_entity (ent); - CACHE_REMOVE (ent->e_type); - ent->e_type = NULL; -} - - -/* This is a restricted function, should be used only during - * read from file */ -void -qof_entity_set_guid (QofEntity *ent, const GUID *guid) -{ - QofCollection *col; - if (guid_equal (guid, &ent->guid)) return; - - col = ent->collection; - qof_collection_remove_entity (ent); - ent->guid = *guid; - qof_collection_insert_entity (col, ent); -} - -const GUID * -qof_entity_get_guid (const QofEntity *ent) -{ - if (!ent) return guid_null(); - return &ent->guid; -} - /* =============================================================== */ static guint @@ -189,7 +128,7 @@ qof_collection_get_type (const QofCollection *col) /* =============================================================== */ -static void +void qof_collection_remove_entity (QofEntity *ent) { QofCollection *col; @@ -322,7 +261,7 @@ qof_collection_from_glist (QofIdType type, GList *glist) coll = qof_collection_new(type); for(list = glist; list != NULL; list = list->next) { - ent = (QofEntity*)list->data; + ent = QOF_ENTITY(list->data); if(FALSE == qof_collection_add_entity(coll, ent)) { return NULL; diff --git a/lib/libqof/qof/qofid.h b/lib/libqof/qof/qofid.h index 2b58991d57..235386a76e 100644 --- a/lib/libqof/qof/qofid.h +++ b/lib/libqof/qof/qofid.h @@ -83,15 +83,15 @@ typedef const gchar * QofIdTypeConst; /** QofLogModule declaration */ typedef const gchar* QofLogModule; +/* Forward declaration for later */ +typedef struct QofInstance_s QofInstance; + #define QOF_ID_NONE NULL #define QOF_ID_NULL "null" #define QOF_ID_BOOK "Book" #define QOF_ID_SESSION "Session" -/** simple,cheesy cast but holds water for now */ -#define QOF_ENTITY(object) ((QofEntity *)(object)) - /** Inline string comparision; compiler will optimize away most of this */ #define QSTRCMP(da,db) ({ \ gint val = 0; \ @@ -124,8 +124,6 @@ print error message if its bad */ (obj); \ })) -/** QofEntity declaration */ -typedef struct QofEntity_s QofEntity; /** QofCollection declaration @param e_type QofIdType @@ -136,20 +134,6 @@ typedef struct QofEntity_s QofEntity; */ typedef struct QofCollection_s QofCollection; -/** QofEntity structure - -@param e_type Entity type -@param guid GUID for the entity -@param collection Entity collection -*/ - -struct QofEntity_s -{ - QofIdType e_type; - GUID guid; - QofCollection * collection; -}; - /** @name QOF Entity Initialization & Shutdown @{ */ /** Initialise the memory associated with an entity */ @@ -198,7 +182,7 @@ QofIdType qof_collection_get_type (const QofCollection *); /** Find the entity going only from its guid */ QofEntity * qof_collection_lookup_entity (const QofCollection *, const GUID *); -/** Callback type for qof_entity_foreach */ +/** Callback type for qof_collection_foreach */ typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data); /** Call the callback for each entity in the collection. */ @@ -240,6 +224,8 @@ by using ::qof_entity_insert_entity or ::qof_entity_remove_entity. gboolean qof_collection_add_entity (QofCollection *coll, QofEntity *ent); +void qof_collection_remove_entity (QofEntity *ent); + /** \brief Merge two QOF_TYPE_COLLECT of the same type. \note \b NOT the same as the main collections in the book. diff --git a/lib/libqof/qof/qofinstance-p.h b/lib/libqof/qof/qofinstance-p.h index 66456c93a3..aa017b70b1 100644 --- a/lib/libqof/qof/qofinstance-p.h +++ b/lib/libqof/qof/qofinstance-p.h @@ -40,7 +40,9 @@ struct QofInstance_s { /* Globally unique id identifying this instance */ - QofEntity entity; + QofIdType e_type; /**< Entity type */ + GUID guid; /**< GUID for the entity */ + QofCollection * collection; /**< Entity collection */ /* The entity_table in which this instance is stored */ QofBook * book; diff --git a/lib/libqof/qof/qofinstance.c b/lib/libqof/qof/qofinstance.c index bc2bc3b07a..85be535ce9 100644 --- a/lib/libqof/qof/qofinstance.c +++ b/lib/libqof/qof/qofinstance.c @@ -39,6 +39,67 @@ static QofLogModule log_module = QOF_MOD_ENGINE; /* ========================================================== */ +static void +qof_int_entity_init (QofEntity *ent, QofIdType type, QofCollection * tab) +{ + g_return_if_fail (NULL != tab); + + /* XXX We passed redundant info to this routine ... but I think that's + * OK, it might eliminate programming errors. */ + if (safe_strcmp(tab->e_type, type)) + { + PERR ("attempt to insert \"%s\" into \"%s\"", type, tab->e_type); + return; + } + ent->e_type = CACHE_INSERT (type); + + do + { + guid_new(&ent->guid); + + if (NULL == qof_collection_lookup_entity (tab, &ent->guid)) break; + + PWARN("duplicate id created, trying again"); + } while(1); + + ent->collection = tab; + + qof_collection_insert_entity (tab, ent); +} + +void +qof_int_entity_release (QofEntity *ent) +{ + if (!ent->collection) return; + qof_collection_remove_entity (ent); + CACHE_REMOVE (ent->e_type); + ent->e_type = NULL; +} + + +/* This is a restricted function, should be used only during + * read from file */ +void +qof_entity_set_guid (QofEntity *ent, const GUID *guid) +{ + QofCollection *col; + if (guid_equal (guid, &ent->guid)) return; + + col = ent->collection; + qof_collection_remove_entity (ent); + ent->guid = *guid; + qof_collection_insert_entity (col, ent); +} + +const GUID * +qof_entity_get_guid (const QofEntity *ent) +{ + if (!ent) return guid_null(); + return &ent->guid; +} + +/* ========================================================== */ + QofInstance* qof_instance_create (QofIdType type, QofBook *book) { @@ -49,6 +110,8 @@ qof_instance_create (QofIdType type, QofBook *book) return inst; } + + void qof_instance_init (QofInstance *inst, QofIdType type, QofBook *book) { @@ -64,7 +127,7 @@ qof_instance_init (QofInstance *inst, QofIdType type, QofBook *book) inst->infant = TRUE; col = qof_book_get_collection (book, type); - qof_entity_init (&inst->entity, type, col); + qof_int_entity_init (&inst->entity, type, col); } void @@ -75,7 +138,7 @@ qof_instance_release (QofInstance *inst) inst->editlevel = 0; inst->do_free = FALSE; inst->dirty = FALSE; - qof_entity_release (&inst->entity); + qof_int_entity_release (&inst->entity); } const GUID * diff --git a/lib/libqof/qof/qofreference.c b/lib/libqof/qof/qofreference.c index f7cecc933f..36f7e8ecc4 100644 --- a/lib/libqof/qof/qofreference.c +++ b/lib/libqof/qof/qofreference.c @@ -122,7 +122,7 @@ create_reference(QofEntity *ent, const QofParam *param) char cm_sa[GUID_ENCODING_LENGTH + 1]; gchar *cm_string; - ref_ent = (QofEntity*)param->param_getfcn(ent, param); + ref_ent = QOF_ENTITY(param->param_getfcn(ent, param)); if(!ref_ent) { return NULL; } reference = g_new0(QofEntityReference, 1); reference->type = ent->e_type; diff --git a/lib/libqof/qof/qofsession.c b/lib/libqof/qof/qofsession.c index ea6f43051a..7333e045ec 100644 --- a/lib/libqof/qof/qofsession.c +++ b/lib/libqof/qof/qofsession.c @@ -514,7 +514,7 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data) registered_type = TRUE; } if(registered_type == FALSE) { -/* referenceEnt = (QofEntity*)cm_param->param_getfcn(importEnt, cm_param); +/* referenceEnt = QOF_ENTITY(cm_param->param_getfcn(importEnt, cm_param)); if(!referenceEnt) { return; } if(!referenceEnt->e_type) { return; }*/ reference = qof_entity_get_reference_from(importEnt, cm_param); @@ -555,7 +555,7 @@ qof_entity_list_foreach(gpointer data, gpointer user_data) const GUID *g; g_return_if_fail(data != NULL); - original = (QofEntity*)data; + original = QOF_ENTITY(data); g_return_if_fail(user_data != NULL); qecd = (QofEntityCopyData*)user_data; if(qof_entity_guid_match(qecd->new_session, original)) { return; } @@ -756,7 +756,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data) } continue; } - ref_ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param); + ref_ent = QOF_ENTITY(ref_param->param_getfcn(ent, ref_param)); if((ref_ent)&&(ref_ent->e_type)) { store->success = qof_entity_copy_to_session(session, ref_ent); @@ -766,7 +766,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data) for(i = ent_list; i != NULL; i = i->next) { if(i->data == NULL) { continue; } - child_ent = (QofEntity*)i->data; + child_ent = QOF_ENTITY(i->data); if(child_ent == NULL) { continue; } ref_list = qof_class_get_referenceList(child_ent->e_type); for(j = ref_list; j != NULL; j = j->next) @@ -784,7 +784,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data) for(i = child_list; i != NULL; i = i->next) { if(i->data == NULL) { continue; } - ref_ent = (QofEntity*)i->data; + ref_ent = QOF_ENTITY(i->data); if(ref_ent == NULL) { continue; } ref_list = qof_class_get_referenceList(ref_ent->e_type); for(j = ref_list; j != NULL; j = j->next) diff --git a/src/backend/postgres/book.c b/src/backend/postgres/book.c index 3897f37f46..aaebc121c3 100644 --- a/src/backend/postgres/book.c +++ b/src/backend/postgres/book.c @@ -139,7 +139,7 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("bookGuid",j), &guid); - qof_entity_set_guid ((QofEntity*)book, &guid); + qof_entity_set_guid (QOF_ENTITY(book), &guid); if((DB_GET_VAL("book_open",j))[0] == 'n') { @@ -208,14 +208,14 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) for (node=blist; node; node=node->next) { book = node->data; - if (guid_equal (qof_entity_get_guid((QofEntity*)book), &guid)) break; + if (guid_equal (qof_entity_get_guid(QOF_ENTITY(book)), &guid)) break; book = NULL; } if (!book) { book = qof_book_new(); - qof_entity_set_guid ((QofEntity*)book, &guid); + qof_entity_set_guid (QOF_ENTITY(book), &guid); } if((DB_GET_VAL("book_open",j))[0] == 'n') diff --git a/src/backend/postgres/events.c b/src/backend/postgres/events.c index be1fd0b86e..f704c31e2b 100644 --- a/src/backend/postgres/events.c +++ b/src/backend/postgres/events.c @@ -290,14 +290,14 @@ pgendProcessEvents (QofBackend *bend) /* if the remote user created an account, mirror it here */ acc = pgendCopyAccountToEngine (be, &(ev->guid)); - ent = (QofEntity*)acc; + ent = QOF_ENTITY(acc); break; } case QOF_EVENT_DESTROY: { Account * acc = pgendAccountLookup (be, &(ev->guid)); xaccAccountBeginEdit (acc); xaccAccountDestroy (acc); - ent = (QofEntity*)acc; + ent = QOF_ENTITY(acc); break; } } @@ -319,7 +319,7 @@ pgendProcessEvents (QofBackend *bend) /* don't mirror transaction creations. If a register needs * it, it will do a query. */ trans = pgendTransLookup (be, &(ev->guid)); - ent = (QofEntity*)trans; + ent = QOF_ENTITY(trans); PINFO ("create transaction"); break; } @@ -327,7 +327,7 @@ pgendProcessEvents (QofBackend *bend) Transaction *trans; trans = pgendTransLookup (be, &(ev->guid)); pgendCopyTransactionToEngine (be, &(ev->guid)); - ent = (QofEntity*)trans; + ent = QOF_ENTITY(trans); break; } case QOF_EVENT_DESTROY: { @@ -336,7 +336,7 @@ pgendProcessEvents (QofBackend *bend) /* mark trans for freeing */ xaccTransDestroy (trans); xaccTransCommitEdit (trans); - ent = (QofEntity*)trans; + ent = QOF_ENTITY(trans); break; } } diff --git a/src/business/business-core/gncInvoice.c b/src/business/business-core/gncInvoice.c index c4a3011fcd..f85451590a 100644 --- a/src/business/business-core/gncInvoice.c +++ b/src/business/business-core/gncInvoice.c @@ -463,14 +463,14 @@ static QofEntity* qofInvoiceGetOwner (GncInvoice *invoice) { if(!invoice) { return NULL; } - return (QofEntity*)&invoice->owner; + return QOF_ENTITY(&invoice->owner); } static QofEntity* qofInvoiceGetBillTo (GncInvoice *invoice) { if(!invoice) { return NULL; } - return (QofEntity*)&invoice->billto; + return QOF_ENTITY(&invoice->billto); } Timespec gncInvoiceGetDateOpened (GncInvoice *invoice) @@ -660,7 +660,7 @@ qofInvoiceGetEntries (GncInvoice *invoice) entry_coll = qof_collection_new(GNC_ID_ENTRY); for(list = gncInvoiceGetEntries(invoice); list != NULL; list = list->next) { - entry = (QofEntity*)list->data; + entry = QOF_ENTITY(list->data); qof_collection_add_entity(entry_coll, entry); } return entry_coll; diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c index ae0ad5bcb1..14d0cb5bb1 100644 --- a/src/business/business-core/gncJob.c +++ b/src/business/business-core/gncJob.c @@ -319,7 +319,7 @@ static QofEntity* qofJobGetOwner (GncJob *job) { if(!job) { return NULL; } - return (QofEntity*)qofOwnerGetOwner(&job->owner); + return QOF_ENTITY(qofOwnerGetOwner(&job->owner)); } /* Other functions */ diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index 2bbecb2859..85e6726a32 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -154,19 +154,19 @@ qofOwnerGetOwner (GncOwner *owner) break; } case GNC_OWNER_CUSTOMER : { - ent = (QofEntity*)owner->owner.customer; + ent = QOF_ENTITY(owner->owner.customer); break; } case GNC_OWNER_JOB : { - ent = (QofEntity*)owner->owner.job; + ent = QOF_ENTITY(owner->owner.job); break; } case GNC_OWNER_VENDOR : { - ent = (QofEntity*)owner->owner.vendor; + ent = QOF_ENTITY(owner->owner.vendor); break; } case GNC_OWNER_EMPLOYEE : { - ent = (QofEntity*)owner->owner.employee; + ent = QOF_ENTITY(owner->owner.employee); break; } } diff --git a/src/engine/test/test-recursive.c b/src/engine/test/test-recursive.c index 6bc9b81853..f738f2f545 100644 --- a/src/engine/test/test-recursive.c +++ b/src/engine/test/test-recursive.c @@ -258,7 +258,7 @@ grand_getDescend(mygrand *g) col = qof_collection_new(CHILD_MODULE_NAME); for(list = g_list_copy(g->descend);list;list=list->next) { - ent = (QofEntity*)list->data; + ent = QOF_ENTITY(list->data); if(!ent) { break; } do_test(0 == safe_strcmp(ent->e_type, CHILD_MODULE_NAME), "wrong entity"); qof_collection_add_entity(col, ent); @@ -871,7 +871,7 @@ create_data (QofSession *original, guint counter) { QofEntity *ent; - ent = (QofEntity*)child1; + ent = QOF_ENTITY(child1); qof_collection_add_entity(coll, ent); grand_setDescend(grand1, coll); qof_collection_destroy(coll); @@ -913,7 +913,7 @@ check_cb (QofEntity *ent, gpointer data) c->collect = qof_collection_count(coll); if(c->book) { qof_book_set_references(c->book); } param = qof_class_get_parameter(GRAND_MODULE_NAME, OBJ_RELATIVE); - parent = (QofEntity*)param->param_getfcn(ent, param); + parent = QOF_ENTITY(param->param_getfcn(ent, param)); testp = grand_getChild((mygrand*)ent); /* not all grandparents have family so just keep count. */ if(!parent) { c->nulls++; return; } diff --git a/src/gnome/dialog-chart-export.c b/src/gnome/dialog-chart-export.c index fe4e32d24c..b4073944fb 100644 --- a/src/gnome/dialog-chart-export.c +++ b/src/gnome/dialog-chart-export.c @@ -151,7 +151,7 @@ chart_entity_cb(QofEntity *ent, gpointer user_data) xaccSplitSetValue (split, balance); ref = qof_class_get_referenceList(GNC_ID_SPLIT); while(ref != NULL) { - ent_ref = qof_entity_get_reference_from((QofEntity*)split, ref->data); + ent_ref = qof_entity_get_reference_from(QOF_ENTITY(split), ref->data); qof_session_update_reference_list(data->chart_session, ent_ref); ref = g_list_next(ref); } @@ -168,14 +168,14 @@ chart_entity_cb(QofEntity *ent, gpointer user_data) xaccAccountCommitEdit (acc_ent); ref = qof_class_get_referenceList(GNC_ID_TRANS); while(ref != NULL) { - ent_ref = qof_entity_get_reference_from((QofEntity*)trans, ref->data); + ent_ref = qof_entity_get_reference_from(QOF_ENTITY(trans), ref->data); qof_session_update_reference_list(data->chart_session, ent_ref); ref = g_list_next(ref); } g_list_free(ref); ref = qof_class_get_referenceList(GNC_ID_SPLIT); while(ref != NULL) { - ent_ref = qof_entity_get_reference_from((QofEntity*)split, ref->data); + ent_ref = qof_entity_get_reference_from(QOF_ENTITY(split), ref->data); qof_session_update_reference_list(data->chart_session, ent_ref); ref = g_list_next(ref); } diff --git a/src/gnome/druid-hierarchy.c b/src/gnome/druid-hierarchy.c index b2249de1fb..978b93335c 100644 --- a/src/gnome/druid-hierarchy.c +++ b/src/gnome/druid-hierarchy.c @@ -754,7 +754,7 @@ balance_cell_edited (GtkCellRendererText *cell, g_object_set (G_OBJECT(cell), "text", "", NULL); } set_final_balance (data->balance_hash, account, amount); - qof_event_gen ((QofEntity*)account, QOF_EVENT_MODIFY, NULL); + qof_event_gen (QOF_ENTITY(account), QOF_EVENT_MODIFY, NULL); } static void