r15810 - gnucash/branches/gobject-engine-dev-warlord - Convert gnc_commodity objects to GObject initialization.

Derek Atkins warlord at cvs.gnucash.org
Wed Apr 4 20:24:19 EDT 2007


Author: warlord
Date: 2007-04-04 20:24:18 -0400 (Wed, 04 Apr 2007)
New Revision: 15810
Trac: http://svn.gnucash.org/trac/changeset/15810

Modified:
   gnucash/branches/gobject-engine-dev-warlord/
   gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.c
   gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.h
Log:
Convert gnc_commodity objects to GObject initialization.



Property changes on: gnucash/branches/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:14369
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/gobject-engine-dev-warlord1:14390
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/branches/gobject-engine-dev-warlord1:14391
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:14282
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk2:13366

Modified: gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.c
===================================================================
--- gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.c	2007-04-05 00:24:09 UTC (rev 15809)
+++ gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.c	2007-04-05 00:24:18 UTC (rev 15810)
@@ -63,6 +63,11 @@
   char    * quote_tz;
 };
 
+struct _GncCommodityClass
+{
+  QofInstanceClass parent_class;
+};
+
 struct gnc_commodity_namespace_s 
 {
   QofInstance inst;
@@ -73,6 +78,11 @@
   GList      * cm_list;
 };
 
+struct _GncCommodityNamespaceClass
+{
+  QofInstanceClass parent_class;
+};
+
 struct gnc_commodity_table_s 
 {
   GHashTable * ns_table;
@@ -523,15 +533,28 @@
                                        com->mnemonic ? com->mnemonic : "");
 }
 
+/* GObject Initialization */
+QOF_GOBJECT_IMPL(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE);
+
+static void
+gnc_commodity_init(gnc_commodity* com)
+{
+}
+
+static void
+gnc_commodity_finalize_real(GObject* comp)
+{
+}
+
 gnc_commodity *
 gnc_commodity_new(QofBook *book, const char * fullname, 
                   const char * namespace, const char * mnemonic, 
                   const char * cusip, int fraction)
 {
-  gnc_commodity * retval = g_new0(gnc_commodity, 1);
+  gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
   gnc_commodity_table *table;
 
-  qof_instance_init (&retval->inst, GNC_ID_COMMODITY, book);
+  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
   table = gnc_commodity_table_get_table(book);
   if (namespace) {
     retval->namespace = gnc_commodity_table_find_namespace(table, namespace);
@@ -596,8 +619,8 @@
 
   cm->mark = 0;
 
-  qof_instance_release (&cm->inst);
-  g_free(cm);
+  /* qof_instance_release (&cm->inst); */
+  g_object_unref(cm);
 }
 
 void
@@ -615,7 +638,8 @@
 gnc_commodity *
 gnc_commodity_clone(gnc_commodity *src)
 {
-  gnc_commodity * dest = g_new0(gnc_commodity, 1);
+  gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
+  /* qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, src->inst.book); */
 
   dest->fullname = CACHE_INSERT(src->fullname);
   dest->mnemonic = CACHE_INSERT(src->mnemonic);
@@ -1522,11 +1546,11 @@
   ns = gnc_commodity_table_find_namespace(table, namespace);
   if(!ns) 
   {
-    ns = g_new0(gnc_commodity_namespace, 1);
+    ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
     ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
     ns->name = CACHE_INSERT((gpointer)namespace);
     ns->iso4217 = gnc_commodity_namespace_is_iso(namespace);
-    qof_instance_init (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
+    qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
     qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);
     
     g_hash_table_insert(table->ns_table,
@@ -1609,8 +1633,8 @@
   CACHE_REMOVE(ns->name);
 
   qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
-  qof_instance_release(&ns->inst);
-  g_free(ns);
+  /* qof_instance_release(&ns->inst); */
+  g_object_unref(ns);
 }
 
 /********************************************************************

Modified: gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.h
===================================================================
--- gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.h	2007-04-05 00:24:09 UTC (rev 15809)
+++ gnucash/branches/gobject-engine-dev-warlord/src/engine/gnc-commodity.h	2007-04-05 00:24:18 UTC (rev 15810)
@@ -46,14 +46,41 @@
 #ifndef GNC_COMMODITY_H
 #define GNC_COMMODITY_H
 
+typedef struct _GncCommodityClass gnc_commodityClass;
+typedef struct _GncCommodityNamespaceClass gnc_commodity_namespaceClass;
+
 #include <glib.h>
 #include "gnc-engine.h"
 
-#define GNC_IS_COMMODITY(obj)  (QOF_CHECK_TYPE((obj), GNC_ID_COMMODITY))
-#define GNC_COMMODITY(obj)     (QOF_CHECK_CAST((obj), GNC_ID_COMMODITY, gnc_commodity))
-#define GNC_IS_COMMODITY_NAMESPACE(obj)  (QOF_CHECK_TYPE((obj), GNC_ID_COMMODITY_NAMESPACE))
-#define GNC_COMMODITY_NAMESPACE(obj)     (QOF_CHECK_CAST((obj), GNC_ID_COMMODITY_NAMESPACE, gnc_commodity_namespace))
+/* --- type macros --- */
+#define GNC_TYPE_COMMODITY            (gnc_commodity_get_type ())
+#define GNC_COMMODITY(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY, gnc_commodity))
+#define GNC_COMMODITY_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY, gnc_commodityClass))
+#define GNC_IS_COMMODITY(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY))
+#define GNC_IS_COMMODITY_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY))
+#define GNC_COMMODITY_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY, gnc_commodityClass))
+GType gnc_commodity_get_type(void);
 
+/* --- type macros --- */
+#define GNC_TYPE_COMMODITY_NAMESPACE            (gnc_commodity_namespace_get_type ())
+#define GNC_COMMODITY_NAMESPACE(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespace))
+#define GNC_COMMODITY_NAMESPACE_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
+#define GNC_IS_COMMODITY_NAMESPACE(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY_NAMESPACE))
+#define GNC_IS_COMMODITY_NAMESPACE_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY_NAMESPACE))
+#define GNC_COMMODITY_NAMESPACE_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
+GType gnc_commodity_namespace_get_type(void);
+
+
 #define GNC_COMMODITY_TABLE "gnc_commodity_table"
 
 /** The commodity namespace definitions are used to tag a commodity by



More information about the gnucash-changes mailing list