32 #include "qofinstance-p.h" 34 static QofLogModule log_module = QOF_MOD_ENGINE;
41 GHashTable * hash_of_entities;
50 CACHE_REMOVE (e_type);
51 g_hash_table_destroy (hash_of_entities);
60 return new QofCollection (type);
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;
160 g_return_if_fail (target->e_type == ent->
e_type);
176 if (!target && !merge)
184 if (!target && merge)
188 if (target && !merge)
192 if (target->e_type != merge->e_type)
196 qof_collection_set_data(target, &value);
197 qof_collection_foreach(merge, collection_compare_cb, target);
201 qof_collection_set_data(merge, &value);
202 qof_collection_foreach(target, collection_compare_cb, merge);
212 g_return_val_if_fail (col, NULL);
213 if (guid == NULL)
return NULL;
214 ent =
static_cast<QofInstance*
>(g_hash_table_lookup (col->hash_of_entities,
225 c = g_hash_table_size(col->hash_of_entities);
234 return col ? col->is_dirty : FALSE;
242 col->is_dirty = FALSE;
247 qof_collection_mark_dirty (QofCollection *col)
251 col->is_dirty = TRUE;
256 qof_collection_print_dirty (
const QofCollection *col, gpointer dummy)
259 printf(
"%s collection is dirty.\n", col->e_type);
268 return col ? col->data : NULL;
272 qof_collection_set_data (QofCollection *col, gpointer user_data)
276 col->data = user_data;
284 gpointer user_data, GCompareFunc sort_fn)
288 g_return_if_fail (col);
289 g_return_if_fail (cb_func);
291 PINFO(
"Hash Table size of %s before is %d", col->e_type, g_hash_table_size(col->hash_of_entities));
293 entries = g_hash_table_get_values (col->hash_of_entities);
295 entries = g_list_sort (entries, sort_fn);
296 g_list_foreach (entries, (GFunc)cb_func, user_data);
297 g_list_free (entries);
299 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