Objects
[Object: Dynamic Object Class Framework]


Detailed Description

QOF Objects provide the means for associating a storage backend to a set of QOF Entities. While an entity can be though of as an identified instance of some thing, the QOF Object provides for a way to associate instances with a storage backend. Storage might be file or SQL storage.

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 QofObjectqof_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, QofInstanceForeachCB 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)


Define Documentation

#define QOF_OBJECT_VERSION   3

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.


Function Documentation

void qof_object_foreach ( QofIdTypeConst  type_name,
QofBook book,
QofInstanceForeachCB  cb,
gpointer  user_data 
)

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 158 of file qofobject.c.

00160 {
00161   QofCollection *col;
00162   const QofObject *obj;
00163 
00164   if (!book || !type_name) { return; }
00165   PINFO ("type=%s", type_name);
00166 
00167   obj = qof_object_lookup (type_name);
00168   if (!obj)
00169   {
00170     PERR ("No object of type %s", type_name);
00171     return;
00172   }
00173   col = qof_book_get_collection (book, obj->e_type);
00174   if (!obj) { return; }
00175   if (obj->foreach) 
00176   {
00177     obj->foreach (col, cb, user_data);
00178   }
00179   return;
00180 }

void qof_object_foreach_type ( QofForeachTypeCB  cb,
gpointer  user_data 
)

Invoke the callback 'cb' on every object class definition. The user_data pointer is passed back to the callback.

Definition at line 128 of file qofobject.c.

00129 {
00130   GList *l;
00131 
00132   if (!cb) return;
00133 
00134   for (l = object_modules; l; l = l->next) {
00135     QofObject *obj = l->data;
00136     (cb) (obj, user_data);
00137   }
00138 }

const char* qof_object_get_type_label ( QofIdTypeConst  type_name  ) 

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 198 of file qofobject.c.

00199 {
00200   const QofObject *obj;
00201 
00202   if (!type_name) return NULL;
00203 
00204   obj = qof_object_lookup (type_name);
00205   if (!obj) return NULL;
00206 
00207   return (obj->type_label);
00208 }

void qof_object_initialize ( void   ) 

Definition at line 218 of file qofobject.c.

00219 {
00220   if (object_is_initialized) return;
00221   backend_data = g_hash_table_new (g_str_hash, g_str_equal);
00222   object_is_initialized = TRUE;
00223 }

const QofObject* qof_object_lookup ( QofIdTypeConst  type_name  ) 

Lookup an object definition

Definition at line 267 of file qofobject.c.

00268 {
00269   GList *iter;
00270   const QofObject *obj;
00271 
00272   g_return_val_if_fail (object_is_initialized, NULL);
00273 
00274   if (!name) return NULL;
00275 
00276   for (iter = object_modules; iter; iter = iter->next) {
00277     obj = iter->data;
00278     if (!safe_strcmp (obj->e_type, name))
00279       return obj;
00280   }
00281   return NULL;
00282 }

gpointer qof_object_new_instance ( QofIdTypeConst  type_name,
QofBook book 
)

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 42 of file qofobject.c.

00043 {
00044   const QofObject *obj;
00045 
00046   if (!type_name) return NULL;
00047 
00048   obj = qof_object_lookup (type_name);
00049   if (!obj) return NULL;
00050 
00051   if (obj->create) 
00052     return (obj->create (book));
00053 
00054   return NULL;
00055 }

const char* qof_object_printable ( QofIdTypeConst  type_name,
gpointer  instance 
)

Returns:
a Human-readable string name for an instance

Definition at line 183 of file qofobject.c.

00184 {
00185   const QofObject *b_obj;
00186 
00187   if (!type_name || !obj) return NULL;
00188 
00189   b_obj = qof_object_lookup (type_name);
00190   if (!b_obj) return NULL;
00191 
00192   if (b_obj->printable)
00193     return (b_obj->printable (obj));
00194 
00195   return NULL;
00196 }

gboolean qof_object_register ( const QofObject object  ) 

Register new types of object objects

Definition at line 245 of file qofobject.c.

00246 {
00247   g_return_val_if_fail (object_is_initialized, FALSE);
00248 
00249   if (!object) return FALSE;
00250   g_return_val_if_fail (object->interface_version == QOF_OBJECT_VERSION, FALSE);
00251 
00252   if (g_list_index (object_modules, (gpointer)object) == -1)
00253     object_modules = g_list_prepend (object_modules, (gpointer)object);
00254   else
00255     return FALSE;
00256 
00257   /* Now initialize all the known books */
00258   if (object->book_begin && book_list) {
00259     GList *node;
00260     for (node = book_list; node; node = node->next)
00261       object->book_begin (node->data);
00262   }
00263 
00264   return TRUE;
00265 }

gboolean qof_object_register_backend ( QofIdTypeConst  type_name,
const char *  backend_name,
gpointer  be_data 
)

Register and lookup backend-specific data for this particular object

Definition at line 284 of file qofobject.c.

00287 {
00288   GHashTable *ht;
00289   g_return_val_if_fail (object_is_initialized, FALSE);
00290 
00291   if (!type_name || *type_name == '\0' ||
00292       !backend_name || *backend_name == '\0' ||
00293       !be_data)
00294     return FALSE;
00295 
00296   ht = g_hash_table_lookup (backend_data, backend_name);
00297 
00298   /* If it doesn't already exist, create a new table for this backend */
00299   if (!ht) {
00300     ht = g_hash_table_new (g_str_hash, g_str_equal);
00301     g_hash_table_insert (backend_data, (char *)backend_name, ht);
00302   }
00303 
00304   /* Now insert the data */
00305   g_hash_table_insert (ht, (char *)type_name, be_data);
00306 
00307   return TRUE;
00308 }


Generated on Tue Oct 14 05:05:22 2008 for GnuCash by  doxygen 1.5.2