32 #include "qofinstance-p.h" 34 static QofLogModule log_module = QOF_MOD_ENGINE;
41 GHashTable * hash_of_entities;
51 col = g_new0(QofCollection, 1);
52 col->e_type =
static_cast<QofIdType>(CACHE_INSERT (type));
61 CACHE_REMOVE (col->e_type);
62 g_hash_table_destroy(col->hash_of_entities);
64 col->hash_of_entities = NULL;
90 g_hash_table_remove (col->hash_of_entities, guid);
91 qof_instance_set_collection(ent, NULL);
99 if (!col || !ent)
return;
102 g_return_if_fail (col->e_type == ent->
e_type);
103 qof_collection_remove_entity (ent);
104 g_hash_table_insert (col->hash_of_entities, (gpointer)guid, ent);
105 qof_instance_set_collection(ent, col);
124 g_return_val_if_fail (coll->e_type == ent->
e_type, FALSE);
130 g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
136 collection_compare_cb (
QofInstance *ent, gpointer user_data)
138 QofCollection *target;
144 target = (QofCollection*)user_data;
158 qof_collection_set_data(target, &value);
161 g_return_if_fail (target->e_type == ent->
e_type);
166 qof_collection_set_data(target, &value);
170 qof_collection_set_data(target, &value);
179 if (!target && !merge)
187 if (!target && merge)
191 if (target && !merge)
195 if (target->e_type != merge->e_type)
199 qof_collection_set_data(target, &value);
200 qof_collection_foreach(merge, collection_compare_cb, target);
204 qof_collection_set_data(merge, &value);
205 qof_collection_foreach(target, collection_compare_cb, merge);
215 g_return_val_if_fail (col, NULL);
216 if (guid == NULL)
return NULL;
217 ent =
static_cast<QofInstance*
>(g_hash_table_lookup (col->hash_of_entities,
231 for (list = glist; list != NULL; list = list->next)
233 ent = QOF_INSTANCE(list->data);
248 c = g_hash_table_size(col->hash_of_entities);
257 return col ? col->is_dirty : FALSE;
265 col->is_dirty = FALSE;
270 qof_collection_mark_dirty (QofCollection *col)
274 col->is_dirty = TRUE;
279 qof_collection_print_dirty (
const QofCollection *col, gpointer dummy)
282 printf(
"%s collection is dirty.\n", col->e_type);
291 return col ? col->data : NULL;
295 qof_collection_set_data (QofCollection *col, gpointer user_data)
299 col->data = user_data;
307 gpointer user_data, GCompareFunc sort_fn)
311 g_return_if_fail (col);
312 g_return_if_fail (cb_func);
314 PINFO(
"Hash Table size of %s before is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
316 entries = g_hash_table_get_values (col->hash_of_entities);
318 entries = g_list_sort (entries, sort_fn);
319 g_list_foreach (entries, (GFunc)cb_func, user_data);
320 g_list_free (entries);
322 PINFO(
"Hash Table size of %s after is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
#define PINFO(format, args...)
Print an informational note.
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
void(* QofInstanceForeachCB)(QofInstance *, gpointer user_data)
Callback type for qof_collection_foreach.
GHashTable * guid_hash_table_new(void)
Returns a GHashTable with <GUID*> as key and a <gpointer> as value and no destructor functions for ke...
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.
void qof_collection_foreach_sorted(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data, GCompareFunc sort_fn)
Call the callback for each entity in the collection.
gint qof_collection_compare(QofCollection *target, QofCollection *merge)
Compare two secondary collections.
const gchar * QofIdType
QofIdType declaration.
QofCollection * qof_collection_from_glist(QofIdType type, const GList *glist)
Create a secondary collection from a GList.
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
void qof_collection_insert_entity(QofCollection *col, QofInstance *ent)
Take entity, remove it from whatever collection its currently in, and place it in a new collection...
void qof_collection_mark_clean(QofCollection *col)
reset value of dirty flag
void qof_collection_destroy(QofCollection *col)
destroy the collection
QofIdType qof_collection_get_type(const QofCollection *col)
return the type that the collection stores
QofIdType e_type
Entity type.
gboolean qof_collection_add_entity(QofCollection *coll, QofInstance *ent)
Add an entity to a QOF_TYPE_COLLECT.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
guint qof_collection_count(const QofCollection *col)
return the number of entities in the collection.
gpointer qof_collection_get_data(const QofCollection *col)
Store and retrieve arbitrary object-defined data.
The type used to store guids in C.
QofCollection * qof_collection_new(QofIdType type)
create a new collection of entities of type