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));
53 col->is_dirty = FALSE;
62 CACHE_REMOVE (col->e_type);
63 g_hash_table_destroy(col->hash_of_entities);
65 col->hash_of_entities = NULL;
91 g_hash_table_remove (col->hash_of_entities, guid);
92 qof_instance_set_collection(ent, NULL);
100 if (!col || !ent)
return;
103 g_return_if_fail (col->e_type == ent->
e_type);
104 qof_collection_remove_entity (ent);
105 g_hash_table_insert (col->hash_of_entities, (gpointer)guid, ent);
106 qof_instance_set_collection(ent, col);
125 g_return_val_if_fail (coll->e_type == ent->
e_type, FALSE);
131 g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
137 collection_compare_cb (
QofInstance *ent, gpointer user_data)
139 QofCollection *target;
145 target = (QofCollection*)user_data;
161 g_return_if_fail (target->e_type == ent->
e_type);
177 if (!target && !merge)
185 if (!target && merge)
189 if (target && !merge)
193 if (target->e_type != merge->e_type)
197 qof_collection_set_data(target, &value);
198 qof_collection_foreach(merge, collection_compare_cb, target);
202 qof_collection_set_data(merge, &value);
203 qof_collection_foreach(target, collection_compare_cb, merge);
213 g_return_val_if_fail (col, NULL);
214 if (guid == NULL)
return NULL;
215 ent =
static_cast<QofInstance*
>(g_hash_table_lookup (col->hash_of_entities,
226 c = g_hash_table_size(col->hash_of_entities);
235 return col ? col->is_dirty : FALSE;
243 col->is_dirty = FALSE;
248 qof_collection_mark_dirty (QofCollection *col)
252 col->is_dirty = TRUE;
257 qof_collection_print_dirty (
const QofCollection *col, gpointer dummy)
260 printf(
"%s collection is dirty.\n", col->e_type);
269 return col ? col->data : NULL;
273 qof_collection_set_data (QofCollection *col, gpointer user_data)
277 col->data = user_data;
285 gpointer user_data, GCompareFunc sort_fn)
289 g_return_if_fail (col);
290 g_return_if_fail (cb_func);
292 PINFO(
"Hash Table size of %s before is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
294 entries = g_hash_table_get_values (col->hash_of_entities);
296 entries = g_list_sort (entries, sort_fn);
297 g_list_foreach (entries, (GFunc)cb_func, user_data);
298 g_list_free (entries);
300 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.
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