mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Hey, look! QofInstance has a GObject.
Granted, it's not used, yet. But it's there. Also add some helpful macros for instances. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/gobject-engine-dev-warlord@15778 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
12461c5b30
commit
06ec94e59c
85
lib/libqof/qof/qof-gobject.h
Normal file
85
lib/libqof/qof/qof-gobject.h
Normal file
@ -0,0 +1,85 @@
|
||||
/********************************************************************\
|
||||
* qof-gobject.h -- helper macros for qof objects using gobject *
|
||||
* *
|
||||
* 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 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef QOF_GOBJECT_H
|
||||
#define QOF_GOBJECT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
/**
|
||||
* This is a simple macro for use in your QOF header files.
|
||||
* In addition to using this macro (which you don't need to use,
|
||||
* you can define the get_type() function directory if you wish)
|
||||
* you also need to define the gobject type cast macros. For example,
|
||||
* for the QofInstance type you would need to define the following
|
||||
* macros:
|
||||
*
|
||||
* #define #define QOF_INSTANCE(o) \
|
||||
* (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_INSTANCE, QofInstance))
|
||||
* #define QOF_INSTANCE_CLASS(k) \
|
||||
* (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_INSTANCE, QofInstanceClass))
|
||||
* #define QOF_IS_INSTANCE(o) \
|
||||
* (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_INSTANCE))
|
||||
* #define QOF_IS_INSTANCE_CLASS(k) \
|
||||
* (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_INSTANCE))
|
||||
* #define QOF_INSTANCE_GET_CLASS(o) \
|
||||
* (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_INSTANCE, QofInstanceClass))
|
||||
*
|
||||
* @param type_name The function type_name for this type
|
||||
*/
|
||||
#define QOF_GOBJECT_DECL(type_name) \
|
||||
GType type_name##_get_type();
|
||||
|
||||
/**
|
||||
* The following macros are for convenience in your QOF object
|
||||
* implementation files. Generally you only need to use
|
||||
* QOF_GOBJECT_IMPL() or QOF_GOBJECT_IMPL_WITH_CODE()
|
||||
*/
|
||||
|
||||
#define QOF_GOBJECT_GET_TYPE(TypeName, type_name, TYPE_PARENT, CODE) \
|
||||
static void type_name##_finalize(GObject *object); \
|
||||
G_DEFINE_TYPE_WITH_CODE(TypeName, type_name, TYPE_PARENT, CODE);
|
||||
|
||||
#define QOF_GOBJECT_CLASS_INIT(type_name, TypeName) \
|
||||
static void type_name##_class_init(TypeName##Class *klass) \
|
||||
{ \
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass); \
|
||||
object_class->finalize = type_name##_finalize; \
|
||||
}
|
||||
|
||||
#define QOF_GOBJECT_FINALIZE(type_name) \
|
||||
static void type_name##_finalize(GObject *object) \
|
||||
{ \
|
||||
type_name##_finalize_real(object); \
|
||||
G_OBJECT_CLASS(type_name##parent_class)->finalize(object); \
|
||||
}
|
||||
|
||||
#define QOF_GOBJECT_IMPL_WITH_CODE(type_name, TypeName, TYPE_PARENT, CODE) \
|
||||
QOF_GOBJECT_GET_TYPE(TypeName, type_name, TYPE_PARENT, CODE); \
|
||||
QOF_GOBJECT_CLASS_INIT(type_name, TypeName); \
|
||||
QOF_GOBJECT_FINALIZE(type_name);
|
||||
|
||||
#define QOF_GOBJECT_IMPL(type_name, TypeName, TYPE_PARENT) \
|
||||
QOF_GOBJECT_IMPL_WITH_CODE(type_name, TypeName, TYPE_PARENT, {})
|
||||
|
||||
|
||||
#endif /* QOF_GOBJECT_H */
|
@ -31,51 +31,6 @@
|
||||
|
||||
#include "qofinstance.h"
|
||||
|
||||
/*
|
||||
* UNDER CONSTRUCTION!
|
||||
* This is mostly scaffolding for now,
|
||||
* eventually, it may hold more fields, such as refrence counting...
|
||||
*
|
||||
*/
|
||||
struct QofInstance_s
|
||||
{
|
||||
/* Globally unique id identifying this instance */
|
||||
QofIdType e_type; /**< Entity type */
|
||||
GUID guid; /**< GUID for the entity */
|
||||
QofCollection * collection; /**< Entity collection */
|
||||
|
||||
/* The entity_table in which this instance is stored */
|
||||
QofBook * book;
|
||||
|
||||
/* kvp_data is a key-value pair database for storing arbirtary
|
||||
* information associated with this instance.
|
||||
* See src/engine/kvp_doc.txt for a list and description of the
|
||||
* important keys. */
|
||||
KvpFrame *kvp_data;
|
||||
|
||||
/* Timestamp used to track the last modification to this
|
||||
* instance. Typically used to compare two versions of the
|
||||
* same object, to see which is newer. When used with the
|
||||
* SQL backend, this field is reserved for SQL use, to compare
|
||||
* the version in local memory to the remote, server version.
|
||||
*/
|
||||
Timespec last_update;
|
||||
|
||||
/* Keep track of nesting level of begin/end edit calls */
|
||||
int editlevel;
|
||||
|
||||
/* In process of being destroyed */
|
||||
gboolean do_free;
|
||||
|
||||
/* dirty/clean flag. If dirty, then this instance has been modified,
|
||||
* but has not yet been written out to storage (file/database)
|
||||
*/
|
||||
gboolean dirty;
|
||||
|
||||
/* True iff this instance has never been committed. */
|
||||
gboolean infant;
|
||||
};
|
||||
|
||||
void qof_instance_set_slots (QofInstance *, KvpFrame *);
|
||||
|
||||
/* Set the last_update time. Reserved for use by the SQL backend;
|
||||
|
@ -41,20 +41,69 @@
|
||||
#include "kvp_frame.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qof-gobject.h"
|
||||
|
||||
/* --- type macros --- */
|
||||
/* cheesy, but will do for now, eventually should be more gtk-like, handle
|
||||
* thunks, etc. */
|
||||
#define QOF_INSTANCE(object) ((QofInstance *)(object))
|
||||
|
||||
/*typedef struct QofInstance_s QofInstance;*/
|
||||
struct QofInstance_s
|
||||
{
|
||||
GObject object;
|
||||
|
||||
/* Globally unique id identifying this instance */
|
||||
QofIdType e_type; /**< Entity type */
|
||||
GUID guid; /**< GUID for the entity */
|
||||
QofCollection * collection; /**< Entity collection */
|
||||
|
||||
/* The entity_table in which this instance is stored */
|
||||
QofBook * book;
|
||||
|
||||
/* kvp_data is a key-value pair database for storing arbirtary
|
||||
* information associated with this instance.
|
||||
* See src/engine/kvp_doc.txt for a list and description of the
|
||||
* important keys. */
|
||||
KvpFrame *kvp_data;
|
||||
|
||||
/* Timestamp used to track the last modification to this
|
||||
* instance. Typically used to compare two versions of the
|
||||
* same object, to see which is newer. When used with the
|
||||
* SQL backend, this field is reserved for SQL use, to compare
|
||||
* the version in local memory to the remote, server version.
|
||||
*/
|
||||
Timespec last_update;
|
||||
|
||||
/* Keep track of nesting level of begin/end edit calls */
|
||||
int editlevel;
|
||||
|
||||
/* In process of being destroyed */
|
||||
gboolean do_free;
|
||||
|
||||
/* dirty/clean flag. If dirty, then this instance has been modified,
|
||||
* but has not yet been written out to storage (file/database)
|
||||
*/
|
||||
gboolean dirty;
|
||||
|
||||
/* True iff this instance has never been committed. */
|
||||
gboolean infant;
|
||||
};
|
||||
|
||||
struct _QofInstanceClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
/** Return the GType of a QofInstance */
|
||||
GType qof_instance_get_type();
|
||||
|
||||
/** Initialise the memory associated with an instance */
|
||||
#if 1
|
||||
void qof_instance_init (QofInstance *, QofIdType, QofBook *);
|
||||
|
||||
/** release the data associated with this instance. Dont actually free
|
||||
* the memory associated with the instance. */
|
||||
void qof_instance_release (QofInstance *inst);
|
||||
void qof_instance_release (QofInstance *);
|
||||
#else
|
||||
void qof_instance_init_data (QofInstance *, QofIdType, QofBook *);
|
||||
#endif
|
||||
|
||||
/** Return the book pointer */
|
||||
QofBook * qof_instance_get_book (const QofInstance *);
|
||||
|
Loading…
Reference in New Issue
Block a user