mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Collapse two functions into their only caller. Move a third function
to the same file. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16003 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
e8208ae756
commit
80a0403ebb
@ -58,60 +58,6 @@ qof_set_alt_dirty_mode (gboolean enabled)
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
void
|
||||
qof_entity_init (QofInstance *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 (QofInstance *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_instance_set_guid (QofInstance *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);
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
static guint
|
||||
id_hash (gconstpointer key)
|
||||
{
|
||||
|
@ -134,9 +134,6 @@ print error message if its bad */
|
||||
@param data gpointer, place where object class can hang arbitrary data
|
||||
|
||||
*/
|
||||
void qof_entity_init (QofInstance *ent, QofIdType type, QofCollection * tab);
|
||||
void qof_entity_release (QofInstance *ent);
|
||||
void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
|
||||
|
||||
/** Is QOF operating in "alternate" dirty mode. In normal mode,
|
||||
* whenever an instance is dirtied, the collection (and therefore the
|
||||
|
@ -67,19 +67,49 @@ void
|
||||
qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
|
||||
{
|
||||
QofCollection *col;
|
||||
QofIdType col_type;
|
||||
|
||||
g_return_if_fail(QOF_IS_INSTANCE(inst));
|
||||
g_return_if_fail(!inst->book);
|
||||
|
||||
inst->book = book;
|
||||
col = qof_book_get_collection (book, type);
|
||||
qof_entity_init (inst, type, col);
|
||||
g_return_if_fail(col != NULL);
|
||||
|
||||
/* XXX We passed redundant info to this routine ... but I think that's
|
||||
* OK, it might eliminate programming errors. */
|
||||
|
||||
col_type = qof_collection_get_type(col);
|
||||
if (safe_strcmp(col_type, type)) {
|
||||
PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type);
|
||||
return;
|
||||
}
|
||||
inst->e_type = CACHE_INSERT (type);
|
||||
|
||||
do {
|
||||
guid_new(&inst->guid);
|
||||
|
||||
if (NULL == qof_collection_lookup_entity (col, &inst->guid))
|
||||
break;
|
||||
|
||||
PWARN("duplicate id created, trying again");
|
||||
} while(1);
|
||||
|
||||
inst->collection = col;
|
||||
|
||||
qof_collection_insert_entity (col, inst);
|
||||
}
|
||||
|
||||
static void
|
||||
qof_instance_dispose (GObject *instp)
|
||||
{
|
||||
QofInstance* inst = QOF_INSTANCE(instp);
|
||||
qof_entity_release (inst);
|
||||
|
||||
if (!inst->collection)
|
||||
return;
|
||||
qof_collection_remove_entity(inst);
|
||||
CACHE_REMOVE(inst->e_type);
|
||||
inst->e_type = NULL;
|
||||
G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp);
|
||||
}
|
||||
|
||||
@ -109,6 +139,18 @@ qof_instance_get_book (const QofInstance *inst)
|
||||
return inst->book;
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_set_guid (QofInstance *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);
|
||||
}
|
||||
|
||||
KvpFrame*
|
||||
qof_instance_get_slots (const QofInstance *inst)
|
||||
{
|
||||
|
@ -119,6 +119,9 @@ QofBook * qof_instance_get_book (const QofInstance *);
|
||||
/** Return the GUID of this instance */
|
||||
const GUID * qof_instance_get_guid (const QofInstance *);
|
||||
|
||||
/** Set the GUID of this instance */
|
||||
void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
|
||||
|
||||
/** Return the pointer to the kvp_data */
|
||||
KvpFrame* qof_instance_get_slots (const QofInstance *);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user