|
GnuCash 2.3.0
|
Files | |
| file | qofid.h |
QOF entity type identification system. | |
Defines | |
| #define | QOF_ID_NONE NULL |
| #define | QOF_ID_NULL "null" |
| #define | QOF_ID_BOOK "Book" |
| #define | QOF_ID_SESSION "Session" |
| #define | QSTRCMP(da, db) |
| #define | QOF_CHECK_TYPE(obj, type) |
| #define | QOF_CHECK_CAST(obj, e_type, c_type) |
Typedefs | |
| typedef const gchar * | QofIdType |
| typedef const gchar * | QofIdTypeConst |
| typedef const gchar * | QofLogModule |
| typedef struct QofCollection_s | QofCollection |
Functions | |
| gboolean | qof_get_alt_dirty_mode (void) |
| void | qof_set_alt_dirty_mode (gboolean enabled) |
Collections of Entities | |
| typedef void(* | QofInstanceForeachCB )(QofInstance *, gpointer user_data) |
| QofCollection * | qof_collection_new (QofIdType type) |
| guint | qof_collection_count (const QofCollection *col) |
| void | qof_collection_destroy (QofCollection *col) |
| QofIdType | qof_collection_get_type (const QofCollection *) |
| QofInstance * | qof_collection_lookup_entity (const QofCollection *, const GncGUID *) |
| void | qof_collection_foreach (const QofCollection *, QofInstanceForeachCB, gpointer user_data) |
| gpointer | qof_collection_get_data (const QofCollection *col) |
| void | qof_collection_set_data (QofCollection *col, gpointer user_data) |
| gboolean | qof_collection_is_dirty (const QofCollection *col) |
QOF_TYPE_COLLECT: Linking one entity to many of one type | |
QOF_TYPE_COLLECT is a secondary collection, used to select entities of one object type as references of another entity.
| |
| gboolean | qof_collection_add_entity (QofCollection *coll, QofInstance *ent) |
| Add an entity to a QOF_TYPE_COLLECT. | |
| void | qof_collection_remove_entity (QofInstance *ent) |
| gint | qof_collection_compare (QofCollection *target, QofCollection *merge) |
| Compare two secondary collections. | |
| QofCollection * | qof_collection_from_glist (QofIdType type, const GList *glist) |
| Create a secondary collection from a GList. | |
This file defines an API that adds types to the GncGUID's. GncGUID's with types can be used to identify and reference typed entities.
The idea here is that a GncGUID can be used to uniquely identify some thing. By adding a type, one can then talk about the type of thing identified. By adding a collection, one can then work with a handle to a collection of things of a given type, each uniquely identified by a given ID. QOF Entities can be used independently of any other part of the system. In particular, Entities can be useful even if one is not using the Query ond Object parts of the QOF system.
Identifiers are globally-unique and permanent, i.e., once an entity has been assigned an identifier, it retains that same identifier for its lifetime. Identifiers can be encoded as hex strings.
GncGUID Identifiers are 'typed' with strings. The native ids used by QOF are defined below.
If you have a type name, and you want to have a way of finding a collection that is associated with that type, then you must use Books.
Entities can refer to other entities as well as to the basic QOF types, using the qofclass parameters.
| #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 QofInstance at %s:%d", __FILE__, __LINE__); \ (obj); \ }))
cast object to the indicated type, print error message if its bad
| #define QOF_CHECK_TYPE | ( | obj, | |
| type | |||
| ) |
(((obj) != NULL) && \ (0 == QSTRCMP((type),(((QofInstance *)(obj))->e_type))))
return TRUE if object is of the given type
| #define QSTRCMP | ( | da, | |
| db | |||
| ) |
({ \
gint 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 statement */ \
})
Inline string comparision; compiler will optimize away most of this
| typedef const gchar* QofIdTypeConst |
| typedef void(* QofInstanceForeachCB)(QofInstance *, gpointer user_data) |
| typedef const gchar* QofLogModule |
| gboolean qof_collection_add_entity | ( | QofCollection * | coll, |
| QofInstance * | ent | ||
| ) |
Add an entity to a QOF_TYPE_COLLECT.
Entities can be freely added and merged across these secondary collections, they will not be removed from the original collection as they would by using ::qof_instance_insert_entity or ::qof_instance_remove_entity.
Definition at line 127 of file qofid.c.
{
QofInstance *e;
const GncGUID *guid;
e = NULL;
if (!coll || !ent)
{
return FALSE;
}
guid = qof_instance_get_guid(ent);
if (guid_equal(guid, guid_null()))
{
return FALSE;
}
g_return_val_if_fail (coll->e_type == ent->e_type, FALSE);
e = qof_collection_lookup_entity(coll, guid);
if ( e != NULL )
{
return FALSE;
}
g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
if (!qof_alt_dirty_mode)
qof_collection_mark_dirty(coll);
return TRUE;
}
| gint qof_collection_compare | ( | QofCollection * | target, |
| QofCollection * | merge | ||
| ) |
Compare two secondary collections.
Performs a deep comparision of the collections. Each QofInstance in each collection is looked up in the other collection, via the GncGUID.
Definition at line 194 of file qofid.c.
{
gint value;
value = 0;
if (!target && !merge)
{
return 0;
}
if (target == merge)
{
return 0;
}
if (!target && merge)
{
return -1;
}
if (target && !merge)
{
return 1;
}
if (target->e_type != merge->e_type)
{
return -1;
}
qof_collection_set_data(target, &value);
qof_collection_foreach(merge, collection_compare_cb, target);
value = *(gint*)qof_collection_get_data(target);
if (value == 0)
{
qof_collection_set_data(merge, &value);
qof_collection_foreach(target, collection_compare_cb, merge);
value = *(gint*)qof_collection_get_data(merge);
}
return value;
}
| guint qof_collection_count | ( | const QofCollection * | col | ) |
| void qof_collection_destroy | ( | QofCollection * | col | ) |
| void qof_collection_foreach | ( | const QofCollection * | , |
| QofInstanceForeachCB | , | ||
| gpointer | user_data | ||
| ) |
Call the callback for each entity in the collection.
Definition at line 338 of file qofid.c.
{
struct _iterate iter;
GList *entries;
g_return_if_fail (col);
g_return_if_fail (cb_func);
iter.fcn = cb_func;
iter.data = user_data;
PINFO("Hash Table size of %s before is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
entries = g_hash_table_get_values (col->hash_of_entities);
g_list_foreach (entries, foreach_cb, &iter);
g_list_free (entries);
PINFO("Hash Table size of %s after is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
}
| QofCollection* qof_collection_from_glist | ( | QofIdType | type, |
| const GList * | glist | ||
| ) |
Create a secondary collection from a GList.
| type | The QofIdType of the QofCollection and of all entities in the GList. |
| glist | GList of entities of the same QofIdType. |
Definition at line 242 of file qofid.c.
{
QofCollection *coll;
QofInstance *ent;
const GList *list;
coll = qof_collection_new(type);
for (list = glist; list != NULL; list = list->next)
{
ent = QOF_INSTANCE(list->data);
if (FALSE == qof_collection_add_entity(coll, ent))
{
return NULL;
}
}
return coll;
}
| gpointer qof_collection_get_data | ( | const QofCollection * | col | ) |
| QofIdType qof_collection_get_type | ( | const QofCollection * | ) |
| gboolean qof_collection_is_dirty | ( | const QofCollection * | col | ) |
| QofInstance* qof_collection_lookup_entity | ( | const QofCollection * | , |
| const GncGUID * | |||
| ) |
Find the entity going only from its guid
Definition at line 232 of file qofid.c.
{
QofInstance *ent;
g_return_val_if_fail (col, NULL);
if (guid == NULL) return NULL;
ent = g_hash_table_lookup (col->hash_of_entities, guid);
return ent;
}
| QofCollection* qof_collection_new | ( | QofIdType | type | ) |
create a new collection of entities of type
Definition at line 62 of file qofid.c.
{
QofCollection *col;
col = g_new0(QofCollection, 1);
col->e_type = CACHE_INSERT (type);
col->hash_of_entities = guid_hash_table_new();
col->data = NULL;
return col;
}
| gboolean qof_get_alt_dirty_mode | ( | void | ) |
QofCollection declaration
| e_type | QofIdType |
| is_dirty | gboolean |
| hash_of_entities | GHashTable |
| data | gpointer, place where object class can hang arbitrary data Is QOF operating in "alternate" dirty mode? |
In normal mode, whenever an instance is dirtied, the collection (and therefore the book) is immediately marked as dirty. In alternate mode, the collection is only marked dirty when a dirty instance is committed. If a dirty instance is freed instead of committed, the dirty state of collection (and therefore the book) is never changed.
Definition at line 48 of file qofid.c.
{
return qof_alt_dirty_mode;
}
| void qof_set_alt_dirty_mode | ( | gboolean | enabled | ) |
Set QOF into "alternate" dirty mode. In normal mode, whenever an instance is dirtied, the collection (and therefore the book) is immediately marked as dirty. In alternate mode, the collection is only marked dirty when a dirty instance is committed. If a dirty instance is freed instead of committed, the dirty state of collection (and therefore the book) is never changed.
Definition at line 54 of file qofid.c.
{
qof_alt_dirty_mode = enabled;
}
1.7.4