Data Structures | |
struct | QofEntity_s |
Files | |
file | qofid.h |
QOF entity type identification system. | |
Defines | |
#define | QOF_ID_NONE NULL |
#define | QOF_ID_NULL "null" |
#define | QOF_ID_BOOK "Book" |
#define | QOF_ID_SESSION "Session" |
#define | QOF_ENTITY(object) ((QofEntity *)(object)) |
#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 struct QofEntity_s | QofEntity |
typedef struct QofCollection_s | QofCollection |
Functions | |
const GUID * | qof_entity_get_guid (QofEntity *) |
Collections of Entities | |
typedef void(* | QofEntityForeachCB )(QofEntity *, gpointer user_data) |
QofCollection * | qof_collection_new (QofIdType type) |
guint | qof_collection_count (QofCollection *col) |
void | qof_collection_destroy (QofCollection *col) |
QofIdType | qof_collection_get_type (QofCollection *) |
QofEntity * | qof_collection_lookup_entity (QofCollection *, const GUID *) |
void | qof_collection_foreach (QofCollection *, QofEntityForeachCB, gpointer user_data) |
gpointer | qof_collection_get_data (QofCollection *col) |
void | qof_collection_set_data (QofCollection *col, gpointer user_data) |
gboolean | qof_collection_is_dirty (QofCollection *col) |
QOF Entity Initialization & Shutdown | |
void | qof_entity_init (QofEntity *, QofIdType, QofCollection *) |
void | qof_entity_release (QofEntity *) |
QOF_TYPE_COLLECT: Linking one entity to many of one type | |
| |
gboolean | qof_collection_add_entity (QofCollection *coll, QofEntity *ent) |
Add an entity to a QOF_TYPE_COLLECT. | |
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, GList *glist) |
Create a secondary collection from a GList. |
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.
#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 QofEntity at %s:%d", __FILE__, __LINE__); \ (obj); \ }))
#define QOF_CHECK_TYPE | ( | obj, | |||
type | ) |
#define QOF_ENTITY | ( | object | ) | ((QofEntity *)(object)) |
#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 statment */ \ })
typedef struct QofCollection_s QofCollection |
typedef struct QofEntity_s QofEntity |
typedef void(* QofEntityForeachCB)(QofEntity *, gpointer user_data) |
typedef const gchar* QofIdTypeConst |
typedef const gchar* QofLogModule |
gboolean qof_collection_add_entity | ( | QofCollection * | coll, | |
QofEntity * | ent | |||
) |
Add an entity to a QOF_TYPE_COLLECT.
Definition at line 182 of file qofid.c.
00183 { 00184 QofEntity *e; 00185 00186 e = NULL; 00187 if (!coll || !ent) 00188 { 00189 return FALSE; 00190 } 00191 if (guid_equal (&ent->guid, guid_null ())) 00192 { 00193 return FALSE; 00194 } 00195 g_return_val_if_fail (coll->e_type == ent->e_type, FALSE); 00196 e = qof_collection_lookup_entity (coll, &ent->guid); 00197 if (e != NULL) 00198 { 00199 return FALSE; 00200 } 00201 g_hash_table_insert (coll->hash_of_entities, &ent->guid, ent); 00202 qof_collection_mark_dirty (coll); 00203 return TRUE; 00204 }
gint qof_collection_compare | ( | QofCollection * | target, | |
QofCollection * | merge | |||
) |
Compare two secondary collections.
Performs a deep comparision of the collections. Each QofEntity in each collection is looked up in the other collection, via the GUID.
Definition at line 264 of file qofid.c.
00265 { 00266 gint value; 00267 00268 value = 0; 00269 if (!target && !merge) 00270 return 0; 00271 if (target == merge) 00272 return 0; 00273 if (!target && merge) 00274 return -1; 00275 if (target && !merge) 00276 return 1; 00277 if (target->e_type != merge->e_type) 00278 return -1; 00279 qof_collection_set_data (target, &value); 00280 qof_collection_foreach (merge, collection_compare_cb, target); 00281 value = *(gint *) qof_collection_get_data (target); 00282 if (value == 0) 00283 { 00284 qof_collection_set_data (merge, &value); 00285 qof_collection_foreach (target, collection_compare_cb, merge); 00286 value = *(gint *) qof_collection_get_data (merge); 00287 } 00288 return value; 00289 }
guint qof_collection_count | ( | QofCollection * | col | ) |
void qof_collection_destroy | ( | QofCollection * | col | ) |
destroy the collection
XXX there should be a destroy notifier for this
Definition at line 132 of file qofid.c.
00133 { 00134 CACHE_REMOVE (col->e_type); 00135 g_hash_table_destroy (col->hash_of_entities); 00136 col->e_type = NULL; 00137 col->hash_of_entities = NULL; 00138 col->data = NULL; 00139 g_free (col); 00140 }
void qof_collection_foreach | ( | QofCollection * | , | |
QofEntityForeachCB | , | |||
gpointer | user_data | |||
) |
Call the callback for each entity in the collection.
Definition at line 392 of file qofid.c.
00394 { 00395 struct _iterate qiter; 00396 00397 g_return_if_fail (col); 00398 g_return_if_fail (cb_func); 00399 00400 qiter.fcn = cb_func; 00401 qiter.data = user_data; 00402 00403 g_hash_table_foreach (col->hash_of_entities, foreach_cb, &qiter); 00404 }
QofCollection* qof_collection_from_glist | ( | QofIdType | type, | |
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 303 of file qofid.c.
00304 { 00305 QofCollection *coll; 00306 QofEntity *ent; 00307 GList *list; 00308 00309 coll = qof_collection_new (type); 00310 for (list = glist; list != NULL; list = list->next) 00311 { 00312 ent = (QofEntity *) list->data; 00313 if (FALSE == qof_collection_add_entity (coll, ent)) 00314 { 00315 return NULL; 00316 } 00317 } 00318 return coll; 00319 }
gpointer qof_collection_get_data | ( | QofCollection * | col | ) |
QofIdType qof_collection_get_type | ( | QofCollection * | ) |
gboolean qof_collection_is_dirty | ( | QofCollection * | col | ) |
QofEntity* qof_collection_lookup_entity | ( | QofCollection * | , | |
const GUID * | ||||
) |
gboolean qof_collection_merge | ( | QofCollection * | target, | |
QofCollection * | merge | |||
) |
Merge two QOF_TYPE_COLLECT of the same type.
Definition at line 216 of file qofid.c.
00217 { 00218 if (!target || !merge) 00219 { 00220 return FALSE; 00221 } 00222 g_return_val_if_fail (target->e_type == merge->e_type, FALSE); 00223 qof_collection_foreach (merge, collection_merge_cb, target); 00224 return TRUE; 00225 }
QofCollection* qof_collection_new | ( | QofIdType | type | ) |
create a new collection of entities of type
Definition at line 121 of file qofid.c.
00122 { 00123 QofCollection *col; 00124 col = g_new0 (QofCollection, 1); 00125 col->e_type = CACHE_INSERT (type); 00126 col->hash_of_entities = g_hash_table_new (guid_hash_to_guint, id_compare); 00127 col->data = NULL; 00128 return col; 00129 }
void qof_collection_set_data | ( | QofCollection * | col, | |
gpointer | user_data | |||
) |
const GUID* qof_entity_get_guid | ( | QofEntity * | ) |
void qof_entity_init | ( | QofEntity * | , | |
QofIdType | , | |||
QofCollection * | ||||
) |
Initialise the memory associated with an entity
Definition at line 49 of file qofid.c.
00050 { 00051 g_return_if_fail (NULL != tab); 00052 00053 /* XXX We passed redundant info to this routine ... but I think that's 00054 * OK, it might eliminate programming errors. */ 00055 if (safe_strcmp (tab->e_type, type)) 00056 { 00057 PERR ("attempt to insert \"%s\" into \"%s\"", type, tab->e_type); 00058 return; 00059 } 00060 ent->e_type = CACHE_INSERT (type); 00061 00062 do 00063 { 00064 guid_new (&ent->guid); 00065 00066 if (NULL == qof_collection_lookup_entity (tab, &ent->guid)) 00067 break; 00068 00069 PWARN ("duplicate id created, trying again"); 00070 } 00071 while (1); 00072 00073 ent->collection = tab; 00074 00075 qof_collection_insert_entity (tab, ent); 00076 }
void qof_entity_release | ( | QofEntity * | ) |
Release the data associated with this entity. Dont actually free the memory associated with the instance.
Definition at line 79 of file qofid.c.
00080 { 00081 if (!ent->collection) 00082 return; 00083 qof_collection_remove_entity (ent); 00084 CACHE_REMOVE (ent->e_type); 00085 ent->e_type = NULL; 00086 }