35 struct QofCollection_s
40 GHashTable *hash_of_entities;
46 static void qof_collection_remove_entity (
QofEntity * ent);
51 g_return_if_fail (NULL != tab);
57 PERR (
"attempt to insert \"%s\" into \"%s\"", type, tab->e_type);
60 ent->e_type = CACHE_INSERT (type);
69 PWARN (
"duplicate id created, trying again");
73 ent->collection = tab;
83 qof_collection_remove_entity (ent);
84 CACHE_REMOVE (ent->e_type);
98 col = ent->collection;
99 qof_collection_remove_entity (ent);
115 id_hash (gconstpointer key)
117 const GUID *guid = key;
123 if (
sizeof (guint) <= 16)
124 return *((guint *) guid->data);
130 for (i = 0, j = 0; i <
sizeof (guint); i++, j++)
136 hash |= guid->data[j];
144 id_compare (gconstpointer key_1, gconstpointer key_2)
154 col->e_type = CACHE_INSERT (type);
155 col->hash_of_entities = g_hash_table_new (id_hash, id_compare);
163 CACHE_REMOVE (col->e_type);
164 g_hash_table_destroy (col->hash_of_entities);
166 col->hash_of_entities = NULL;
183 qof_collection_remove_entity (
QofEntity * ent)
188 col = ent->collection;
191 g_hash_table_remove (col->hash_of_entities, &ent->guid);
192 qof_collection_mark_dirty (col);
193 ent->collection = NULL;
203 g_return_if_fail (col->e_type == ent->e_type);
204 qof_collection_remove_entity (ent);
205 g_hash_table_insert (col->hash_of_entities, &ent->guid, ent);
206 qof_collection_mark_dirty (col);
207 ent->collection = col;
224 g_return_val_if_fail (coll->e_type == ent->e_type, FALSE);
230 g_hash_table_insert (coll->hash_of_entities, &ent->guid, ent);
231 qof_collection_mark_dirty (coll);
236 collection_merge_cb (
QofEntity * ent, gpointer data)
247 if (!target || !merge)
251 g_return_val_if_fail (target->e_type == merge->e_type, FALSE);
257 collection_compare_cb (
QofEntity * ent, gpointer user_data)
280 g_return_if_fail (target->e_type == ent->e_type);
298 if (!target && !merge)
302 if (!target && merge)
304 if (target && !merge)
306 if (target->e_type != merge->e_type)
324 g_return_val_if_fail (col, NULL);
327 ent = g_hash_table_lookup (col->hash_of_entities, guid);
339 for (list = glist; list != NULL; list = list->next)
355 c = g_hash_table_size (col->hash_of_entities);
364 return col ? col->is_dirty : FALSE;
372 col->is_dirty = FALSE;
381 col->is_dirty = TRUE;
390 return col ? col->data : NULL;
398 col->data = user_data;
411 foreach_cb (gpointer key __attribute__ ((unused)), gpointer item,
414 struct _iterate *qiter = arg;
417 qiter->fcn (ent, qiter->data);
424 struct _iterate qiter;
426 g_return_if_fail (col);
427 g_return_if_fail (cb_func);
430 qiter.data = user_data;
432 g_hash_table_foreach (col->hash_of_entities, foreach_cb, &qiter);