2005-11-07 09:45:58 -06:00
|
|
|
/********************************************************************\
|
|
|
|
* qofobject.h -- the Core Object Registration/Lookup Interface *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2005-11-07 09:45:58 -06:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
/** @addtogroup Object
|
|
|
|
@{ */
|
|
|
|
/** @addtogroup Objects
|
|
|
|
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.
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
QOF Objects are also used by the query system ....
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
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/
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
XXX todo, we should split out the storage aspects of this
|
2005-11-07 09:45:58 -06:00
|
|
|
thing from the 'foreach' that query depends on. These are
|
|
|
|
kinda unrelated concepts.
|
|
|
|
|
|
|
|
@{ */
|
|
|
|
/** @file qofobject.h
|
|
|
|
* @brief the Core Object Registration/Lookup Interface
|
|
|
|
* @author Copyright (c) 2001,2002 Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QOF_OBJECT_H_
|
|
|
|
#define QOF_OBJECT_H_
|
|
|
|
|
|
|
|
#include "qofbook.h"
|
|
|
|
#include "qofid.h"
|
|
|
|
|
2014-04-25 15:41:11 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/** Defines the version of the core object object registration
|
|
|
|
* interface. Only object modules compiled against this version
|
|
|
|
* of the interface will load properly
|
|
|
|
*/
|
|
|
|
#define QOF_OBJECT_VERSION 3
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
#define QOF_MOD_OBJECT "qof.object"
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
typedef struct _QofObject QofObject;
|
|
|
|
typedef void (*QofForeachCB) (gpointer obj, gpointer user_data);
|
|
|
|
typedef void (*QofForeachTypeCB) (QofObject *type, gpointer user_data);
|
|
|
|
typedef void (*QofForeachBackendTypeCB) (QofIdTypeConst type,
|
2009-09-18 14:40:57 -05:00
|
|
|
gpointer backend_data,
|
|
|
|
gpointer user_data);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
/** This is the QofObject Class descriptor
|
2005-11-07 09:45:58 -06:00
|
|
|
*/
|
2009-09-18 14:40:57 -05:00
|
|
|
struct _QofObject
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
gint interface_version; /* of this object interface */
|
|
|
|
QofIdType e_type; /* the Object's QOF_ID */
|
|
|
|
const char * type_label; /* "Printable" type-label string */
|
|
|
|
|
|
|
|
/** Create a new instance of this object type. This routine might be
|
|
|
|
* NULL if the object type doesn't provide a way of creating new
|
|
|
|
* instances.
|
|
|
|
*/
|
|
|
|
gpointer (*create)(QofBook *);
|
|
|
|
|
|
|
|
/** book_begin is called from within the Book routines to create
|
|
|
|
* module-specific hooks in a book whenever a book is created.
|
|
|
|
*/
|
|
|
|
void (*book_begin)(QofBook *);
|
|
|
|
|
|
|
|
/** book_end is called when the book is being closed, to clean
|
|
|
|
* up (and free memory).
|
|
|
|
*/
|
|
|
|
void (*book_end)(QofBook *);
|
|
|
|
|
|
|
|
/** Determine if there are any dirty items in this book */
|
|
|
|
gboolean (*is_dirty)(const QofCollection *);
|
|
|
|
|
|
|
|
/** Mark this object's book clean (for after a load) */
|
|
|
|
void (*mark_clean)(QofCollection *);
|
|
|
|
|
|
|
|
/** Traverse over all of the items in the collection, calling
|
|
|
|
* the callback on each item. The third argument can be any
|
|
|
|
* arbitrary caller-supplied data, and is passed to the callback.
|
2021-02-05 13:52:33 -06:00
|
|
|
* Although (*foreach) may be NULL, almost all objects should
|
2009-09-18 14:40:57 -05:00
|
|
|
* provide this routine, as without it, little of interest can
|
|
|
|
* be done.
|
|
|
|
*/
|
|
|
|
void (*foreach)(const QofCollection *, QofInstanceForeachCB, gpointer);
|
|
|
|
|
|
|
|
/** Given a particular item of this type, return a printable string.
|
|
|
|
*/
|
|
|
|
const char * (*printable)(gpointer instance);
|
|
|
|
|
|
|
|
/** Given a pair of items of this type, this routine returns value
|
|
|
|
* indicating which item is 'newer'. This routine is used by storage
|
|
|
|
* backends to determine if the local or the remote copy of a
|
|
|
|
* particular item is the latest, 'uptodate' version. Tis routine
|
|
|
|
* should return an integer less than, equal to, or greater than zero
|
2021-02-05 13:52:33 -06:00
|
|
|
* if 'instance_left' is found to be, respectively, earlier than, equal
|
2009-09-18 14:40:57 -05:00
|
|
|
* to or later than than 'instance_right'.
|
|
|
|
*/
|
|
|
|
int (*version_cmp)(gpointer instance_left, gpointer instance_right);
|
2005-11-07 09:45:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** @name Initialize the object registration subsystem */
|
|
|
|
/** @{ */
|
|
|
|
void qof_object_initialize (void);
|
|
|
|
void qof_object_shutdown (void);
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/** Register new types of object objects */
|
|
|
|
gboolean qof_object_register (const QofObject *object);
|
|
|
|
|
|
|
|
/** Lookup an object definition */
|
|
|
|
const QofObject * qof_object_lookup (QofIdTypeConst type_name);
|
|
|
|
|
|
|
|
/** Create an instance of the indicated type, returning a pointer to that
|
|
|
|
* instance. This routine just calls the (*new) callback on the object
|
2009-09-18 14:40:57 -05:00
|
|
|
* definition.
|
2005-11-07 09:45:58 -06:00
|
|
|
*/
|
|
|
|
gpointer qof_object_new_instance (QofIdTypeConst type_name, QofBook *book);
|
|
|
|
|
|
|
|
/** Get the printable label for a type. This label is *not*
|
|
|
|
* translated; you must use _() on it if you want a translated version.
|
|
|
|
*/
|
|
|
|
const char * qof_object_get_type_label (QofIdTypeConst type_name);
|
|
|
|
|
|
|
|
/** @return a Human-readable string name for an instance */
|
|
|
|
const char * qof_object_printable (QofIdTypeConst type_name, gpointer instance);
|
|
|
|
|
|
|
|
/** Invoke the callback 'cb' on every object class definition.
|
|
|
|
* The user_data pointer is passed back to the callback.
|
|
|
|
*/
|
|
|
|
void qof_object_foreach_type (QofForeachTypeCB 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
|
2009-09-18 14:40:57 -05:00
|
|
|
* identifies a colllection of instances; thus the callback will
|
2005-11-07 09:45:58 -06:00
|
|
|
* be invoked only for those instances stored in the book.
|
|
|
|
*/
|
2009-09-18 14:40:57 -05:00
|
|
|
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
|
2007-04-01 17:18:50 -05:00
|
|
|
QofInstanceForeachCB cb, gpointer user_data);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
Bug #638225: Sort when saving as XML
Patch by Jim Radford (with code beautified and re-indented by myself):
The attached patches sort the slots, lots, book accounts, bill terms,
customers, employees, entries, invoices, jobs, orders, tax tables and
vendors before saving them to the GnuCash XML file.
This is an attempt to make saves more idempotent thereby facilitating
the use of a revision control system on the GnuCash XML files.
With these patches most of the needless and seemingly random churn is
gone and I can add or remove a transaction and expect
there to be no unrelated changes to the GnuCash file.
I've been using and refining this patches for the last few years, so it has
received quite a bit of testing.
David Fraser adds: Without specific testing, I'm using this on an average-sized gnucash file
(5.7MB) without noticing any particular slowdown in saving, but a wonderful
reduction in diffs when comparing changes.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20067 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-11 14:40:19 -06:00
|
|
|
/** Invoke callback 'cb' on each instance in guid orted order */
|
|
|
|
void qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book,
|
|
|
|
QofInstanceForeachCB cb, gpointer user_data);
|
|
|
|
|
2014-04-25 15:41:11 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
#endif /* QOF_OBJECT_H_ */
|
|
|
|
/** @} */
|
|
|
|
/** @} */
|