The idea here is that a GUID 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.
GUID 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.
Files | |
| file | qofid.h |
| QOF entity type identification system. | |
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 GUID *) |
| 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 | |
| |
| gboolean | qof_collection_add_entity (QofCollection *coll, QofInstance *ent) |
| Add an entity to a QOF_TYPE_COLLECT. | |
| void | qof_collection_remove_entity (QofInstance *ent) |
| gboolean | qof_collection_merge (QofCollection *target, QofCollection *merge) |
| Merge two QOF_TYPE_COLLECT of the same type. | |
| 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. | |
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 QofCollection_s | QofCollection |
Functions | |
| gboolean | qof_get_alt_dirty_mode (void) |
| void | qof_set_alt_dirty_mode (gboolean enabled) |
| #define QOF_CHECK_CAST | ( | obj, | |||
| e_type, | |||||
| c_type | ) |
Value:
( \ 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); \ }))
| #define QOF_CHECK_TYPE | ( | obj, | |||
| type | ) |
Value:
(((obj) != NULL) && \ (0 == QSTRCMP((type),(((QofInstance *)(obj))->e_type))))
| #define QSTRCMP | ( | da, | |||
| db | ) |
Value:
({ \
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 */ \
})
| 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.
Definition at line 162 of file qofid.c.
00163 { 00164 QofInstance *e; 00165 const GUID *guid; 00166 00167 e = NULL; 00168 if (!coll || !ent) { return FALSE; } 00169 guid = qof_instance_get_guid(ent); 00170 if (guid_equal(guid, guid_null())) { return FALSE; } 00171 g_return_val_if_fail (coll->e_type == ent->e_type, FALSE); 00172 e = qof_collection_lookup_entity(coll, guid); 00173 if ( e != NULL ) { return FALSE; } 00174 g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent); 00175 if (!qof_alt_dirty_mode) 00176 qof_collection_mark_dirty(coll); 00177 return TRUE; 00178 }
| 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 GUID.
Definition at line 231 of file qofid.c.
00232 { 00233 gint value; 00234 00235 value = 0; 00236 if (!target && !merge) { return 0; } 00237 if (target == merge) { return 0; } 00238 if (!target && merge) { return -1; } 00239 if (target && !merge) { return 1; } 00240 if(target->e_type != merge->e_type) { return -1; } 00241 qof_collection_set_data(target, &value); 00242 qof_collection_foreach(merge, collection_compare_cb, target); 00243 value = *(gint*)qof_collection_get_data(target); 00244 if(value == 0) { 00245 qof_collection_set_data(merge, &value); 00246 qof_collection_foreach(target, collection_compare_cb, merge); 00247 value = *(gint*)qof_collection_get_data(merge); 00248 } 00249 return value; 00250 }
| guint qof_collection_count | ( | const QofCollection * | col | ) |
return the number of entities in the collection.
Definition at line 282 of file qofid.c.
00283 { 00284 guint c; 00285 00286 c = g_hash_table_size(col->hash_of_entities); 00287 return c; 00288 }
| void qof_collection_destroy | ( | QofCollection * | col | ) |
destroy the collection
XXX there should be a destroy notifier for this
Definition at line 108 of file qofid.c.
00109 { 00110 CACHE_REMOVE (col->e_type); 00111 g_hash_table_destroy(col->hash_of_entities); 00112 col->e_type = NULL; 00113 col->hash_of_entities = NULL; 00114 col->data = NULL; 00115 g_free (col); 00116 }
| void qof_collection_foreach | ( | const QofCollection * | , | |
| QofInstanceForeachCB | , | |||
| gpointer | user_data | |||
| ) |
Call the callback for each entity in the collection.
Definition at line 348 of file qofid.c.
00350 { 00351 struct _iterate iter; 00352 00353 g_return_if_fail (col); 00354 g_return_if_fail (cb_func); 00355 00356 iter.fcn = cb_func; 00357 iter.data = user_data; 00358 00359 g_hash_table_foreach (col->hash_of_entities, foreach_cb, &iter); 00360 }
| 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 263 of file qofid.c.
00264 { 00265 QofCollection *coll; 00266 QofInstance *ent; 00267 const GList *list; 00268 00269 coll = qof_collection_new(type); 00270 for(list = glist; list != NULL; list = list->next) 00271 { 00272 ent = QOF_INSTANCE(list->data); 00273 if(FALSE == qof_collection_add_entity(coll, ent)) 00274 { 00275 return NULL; 00276 } 00277 } 00278 return coll; 00279 }
| gpointer qof_collection_get_data | ( | const QofCollection * | col | ) |
Store and retreive arbitrary object-defined data
XXX We need to add a callback for when the collection is being destroyed, so that the user has a chance to clean up anything that was put in the 'data' member here.
Definition at line 321 of file qofid.c.
00322 { 00323 return col ? col->data : NULL; 00324 }
| QofIdType qof_collection_get_type | ( | const QofCollection * | ) |
| gboolean qof_collection_is_dirty | ( | const QofCollection * | col | ) |
| QofInstance* qof_collection_lookup_entity | ( | const QofCollection * | , | |
| const GUID * | ||||
| ) |
Find the entity going only from its guid
Definition at line 253 of file qofid.c.
00254 { 00255 QofInstance *ent; 00256 g_return_val_if_fail (col, NULL); 00257 if (guid == NULL) return NULL; 00258 ent = g_hash_table_lookup (col->hash_of_entities, guid); 00259 return ent; 00260 }
| gboolean qof_collection_merge | ( | QofCollection * | target, | |
| QofCollection * | merge | |||
| ) |
Merge two QOF_TYPE_COLLECT of the same type.
Definition at line 190 of file qofid.c.
00191 { 00192 if(!target || !merge) { return FALSE; } 00193 g_return_val_if_fail (target->e_type == merge->e_type, FALSE); 00194 qof_collection_foreach(merge, collection_merge_cb, target); 00195 return TRUE; 00196 }
| QofCollection* qof_collection_new | ( | QofIdType | type | ) |
create a new collection of entities of type
Definition at line 97 of file qofid.c.
00098 { 00099 QofCollection *col; 00100 col = g_new0(QofCollection, 1); 00101 col->e_type = CACHE_INSERT (type); 00102 col->hash_of_entities = g_hash_table_new (id_hash, id_compare); 00103 col->data = NULL; 00104 return col; 00105 }
| gboolean qof_get_alt_dirty_mode | ( | void | ) |
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.
| 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.
1.5.2