GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Functions

QOF Objects provide the means for associating a storage backend to a set of QOF Entities. More...

Files

file  qofobject.h
 the Core Object Registration/Lookup Interface
 

Data Structures

struct  QofObject
 This is the QofObject Class descriptor. More...
 

Macros

#define QOF_OBJECT_VERSION   3
 Defines the version of the core object object registration interface.
 
#define QOF_MOD_OBJECT   "qof.object"
 

Typedefs

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)
 Register new types of object objects.
 
const QofObject * qof_object_lookup (QofIdTypeConst type_name)
 Lookup an object definition.
 
gpointer qof_object_new_instance (QofIdTypeConst type_name, QofBook *book)
 Create an instance of the indicated type, returning a pointer to that instance.
 
const char * qof_object_get_type_label (QofIdTypeConst type_name)
 Get the printable label for a type.
 
const char * qof_object_printable (QofIdTypeConst type_name, gpointer instance)
 
void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data)
 Invoke the callback 'cb' on every object class definition.
 
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.
 
void qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
 Invoke callback 'cb' on each instance in guid orted order.
 

Initialize the object registration subsystem

void qof_object_initialize (void)
 
void qof_object_shutdown (void)
 

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.

Macro Definition Documentation

◆ QOF_MOD_OBJECT

#define QOF_MOD_OBJECT   "qof.object"

Definition at line 65 of file qofobject.h.

◆ QOF_OBJECT_VERSION

#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 63 of file qofobject.h.

Typedef Documentation

◆ QofForeachBackendTypeCB

typedef void(* QofForeachBackendTypeCB) (QofIdTypeConst type, gpointer backend_data, gpointer user_data)

Definition at line 70 of file qofobject.h.

◆ QofForeachCB

typedef void(* QofForeachCB) (gpointer obj, gpointer user_data)

Definition at line 68 of file qofobject.h.

◆ QofForeachTypeCB

typedef void(* QofForeachTypeCB) (QofObject *type, gpointer user_data)

Definition at line 69 of file qofobject.h.

Function Documentation

◆ qof_object_foreach()

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 185 of file qofobject.cpp.

187{
188 QofCollection *col;
189 const QofObject *obj;
190
191 if (!book || !type_name)
192 {
193 return;
194 }
195 PINFO ("type=%s", type_name);
196
197 obj = qof_object_lookup (type_name);
198 if (!obj)
199 {
200 PERR ("No object of type %s", type_name);
201 return;
202 }
203 col = qof_book_get_collection (book, obj->e_type);
204 if (!col)
205 {
206 return;
207 }
208 if (obj->foreach)
209 {
210 obj->foreach (col, cb, user_data);
211 }
212 return;
213}
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244
const QofObject * qof_object_lookup(QofIdTypeConst name)
Lookup an object definition.

◆ qof_object_foreach_sorted()

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

Invoke callback 'cb' on each instance in guid orted order.

Definition at line 223 of file qofobject.cpp.

224{
225 GList *list = nullptr;
226 GList *iter;
227
228 qof_object_foreach(type_name, book, do_prepend, &list);
229
230 list = g_list_sort(list, qof_instance_guid_compare);
231
232 for (iter = list; iter; iter = iter->next)
233 {
234 cb(static_cast<QofInstance*>(iter->data), user_data);
235 }
236
237 g_list_free(list);
238
239 // FIXME: Apparently this is a memory leak, as this g_list_free doesn't
240 // free all of the allocated memory of g_list_append in do_append(). Why?!?
241 // Does g_list_sort have special side-effects on the memory of the list?
242 // Subsequently, I've changed the g_list_append into g_list_prepend, but
243 // solely for performance reasons. To my surprise, this also makes the
244 // dubious memory leak go away. But again why?!?
245}
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
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.

◆ qof_object_foreach_type()

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 153 of file qofobject.cpp.

154{
155 GList *l;
156
157 if (!cb) return;
158
159 for (l = object_modules; l; l = l->next)
160 {
161 QofObject *obj = static_cast<QofObject*>(l->data);
162 (cb) (obj, user_data);
163 }
164}

◆ qof_object_get_type_label()

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 263 of file qofobject.cpp.

264{
265 const QofObject *obj;
266
267 if (!type_name) return nullptr;
268
269 obj = qof_object_lookup (type_name);
270 if (!obj) return nullptr;
271
272 return (obj->type_label);
273}

◆ qof_object_initialize()

void qof_object_initialize ( void  )

Definition at line 277 of file qofobject.cpp.

278{
279 if (object_is_initialized) return;
280 object_is_initialized = TRUE;
281}

◆ qof_object_lookup()

const QofObject * qof_object_lookup ( QofIdTypeConst  type_name)

Lookup an object definition.

Definition at line 322 of file qofobject.cpp.

323{
324 GList *iter;
325 const QofObject *obj;
326
327 g_return_val_if_fail (object_is_initialized, nullptr);
328
329 if (!name) return nullptr;
330
331 for (iter = object_modules; iter; iter = iter->next)
332 {
333 obj = static_cast<QofObject*>(iter->data);
334 if (!g_strcmp0 (obj->e_type, name))
335 return obj;
336 }
337 return nullptr;
338}

◆ qof_object_new_instance()

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 65 of file qofobject.cpp.

66{
67 const QofObject *obj;
68
69 if (!type_name) return nullptr;
70
71 obj = qof_object_lookup (type_name);
72 if (!obj) return nullptr;
73
74 if (obj->create)
75 return (obj->create (book));
76
77 return nullptr;
78}

◆ qof_object_printable()

const char * qof_object_printable ( QofIdTypeConst  type_name,
gpointer  instance 
)
Returns
a Human-readable string name for an instance

Definition at line 248 of file qofobject.cpp.

249{
250 const QofObject *b_obj;
251
252 if (!type_name || !obj) return nullptr;
253
254 b_obj = qof_object_lookup (type_name);
255 if (!b_obj) return nullptr;
256
257 if (b_obj->printable)
258 return (b_obj->printable (obj));
259
260 return nullptr;
261}

◆ qof_object_register()

gboolean qof_object_register ( const QofObject *  object)

Register new types of object objects.

Definition at line 299 of file qofobject.cpp.

300{
301 g_return_val_if_fail (object_is_initialized, FALSE);
302
303 if (!object) return FALSE;
304 g_return_val_if_fail (object->interface_version == QOF_OBJECT_VERSION, FALSE);
305
306 if (g_list_index (object_modules, (gpointer)object) == -1)
307 object_modules = g_list_prepend (object_modules, (gpointer)object);
308 else
309 return FALSE;
310
311 /* Now initialize all the known books */
312 if (object->book_begin && book_list)
313 {
314 GList *node;
315 for (node = book_list; node; node = node->next)
316 object->book_begin (static_cast<QofBook*>(node->data));
317 }
318
319 return TRUE;
320}
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
Definition qofobject.h:63
QofBook reference.
Definition qofbook-p.hpp:47

◆ qof_object_shutdown()

void qof_object_shutdown ( void  )

Definition at line 283 of file qofobject.cpp.

284{
285 g_return_if_fail (object_is_initialized == TRUE);
286
287 g_list_free (object_modules);
288 object_modules = nullptr;
289 g_list_free (book_list);
290 book_list = nullptr;
291 object_is_initialized = FALSE;
292}