GnuCash  4.8a-132-gcdaeb421d+
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. More...
 
#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. More...
 
const char * qof_object_get_type_label (QofIdTypeConst type_name)
 Get the printable label for a type. More...
 
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. More...
 
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. More...
 
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_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 64 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 197 of file qofobject.cpp.

199 {
200  QofCollection *col;
201  const QofObject *obj;
202 
203  if (!book || !type_name)
204  {
205  return;
206  }
207  PINFO ("type=%s", type_name);
208 
209  obj = qof_object_lookup (type_name);
210  if (!obj)
211  {
212  PERR ("No object of type %s", type_name);
213  return;
214  }
215  col = qof_book_get_collection (book, obj->e_type);
216  if (!obj)
217  {
218  return;
219  }
220  if (obj->foreach)
221  {
222  obj->foreach (col, cb, user_data);
223  }
224  return;
225 }
#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.
Definition: qofobject.cpp:340
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:604

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

166 {
167  GList *l;
168 
169  if (!cb) return;
170 
171  for (l = object_modules; l; l = l->next)
172  {
173  QofObject *obj = static_cast<QofObject*>(l->data);
174  (cb) (obj, user_data);
175  }
176 }

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

276 {
277  const QofObject *obj;
278 
279  if (!type_name) return NULL;
280 
281  obj = qof_object_lookup (type_name);
282  if (!obj) return NULL;
283 
284  return (obj->type_label);
285 }
const QofObject * qof_object_lookup(QofIdTypeConst name)
Lookup an object definition.
Definition: qofobject.cpp:340

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

78 {
79  const QofObject *obj;
80 
81  if (!type_name) return NULL;
82 
83  obj = qof_object_lookup (type_name);
84  if (!obj) return NULL;
85 
86  if (obj->create)
87  return (obj->create (book));
88 
89  return NULL;
90 }
const QofObject * qof_object_lookup(QofIdTypeConst name)
Lookup an object definition.
Definition: qofobject.cpp:340

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

261 {
262  const QofObject *b_obj;
263 
264  if (!type_name || !obj) return NULL;
265 
266  b_obj = qof_object_lookup (type_name);
267  if (!b_obj) return NULL;
268 
269  if (b_obj->printable)
270  return (b_obj->printable (obj));
271 
272  return NULL;
273 }
const QofObject * qof_object_lookup(QofIdTypeConst name)
Lookup an object definition.
Definition: qofobject.cpp:340