changes to use more generic 'collection of entities' functions

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9568 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2003-10-19 05:11:07 +00:00
parent 8c8871f65d
commit b10828a439
23 changed files with 808 additions and 615 deletions
+2 -14
View File
@@ -2807,19 +2807,7 @@ xaccAccountFindTransByDesc(Account *account, const char *description)
}
/* ================================================================ */
/* gncObject function implementation and registration */
static void
account_foreach (QofBook *book, QofForeachCB cb, gpointer ud)
{
QofCollection *col;
g_return_if_fail (book);
g_return_if_fail (cb);
col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
qof_collection_foreach (col, (QofEntityForeachCB) cb, ud);
}
/* QofObject function implementation and registration */
static QofObject account_object_def = {
interface_version: QOF_OBJECT_VERSION,
@@ -2829,7 +2817,7 @@ static QofObject account_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: account_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccAccountGetName
};
+32 -14
View File
@@ -84,33 +84,51 @@ xaccMallocAccountGroup (QofBook *book)
/********************************************************************\
\********************************************************************/
#define GNC_TOP_GROUP "gnc_top_group"
AccountGroup *
xaccCollGetAccountGroup (QofCollection *col)
{
if (!col) return NULL;
return qof_collection_get_data (col);
}
void
xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp)
{
AccountGroup *old_grp;
if (!col) return;
old_grp = xaccCollGetAccountGroup (col);
if (old_grp == grp) return;
qof_collection_set_data (col, grp);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
}
AccountGroup *
xaccGetAccountGroup (QofBook *book)
{
QofCollection *col;
if (!book) return NULL;
return qof_book_get_data (book, GNC_TOP_GROUP);
col = qof_book_get_collection (book, GNC_ID_GROUP);
return xaccCollGetAccountGroup (col);
}
void
xaccSetAccountGroup (QofBook *book, AccountGroup *grp)
{
AccountGroup *old_grp;
QofCollection *col;
if (!book) return;
old_grp = xaccGetAccountGroup (book);
if (old_grp == grp) return;
if (grp && grp->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
qof_book_set_data (book, GNC_TOP_GROUP, grp);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
col = qof_book_get_collection (book, GNC_ID_GROUP);
xaccCollSetAccountGroup (col, grp);
}
/********************************************************************\
@@ -1229,15 +1247,15 @@ group_book_end (QofBook *book)
}
static gboolean
group_is_dirty (QofBook *book)
group_is_dirty (QofCollection *col)
{
return xaccGroupNotSaved(xaccGetAccountGroup(book));
return xaccGroupNotSaved(xaccCollGetAccountGroup(col));
}
static void
group_mark_clean(QofBook *book)
group_mark_clean(QofCollection *col)
{
xaccGroupMarkSaved(xaccGetAccountGroup(book));
xaccGroupMarkSaved(xaccCollGetAccountGroup(col));
}
static QofObject group_object_def =
+1
View File
@@ -46,6 +46,7 @@ AccountGroup *xaccMallocAccountGroup (QofBook *book);
* account group associated with the indicated book.
*/
AccountGroup * xaccGetAccountGroup (QofBook *book);
AccountGroup * xaccCollGetAccountGroup (QofCollection *col);
/*
* The xaccAccountDestroy() routine will destroy and free all
+1
View File
@@ -95,6 +95,7 @@ void xaccFreeAccountGroup (AccountGroup *account_group);
/* Set the top-level group in the book */
void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
void xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp);
/*
* The xaccGroupGetBackend() subroutine will find the
+5 -1
View File
@@ -35,19 +35,23 @@
#define GNC_SX_BOOK_P_H
#include "qofbook.h"
#include "qofid.h"
/* ====================================================================== */
struct xaccSchedXactionsDef {
QofBook *book;
GList *sx_list;
gboolean sx_notsaved;
};
void gnc_book_set_schedxactions( QofBook *book, GList *newList );
void gnc_collection_set_schedxactions( QofCollection *col, GList *newList );
/* Associate the given template group with a book */
void gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup);
void gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup);
gboolean gnc_sxtt_register (void);
+131 -74
View File
@@ -54,33 +54,133 @@
static short module = MOD_SX;
/* XXX this whole file is crufty, it doesn't really use entities
* in the most efficient/best way */
/* ====================================================================== */
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
SchedXactions *
gnc_book_get_schedxaction_list( QofBook *book )
AccountGroup *
gnc_collection_get_template_group( QofCollection *col )
{
if ( book == NULL ) return NULL;
return qof_book_get_data (book, GNC_SCHEDXACTIONS);
return qof_collection_get_data (col);
}
AccountGroup *
gnc_book_get_template_group( QofBook *book )
{
QofCollection *col;
if (!book) return NULL;
col = qof_book_get_collection (book, GNC_ID_SXTG);
return gnc_collection_get_template_group (col);
}
void
gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup)
{
AccountGroup *old_grp;
if (!col) return;
old_grp = gnc_collection_get_template_group (col);
if (old_grp == templateGroup) return;
qof_collection_set_data (col, templateGroup);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
}
void
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
{
QofCollection *col;
if (!book) return;
if (templateGroup && templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
col = qof_book_get_collection (book, GNC_ID_SXTG);
gnc_collection_set_template_group (col, templateGroup);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
static void
sxtg_book_begin (QofBook *book)
{
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
sxtg_book_end (QofBook *book)
{
gnc_book_set_template_group (book, NULL);
}
static gboolean
sxtg_is_dirty(QofCollection *col)
{
return xaccGroupNotSaved(gnc_collection_get_template_group(col));
}
static void
sxtg_mark_clean(QofCollection *col)
{
xaccGroupMarkSaved(gnc_collection_get_template_group(col));
}
static QofObject sxtg_object_def =
{
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_SXTG,
type_label: "Scheduled Transaction Templates",
book_begin: sxtg_book_begin,
book_end: sxtg_book_end,
is_dirty: sxtg_is_dirty,
mark_clean: sxtg_mark_clean,
foreach: NULL,
printable: NULL,
};
/* ====================================================================== */
SchedXactions *
gnc_collection_get_schedxaction_list( QofCollection *col)
{
return qof_collection_get_data (col);
}
GList *
gnc_collection_get_schedxactions( QofCollection *col)
{
SchedXactions *list;
list = qof_collection_get_data (col);
if (list) return list->sx_list;
return NULL;
}
GList *
gnc_book_get_schedxactions( QofBook *book )
{
SchedXactions *list;
if ( book == NULL ) return NULL;
list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
if (list) return list->sx_list;
return NULL;
QofCollection *col;
col = qof_book_get_collection (book, GNC_ID_SXTT);
return gnc_collection_get_schedxactions (col);
}
void
gnc_book_set_schedxactions( QofBook *book, GList *newList )
gnc_collection_set_schedxactions( QofCollection *col, GList *newList )
{
SchedXactions *old_list, *new_list;
if ( book == NULL ) return;
if ( col == NULL ) return;
old_list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
old_list = qof_collection_get_data (col);
if (old_list && old_list->sx_list == newList)
{
/* Assume the worst, that any 'set' means the data has
@@ -90,73 +190,39 @@ gnc_book_set_schedxactions( QofBook *book, GList *newList )
}
new_list = g_new (SchedXactions, 1);
new_list->book = book;
new_list->sx_list = newList;
new_list->sx_notsaved = TRUE;
if (NULL == newList) new_list->sx_notsaved = FALSE;
qof_book_set_data (book, GNC_SCHEDXACTIONS, new_list);
qof_collection_set_data (col, new_list);
g_free (old_list);
}
/* ====================================================================== */
#define GNC_TEMPLATE_GROUP "gnc_template_group"
AccountGroup *
gnc_book_get_template_group( QofBook *book )
{
if (!book) return NULL;
return qof_book_get_data (book, GNC_TEMPLATE_GROUP);
}
void
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
gnc_book_set_schedxactions( QofBook *book, GList *newList )
{
AccountGroup *old_grp;
if (!book) return;
QofCollection *col;
if ( book == NULL ) return;
if (templateGroup && templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
col = qof_book_get_collection (book, GNC_ID_SXTT);
gnc_collection_set_schedxactions (col, newList);
}
old_grp = gnc_book_get_template_group (book);
if (old_grp == templateGroup) return;
qof_book_set_data (book, GNC_TEMPLATE_GROUP, templateGroup);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
/* XXX Its not clear to me if the template group and the sched xactions
* should be treated together or not. I got lazy, and mashed them together.
* For right now, this works. If you feel you need to slit this up into
* two separate gnc Objects, that's OK with me.
*/
/* SX-trans stuff */
static void
sxtt_book_begin (QofBook *book)
{
gnc_book_set_schedxactions (book, NULL);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
sxtt_book_end (QofBook *book)
{
gnc_book_set_template_group (book, NULL);
gnc_book_set_schedxactions (book, NULL);
}
/* ====================================================================== */
/* dirty flag stuff */
static void
mark_sx_clean(gpointer data, gpointer user_data)
{
@@ -165,33 +231,31 @@ mark_sx_clean(gpointer data, gpointer user_data)
}
static void
book_sxns_mark_saved(QofBook *book)
book_sxns_mark_saved(QofCollection *col)
{
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
sxl = gnc_collection_get_schedxaction_list (col);
if (sxl) sxl->sx_notsaved = FALSE;
g_list_foreach(gnc_book_get_schedxactions(book),
g_list_foreach(gnc_collection_get_schedxactions(col),
mark_sx_clean,
NULL);
}
static gboolean
book_sxlist_notsaved(QofBook *book)
book_sxlist_notsaved(QofCollection *col)
{
GList *sxlist;
SchedXaction *sx;
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if((sxl && sxl->sx_notsaved)
||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
sxl = gnc_collection_get_schedxaction_list (col);
if((sxl && sxl->sx_notsaved)) return TRUE;
for(sxlist = gnc_book_get_schedxactions(book);
for(sxlist = gnc_collection_get_schedxactions(col);
sxlist != NULL;
sxlist = g_list_next(sxlist))
{
SchedXaction *sx;
sx = (SchedXaction *) (sxlist->data);
if (xaccSchedXactionIsDirty( sx ))
return TRUE;
@@ -200,23 +264,15 @@ book_sxlist_notsaved(QofBook *book)
return FALSE;
}
static void
sxtt_mark_clean(QofBook *book)
{
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
}
static QofObject sxtt_object_def =
{
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_SXTT,
type_label: "SXTT",
type_label: "Scheduled Transaction Templates",
book_begin: sxtt_book_begin,
book_end: sxtt_book_end,
is_dirty: book_sxlist_notsaved,
mark_clean: sxtt_mark_clean,
mark_clean: book_sxns_mark_saved,
foreach: NULL,
printable: NULL,
};
@@ -224,6 +280,7 @@ static QofObject sxtt_object_def =
gboolean
gnc_sxtt_register (void)
{
return qof_object_register (&sxtg_object_def);
return qof_object_register (&sxtt_object_def);
}
+8 -1
View File
@@ -27,6 +27,9 @@
* @brief Anchor Scheduled Transaction info in a book.
* See src/doc/books.txt for design overview.
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
*
* XXX currently, this is crufty, it should be modified to use
* entities a bit more whole-heartedly than it does.
**/
#ifndef GNC_SX_BOOK_H
@@ -38,15 +41,19 @@
#include "gnc-engine.h"
#include "qofbook.h"
#include "qofid.h"
typedef struct xaccSchedXactionsDef SchedXactions;
SchedXactions * gnc_book_get_schedxaction_list( QofBook *book );
SchedXactions * gnc_collection_get_schedxaction_list( QofCollection *col);
GList * gnc_collection_get_schedxactions( QofCollection *col);
GList * gnc_book_get_schedxactions( QofBook *book );
/** Returns the template group from the book.
**/
AccountGroup * gnc_book_get_template_group (QofBook *book);
AccountGroup * gnc_collection_get_template_group( QofCollection *col );
#endif /* GNC_SX_BOOK_H */
/** @} */
+4 -22
View File
@@ -3179,18 +3179,9 @@ xaccTransReverse (Transaction *trans)
/********************************************************************\
\********************************************************************/
/* gncObject function implementation */
/* QofObject function implementation */
static void
split_foreach (QofBook *book, QofForeachCB fcn, gpointer user_data)
{
QofCollection *col;
g_return_if_fail (book);
col = qof_book_get_collection (book, GNC_ID_SPLIT);
qof_collection_foreach (col, (QofEntityForeachCB) fcn, user_data);
}
/* Hook into the gncObject registry */
/* Hook into the QofObject registry */
static QofObject split_object_def = {
interface_version: QOF_OBJECT_VERSION,
@@ -3200,7 +3191,7 @@ static QofObject split_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: split_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccSplitGetMemo
};
@@ -3284,15 +3275,6 @@ gboolean xaccSplitRegister (void)
return qof_object_register (&split_object_def);
}
static void
trans_foreach (QofBook *book, QofForeachCB fcn, gpointer user_data)
{
QofCollection *col;
g_return_if_fail (book);
col = qof_book_get_collection (book, GNC_ID_TRANS);
qof_collection_foreach (col, (QofEntityForeachCB) fcn, user_data);
}
static QofObject trans_object_def = {
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_TRANS,
@@ -3301,7 +3283,7 @@ static QofObject trans_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: trans_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccTransGetDescription
};
+2
View File
@@ -40,9 +40,11 @@
#define SAFE_STRCMP_REAL(fcn,da,db) { \
if ((da) && (db)) { \
if ((da) != (db)) { \
int retval = fcn ((da), (db)); \
/* if strings differ, return */ \
if (retval) return retval; \
} \
} else \
if ((!(da)) && (db)) { \
return -1; \
+2 -1
View File
@@ -68,7 +68,8 @@
#define GNC_ID_PRICEDB "PriceDB"
#define GNC_ID_SPLIT "Split"
#define GNC_ID_SCHEDXACTION "SchedXaction"
#define GNC_ID_SXTT "SXTT"
#define GNC_ID_SXTG "SXTGroup"
#define GNC_ID_SXTT "SXTTrans"
#define GNC_ID_TRANS "Trans"
/* TYPES **********************************************************/
+2
View File
@@ -100,6 +100,8 @@ typedef struct gnc_price_lookup_helper_s
#define gnc_price_set_guid(P,G) qof_entity_set_guid(QOF_ENTITY(P),(G))
void gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db);
void gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db);
void gnc_pricedb_mark_clean(GNCPriceDB *db);
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
+31 -17
View File
@@ -678,29 +678,43 @@ gnc_pricedb_destroy(GNCPriceDB *db)
/* ==================================================================== */
#define GNC_PRICEDB "gnc_pricedb"
GNCPriceDB *
gnc_collection_get_pricedb(QofCollection *col)
{
return qof_collection_get_data (col);
}
GNCPriceDB *
gnc_pricedb_get_db(QofBook *book)
{
QofCollection *col;
if (!book) return NULL;
return qof_book_get_data (book, GNC_PRICEDB);
col = qof_book_get_collection (book, GNC_ID_PRICE);
return gnc_collection_get_pricedb (col);
}
void
gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db)
{
GNCPriceDB *old_db;
if(!col) return;
old_db = qof_collection_get_data (col);
if (db == old_db) return;
qof_collection_set_data (col, db);
gnc_pricedb_destroy (old_db);
}
void
gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db)
{
GNCPriceDB *old_db;
QofCollection *col;
if(!book) return;
old_db = gnc_pricedb_get_db (book);
if (db == old_db) return;
qof_book_set_data (book, GNC_PRICEDB, db);
col = qof_book_get_collection (book, GNC_ID_PRICE);
gnc_collection_set_pricedb (col, db);
if (db) db->book = book;
gnc_pricedb_destroy (old_db);
}
/* ==================================================================== */
@@ -1942,15 +1956,15 @@ pricedb_book_end (QofBook *book)
}
static gboolean
pricedb_is_dirty (QofBook *book)
pricedb_is_dirty (QofCollection *col)
{
return gnc_pricedb_dirty(gnc_pricedb_get_db(book));
return gnc_pricedb_dirty(gnc_collection_get_pricedb(col));
}
static void
pricedb_mark_clean(QofBook *book)
pricedb_mark_clean(QofCollection *col)
{
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
gnc_pricedb_mark_clean(gnc_collection_get_pricedb(col));
}
/* ==================================================================== */
@@ -2002,9 +2016,9 @@ void_unstable_price_traversal(GNCPriceDB *db,
}
static void
pricedb_foreach(QofBook *book, QofForeachCB cb, gpointer data)
pricedb_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
{
GNCPriceDB *db = gnc_pricedb_get_db(book);
GNCPriceDB *db = gnc_collection_get_pricedb(col);
void_unstable_price_traversal(db,
(void (*)(GNCPrice *, gpointer)) cb,
data);
+2
View File
@@ -31,6 +31,7 @@
#include "gnc-numeric.h"
#include "guid.h"
#include "qofbook.h"
#include "qofid.h"
#include "qofinstance.h"
@@ -239,6 +240,7 @@ GNCPriceDB * gnc_pricedb_create(QofBook *book);
/** return the pricedb associated with the book */
GNCPriceDB * gnc_pricedb_get_db(QofBook *book);
GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col);
/** gnc_pricedb_destroy - destroy the given pricedb and unref all of
the prices it contains. This may not deallocate all of those
+12
View File
@@ -43,6 +43,18 @@
* manipulated by GnuCash. This is the top-most structure
* used for anchoring data.
*/
/** Lookup an entity by guid, returning pointer to the entity */
#define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({ \
QofEntity *val = NULL; \
if (guid && book) { \
QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
} \
(c_type *) val; \
})
typedef struct _QofBook QofBook;
/** GList of QofBook */
+3
View File
@@ -42,5 +42,8 @@ void qof_entity_set_guid (QofEntity *ent, const GUID *guid);
*/
void qof_collection_insert_entity (QofCollection *, QofEntity *);
/* reset value of dirty flag */
void qof_collection_mark_clean (QofCollection *);
void qof_collection_mark_dirty (QofCollection *);
#endif /* QOF_ID_P_H */
+42
View File
@@ -43,6 +43,7 @@ struct QofCollection_s
gboolean is_dirty;
GHashTable * hash_of_entities;
gpointer data; /* place where object class can hang arbitrari data */
};
/* =============================================================== */
@@ -152,6 +153,7 @@ qof_collection_new (QofIdType type)
col = g_new0(QofCollection, 1);
col->e_type = CACHE_INSERT (type);
col->hash_of_entities = g_hash_table_new (id_hash, id_compare);
col->data = NULL;
return col;
}
@@ -162,6 +164,7 @@ qof_collection_destroy (QofCollection *col)
g_hash_table_destroy(col->hash_of_entities);
col->e_type = NULL;
col->hash_of_entities = NULL;
col->data = NULL; /** XXX there should be a destroy notifier for this */
g_free (col);
}
@@ -207,6 +210,45 @@ qof_collection_lookup_entity (QofCollection *col, const GUID * guid)
/* =============================================================== */
gboolean
qof_collection_is_dirty (QofCollection *col)
{
if (!col) return FALSE;
return col->is_dirty;
}
void
qof_collection_mark_clean (QofCollection *col)
{
if (!col) return;
col->is_dirty = FALSE;
}
void
qof_collection_mark_dirty (QofCollection *col)
{
if (!col) return;
col->is_dirty = TRUE;
}
/* =============================================================== */
gpointer
qof_collection_get_data (QofCollection *col)
{
if (!col) return NULL;
return col->data;
}
void
qof_collection_set_data (QofCollection *col, gpointer user_data)
{
if (!col) return;
col->data = user_data;
}
/* =============================================================== */
struct _iterate {
QofEntityForeachCB fcn;
gpointer data;
+38
View File
@@ -52,6 +52,7 @@
* type of the identifier.
*/
#include <string.h>
#include "guid.h"
typedef const char * QofIdType;
@@ -65,6 +66,37 @@ typedef const char * QofIdTypeConst;
/* 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) ({ \
int val = 0; \
if ((da) && (db)) { \
if ((da) != (db)) { \
val = strcmp ((da), (db)); \
} \
} else \
if ((!(da)) && (db)) { \
val = -1; \
} else \
if ((da) && (!(db))) { \
val = 1; \
} \
val; /* block assumes value of last statment */ \
})
/** return TRUE if object is of the given type */
#define QOF_CHECK_TYPE(obj,type) (0 == QSTRCMP((type),(((QofEntity *)(obj))->e_type)))
/** cast object to the indicated type, print error message if its bad */
#define QOF_CHECK_CAST(obj,e_type,c_type) ( \
QOF_CHECK_TYPE((obj),(e_type)) ? \
(c_type *) (obj) : \
(c_type *) ({ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
"Error: Bad QofEntity at %s:%d", __FILE__, __LINE__); \
(obj); \
}))
typedef struct QofEntity_s QofEntity;
typedef struct QofCollection_s QofCollection;
@@ -102,6 +134,12 @@ typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data);
void qof_collection_foreach (QofCollection *,
QofEntityForeachCB, gpointer user_data);
/** store and retreive arbitrary object-defined data */
gpointer qof_collection_get_data (QofCollection *col);
void qof_collection_set_data (QofCollection *col, gpointer user_data);
/* Return value of 'dirty' flag on collection */
gboolean qof_collection_is_dirty (QofCollection *col);
#endif /* QOF_ID_H */
+26 -11
View File
@@ -75,29 +75,40 @@ void qof_object_book_end (QofBook *book)
LEAVE (" ");
}
gboolean qof_object_is_dirty (QofBook *book)
gboolean
qof_object_is_dirty (QofBook *book)
{
GList *l;
if (!book) return FALSE;
for (l = object_modules; l; l = l->next) {
for (l = object_modules; l; l = l->next)
{
QofObject *obj = l->data;
if (obj->is_dirty)
if (obj->is_dirty (book))
return TRUE;
{
QofCollection *col;
col = qof_book_get_collection (book, obj->e_type);
if (obj->is_dirty (col)) return TRUE;
}
}
return FALSE;
}
void qof_object_mark_clean (QofBook *book)
void
qof_object_mark_clean (QofBook *book)
{
GList *l;
if (!book) return;
for (l = object_modules; l; l = l->next) {
for (l = object_modules; l; l = l->next)
{
QofObject *obj = l->data;
if (obj->mark_clean)
(obj->mark_clean) (book);
{
QofCollection *col;
col = qof_book_get_collection (book, obj->e_type);
(obj->mark_clean) (col);
}
}
}
@@ -113,21 +124,25 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data)
}
}
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofForeachCB cb, gpointer user_data)
void
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data)
{
QofCollection *col;
const QofObject *obj;
if (!book || !type_name) return;
ENTER ("type=%s", type_name);
obj = qof_object_lookup (type_name);
col = qof_book_get_collection (book, obj->e_type);
PINFO ("lookup obj=%p for type=%s", obj, type_name);
if (!obj) return;
PINFO ("type=%s foreach=%p", type_name, obj->foreach);
if (obj->foreach) {
obj->foreach (book, cb, user_data);
if (obj->foreach)
{
obj->foreach (col, cb, user_data);
}
LEAVE ("type=%s", type_name);
+9 -5
View File
@@ -31,6 +31,7 @@
#define QOF_OBJECT_H_
#include "qofbook.h"
#include "qofid.h"
/* Defines the version of the core object object registration
* interface. Only object modules compiled against this version
@@ -46,7 +47,10 @@ typedef void (*QofForeachBackendTypeCB) (QofIdTypeConst type,
gpointer backend_data,
gpointer user_data);
/** This is the QofObject Class descriptor */
/** This is the QofObject Class descriptor
*
* XXX Hmm, should we add an object factory to this?
*/
struct _QofObject
{
gint interface_version; /* of this object interface */
@@ -62,15 +66,15 @@ struct _QofObject
void (*book_end)(QofBook *);
/* Determine if there are any dirty items in this book */
gboolean (*is_dirty)(QofBook *);
gboolean (*is_dirty)(QofCollection *);
/* Mark this object's book clean (for after a load) */
void (*mark_clean)(QofBook *);
void (*mark_clean)(QofCollection *);
/* foreach() is used to execute a callback over each object
* stored in the particular book
*/
void (*foreach)(QofBook *, QofForeachCB, gpointer);
void (*foreach)(QofCollection *, QofEntityForeachCB, gpointer);
/* Given a particular object, return a printable string */
/* Argument should really be QofInstance not gpointer.. */
@@ -87,7 +91,7 @@ void qof_object_shutdown (void);
void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data);
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofForeachCB cb, gpointer user_data);
QofEntityForeachCB cb, gpointer user_data);
const char * qof_object_printable (QofIdTypeConst type_name, gpointer obj);
+1 -1
View File
@@ -743,7 +743,7 @@ GList * qof_query_run (QofQuery *q)
}
/* and then iterate over all the objects */
qof_object_foreach (q->search_for, book, check_item_cb, &qcb);
qof_object_foreach (q->search_for, book, (QofEntityForeachCB) check_item_cb, &qcb);
}
matching_objects = qcb.list;
+2 -2
View File
@@ -3,10 +3,10 @@
#include "gnc-engine-util.h"
#include "gnc-book.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "qofbook.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
@@ -108,7 +108,7 @@ test_commodity(void)
gnc_commodity *coms[20];
QofBook *book;
book = gnc_book_new ();
book = qof_book_new ();
tbl = gnc_commodity_table_new ();
do_test(gnc_commodity_table_get_size(tbl) == 0,
+3 -3
View File
@@ -15,7 +15,7 @@
#include "FreqSpec.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "gnc-book.h"
#include "qofbook.h"
static QofBook *book;
@@ -533,7 +533,7 @@ guile_main ( void *closure, int argc, char* argv[] )
set_success_print(TRUE);
#endif
book = gnc_book_new ();
book = qof_book_new ();
test_once();
@@ -547,7 +547,7 @@ guile_main ( void *closure, int argc, char* argv[] )
test_composite();
gnc_book_destroy (book);
qof_book_destroy (book);
print_test_results();
exit (get_rv());
+24 -24
View File
@@ -6,14 +6,14 @@
#include "gnc-engine-util.h"
#include "messages.h"
#include "qofbook.h"
#include "qofobject.h"
#include "gncObject.h"
#include "test-stuff.h"
#define TEST_MODULE_NAME "object-test"
#define TEST_MODULE_DESC "Test Object"
static void foreach (QofBook *, QofForeachCB, gpointer);
static void obj_foreach (QofCollection *, QofEntityForeachCB, gpointer);
static const char * printable (gpointer obj);
static void test_printable (const char *name, gpointer obj);
static void test_foreach (QofBook *, const char *);
@@ -26,7 +26,7 @@ static QofObject bus_obj = {
NULL, /* destroy */
NULL, /* is dirty */
NULL, /* mark_clean */
foreach,
obj_foreach,
printable,
};
@@ -34,15 +34,15 @@ static void test_object (void)
{
/* Test the global registration and lookup functions */
{
do_test (!gncObjectRegister (NULL), "register NULL");
do_test (gncObjectRegister (&bus_obj), "register test object");
do_test (!gncObjectRegister (&bus_obj), "register test object again");
do_test (gncObjectLookup (TEST_MODULE_NAME) == &bus_obj,
do_test (!qof_object_register (NULL), "register NULL");
do_test (qof_object_register (&bus_obj), "register test object");
do_test (!qof_object_register (&bus_obj), "register test object again");
do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj,
"lookup our installed object");
do_test (gncObjectLookup ("snm98sn snml say dyikh9y9ha") == NULL,
do_test (qof_object_lookup ("snm98sn snml say dyikh9y9ha") == NULL,
"lookup non-existant object object");
do_test (!safe_strcmp (gncObjectGetTypeLabel (TEST_MODULE_NAME),
do_test (!safe_strcmp (qof_object_get_type_label (TEST_MODULE_NAME),
_(TEST_MODULE_DESC)),
"test description return");
}
@@ -52,17 +52,17 @@ static void test_object (void)
}
static void
foreach (QofBook *book, QofForeachCB cb, gpointer u_d)
obj_foreach (QofCollection *col, QofEntityForeachCB cb, gpointer u_d)
{
int *foo = u_d;
do_test (book != NULL, "foreach: NULL object");
do_test (col != NULL, "foreach: NULL collection");
success ("called foreach callback");
*foo = 1;
}
static void foreachCB (gpointer obj, gpointer u_d)
static void foreachCB (QofEntity *ent, gpointer u_d)
{
do_test (FALSE, "FAIL");
}
@@ -80,26 +80,26 @@ test_foreach (QofBook *book, const char *name)
{
int res = 0;
gncObjectForeach (NULL, NULL, NULL, &res);
qof_object_foreach (NULL, NULL, NULL, &res);
do_test (res == 0, "object: Foreach: NULL, NULL, NULL");
gncObjectForeach (NULL, NULL, foreachCB, &res);
qof_object_foreach (NULL, NULL, foreachCB, &res);
do_test (res == 0, "object: Foreach: NULL, NULL, foreachCB");
gncObjectForeach (NULL, book, NULL, &res);
qof_object_foreach (NULL, book, NULL, &res);
do_test (res == 0, "object: Foreach: NULL, book, NULL");
gncObjectForeach (NULL, book, foreachCB, &res);
qof_object_foreach (NULL, book, foreachCB, &res);
do_test (res == 0, "object: Foreach: NULL, book, foreachCB");
gncObjectForeach (name, NULL, NULL, &res);
qof_object_foreach (name, NULL, NULL, &res);
do_test (res == 0, "object: Foreach: name, NULL, NULL");
gncObjectForeach (name, NULL, foreachCB, &res);
qof_object_foreach (name, NULL, foreachCB, &res);
do_test (res == 0, "object: Foreach: name, NULL, foreachCB");
gncObjectForeach (name, book, NULL, &res);
qof_object_foreach (name, book, NULL, &res);
do_test (res != 0, "object: Foreach: name, book, NULL");
res = 0;
gncObjectForeach (name, book, foreachCB, &res);
qof_object_foreach (name, book, foreachCB, &res);
do_test (res != 0, "object: Foreach: name, book, foreachCB");
}
@@ -108,13 +108,13 @@ test_printable (const char *name, gpointer obj)
{
const char *res;
do_test (gncObjectPrintable (NULL, NULL) == NULL,
do_test (qof_object_printable (NULL, NULL) == NULL,
"object: Printable: NULL, NULL");
do_test (gncObjectPrintable (NULL, obj) == NULL,
do_test (qof_object_printable (NULL, obj) == NULL,
"object: Printable: NULL, object");
do_test (gncObjectPrintable (name, NULL) == NULL,
do_test (qof_object_printable (name, NULL) == NULL,
"object: Printable: mod_name, NULL");
res = gncObjectPrintable (name, obj);
res = qof_object_printable (name, obj);
do_test (res != NULL, "object: Printable: mod_name, object");
}