QOF Objects are also used by the query system ....
To work with your own QOF Objects, you can use the QOF Generator to create sample objects and a mini-application with the SQL-type query interface. http://qof-gen.sourceforge.net/
XXX todo, we should split out the storage aspects of this thing from the 'foreach' that query depends on. These are kinda unrelated concepts.
Files | |
| file | qofobject.h |
| the Core Object Registration/Lookup Interface | |
Data Structures | |
| struct | _QofObject |
Initialize the object registration subsystem | |
| void | qof_object_initialize (void) |
| void | qof_object_shutdown (void) |
Defines | |
| #define | QOF_OBJECT_VERSION 3 |
| #define | QOF_MOD_OBJECT "qof-object" |
Typedefs | |
| typedef _QofObject | QofObject |
| typedef void(* | QofForeachCB )(gpointer obj, gpointer user_data) |
| typedef void(* | QofForeachTypeCB )(QofObject *type, gpointer user_data) |
| typedef void(* | QofForeachBackendTypeCB )(QofIdTypeConst type, gpointer backend_data, gpointer user_data) |
Functions | |
| gboolean | qof_object_register (const QofObject *object) |
| const QofObject * | qof_object_lookup (QofIdTypeConst type_name) |
| gpointer | qof_object_new_instance (QofIdTypeConst type_name, QofBook *book) |
| const char * | qof_object_get_type_label (QofIdTypeConst type_name) |
| const char * | qof_object_printable (QofIdTypeConst type_name, gpointer instance) |
| void | qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data) |
| void | qof_object_foreach (QofIdTypeConst type_name, QofBook *book, QofEntityForeachCB cb, gpointer user_data) |
| gboolean | qof_object_register_backend (QofIdTypeConst type_name, const char *backend_name, gpointer be_data) |
| gpointer | qof_object_lookup_backend (QofIdTypeConst type_name, const char *backend_name) |
| void | qof_object_foreach_backend (const char *backend_name, QofForeachBackendTypeCB cb, gpointer user_data) |
|
|
Defines the version of the core object object registration interface. Only object modules compiled against this version of the interface will load properly Definition at line 59 of file qofobject.h. |
|
||||||||||||||||||||
|
Invoke the callback 'cb' on every instance ov a particular object type. It is presumed that the 'book' stores or somehow identifies a colllection of instances; thus the callback will be invoked only for those instances stored in the book. Definition at line 144 of file qofobject.c. 00146 { 00147 QofCollection *col; 00148 const QofObject *obj; 00149 00150 if (!book || !type_name) return; 00151 ENTER ("type=%s", type_name); 00152 00153 obj = qof_object_lookup (type_name); 00154 if (!obj) 00155 { 00156 PERR ("No object of type %s", type_name); 00157 return; 00158 } 00159 col = qof_book_get_collection (book, obj->e_type); 00160 PINFO ("lookup obj=%p for type=%s", obj, type_name); 00161 if (!obj) return; 00162 00163 PINFO ("type=%s foreach=%p", type_name, obj->foreach); 00164 if (obj->foreach) 00165 { 00166 obj->foreach (col, cb, user_data); 00167 } 00168 LEAVE ("type=%s", type_name); 00169 00170 return; 00171 }
|
|
||||||||||||
|
Invoke the callback 'cb' on every object class definition. The user_data pointer is passed back to the callback. Definition at line 131 of file qofobject.c. 00132 { 00133 GList *l; 00134 00135 if (!cb) return; 00136 00137 for (l = object_modules; l; l = l->next) { 00138 QofObject *obj = l->data; 00139 (cb) (obj, user_data); 00140 } 00141 }
|
|
|
Get the printable label for a type. This label is *not* translated; you must use _() on it if you want a translated version. Definition at line 189 of file qofobject.c. 00190 { 00191 const QofObject *obj; 00192 00193 if (!type_name) return NULL; 00194 00195 obj = qof_object_lookup (type_name); 00196 if (!obj) return NULL; 00197 00198 return (obj->type_label); 00199 }
|
|
|
Lookup an object definition Definition at line 258 of file qofobject.c. 00259 { 00260 GList *iter; 00261 const QofObject *obj; 00262 00263 g_return_val_if_fail (object_is_initialized, NULL); 00264 00265 if (!name) return NULL; 00266 00267 for (iter = object_modules; iter; iter = iter->next) { 00268 obj = iter->data; 00269 if (!safe_strcmp (obj->e_type, name)) 00270 return obj; 00271 } 00272 return NULL; 00273 }
|
|
||||||||||||
|
Create an instance of the indicated type, returning a pointer to that instance. This routine just calls the (*new) callback on the object definition. Definition at line 45 of file qofobject.c. 00046 { 00047 const QofObject *obj; 00048 00049 if (!type_name) return NULL; 00050 00051 obj = qof_object_lookup (type_name); 00052 if (!obj) return NULL; 00053 00054 if (obj->create) 00055 return (obj->create (book)); 00056 00057 return NULL; 00058 }
|
|
||||||||||||
|
Definition at line 174 of file qofobject.c. 00175 { 00176 const QofObject *b_obj; 00177 00178 if (!type_name || !obj) return NULL; 00179 00180 b_obj = qof_object_lookup (type_name); 00181 if (!b_obj) return NULL; 00182 00183 if (b_obj->printable) 00184 return (b_obj->printable (obj)); 00185 00186 return NULL; 00187 }
|
|
|
Register new types of object objects Definition at line 236 of file qofobject.c. 00237 { 00238 g_return_val_if_fail (object_is_initialized, FALSE); 00239 00240 if (!object) return FALSE; 00241 g_return_val_if_fail (object->interface_version == QOF_OBJECT_VERSION, FALSE); 00242 00243 if (g_list_index (object_modules, (gpointer)object) == -1) 00244 object_modules = g_list_prepend (object_modules, (gpointer)object); 00245 else 00246 return FALSE; 00247 00248 /* Now initialize all the known books */ 00249 if (object->book_begin && book_list) { 00250 GList *node; 00251 for (node = book_list; node; node = node->next) 00252 object->book_begin (node->data); 00253 } 00254 00255 return TRUE; 00256 }
|
|
||||||||||||||||
|
Register and lookup backend-specific data for this particular object Definition at line 275 of file qofobject.c. 00278 { 00279 GHashTable *ht; 00280 g_return_val_if_fail (object_is_initialized, FALSE); 00281 00282 if (!type_name || *type_name == '\0' || 00283 !backend_name || *backend_name == '\0' || 00284 !be_data) 00285 return FALSE; 00286 00287 ht = g_hash_table_lookup (backend_data, backend_name); 00288 00289 /* If it doesn't already exist, create a new table for this backend */ 00290 if (!ht) { 00291 ht = g_hash_table_new (g_str_hash, g_str_equal); 00292 g_hash_table_insert (backend_data, (char *)backend_name, ht); 00293 } 00294 00295 /* Now insert the data */ 00296 g_hash_table_insert (ht, (char *)type_name, be_data); 00297 00298 return TRUE; 00299 }
|
1.4.5