r15778 - gnucash/gobject-engine-dev-warlord - Hey, look! QofInstance has a GObject.

Derek Atkins warlord at cvs.gnucash.org
Mon Apr 2 22:14:14 EDT 2007


Author: warlord
Date: 2007-04-02 22:14:13 -0400 (Mon, 02 Apr 2007)
New Revision: 15778
Trac: http://svn.gnucash.org/trac/changeset/15778

Added:
   gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qof-gobject.h
Modified:
   gnucash/gobject-engine-dev-warlord/
   gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance-p.h
   gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance.h
Log:
Hey, look!  QofInstance has a GObject.
Granted, it's not used, yet.  But it's there.
Also add some helpful macros for instances.



Property changes on: gnucash/gobject-engine-dev-warlord
___________________________________________________________________
Name: svk:merge
   - 3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/branches/swig-redo:802
3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/trunk:1037
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/gobject-engine-dev-warlord:14365
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:14282
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk2:13366
   + 3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/branches/swig-redo:802
3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/trunk:1037
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/gobject-engine-dev-warlord:14369
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:14282
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk2:13366

Added: gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qof-gobject.h
===================================================================
--- gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qof-gobject.h	2007-04-03 00:55:56 UTC (rev 15777)
+++ gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qof-gobject.h	2007-04-03 02:14:13 UTC (rev 15778)
@@ -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 at 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 */


Property changes on: gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qof-gobject.h
___________________________________________________________________
Name: svn:keywords
   + "Author Date Id Revision"
Name: svn:eol-style
   + native

Modified: gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance-p.h
===================================================================
--- gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance-p.h	2007-04-03 00:55:56 UTC (rev 15777)
+++ gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance-p.h	2007-04-03 02:14:13 UTC (rev 15778)
@@ -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;

Modified: gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance.h	2007-04-03 00:55:56 UTC (rev 15777)
+++ gnucash/gobject-engine-dev-warlord/lib/libqof/qof/qofinstance.h	2007-04-03 02:14:13 UTC (rev 15778)
@@ -41,21 +41,70 @@
 #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 *);
+void qof_instance_release (QofInstance *);
+#else
+void qof_instance_init_data (QofInstance *, QofIdType, QofBook *);
+#endif
 
-/** release the data associated with this instance. Dont actually free 
- * the memory associated with the instance. */
-void qof_instance_release (QofInstance *inst);
-
 /** Return the book pointer */
 QofBook * qof_instance_get_book (const QofInstance *);
 



More information about the gnucash-changes mailing list