r16039 - gnucash/trunk - Move QofInstance guid property from its public data structure to its

David Hampton hampton at cvs.gnucash.org
Wed May 2 01:42:43 EDT 2007


Author: hampton
Date: 2007-05-02 01:42:41 -0400 (Wed, 02 May 2007)
New Revision: 16039
Trac: http://svn.gnucash.org/trac/changeset/16039

Modified:
   gnucash/trunk/lib/libqof/backend/file/qsf-backend.c
   gnucash/trunk/lib/libqof/qof/deprecated.h
   gnucash/trunk/lib/libqof/qof/guid.c
   gnucash/trunk/lib/libqof/qof/guid.h
   gnucash/trunk/lib/libqof/qof/kvp-util-p.h
   gnucash/trunk/lib/libqof/qof/kvp-util.c
   gnucash/trunk/lib/libqof/qof/qofbookmerge.c
   gnucash/trunk/lib/libqof/qof/qofevent-p.h
   gnucash/trunk/lib/libqof/qof/qofevent.c
   gnucash/trunk/lib/libqof/qof/qofid-p.h
   gnucash/trunk/lib/libqof/qof/qofid.c
   gnucash/trunk/lib/libqof/qof/qofid.h
   gnucash/trunk/lib/libqof/qof/qofinstance.c
   gnucash/trunk/lib/libqof/qof/qofinstance.h
   gnucash/trunk/lib/libqof/qof/qofreference.c
   gnucash/trunk/lib/libqof/qof/qofsession.c
   gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c
   gnucash/trunk/src/backend/postgres/txn.c
   gnucash/trunk/src/business/business-core/gncEntry.c
   gnucash/trunk/src/business/business-core/gncInvoice.c
   gnucash/trunk/src/business/business-core/gncOrder.c
   gnucash/trunk/src/business/business-core/test/test-address.c
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/Scrub2.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/test/test-guid.c
Log:
Move QofInstance guid property from its public data structure to its
private data structure.


Modified: gnucash/trunk/lib/libqof/backend/file/qsf-backend.c
===================================================================
--- gnucash/trunk/lib/libqof/backend/file/qsf-backend.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/backend/file/qsf-backend.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -1209,7 +1209,7 @@
 		reference = g_new0(QofInstanceReference, 1);
 		reference->type = g_strdup(qsf_ent->e_type);
 		reference->ref_guid = cm_guid;
-		reference->ent_guid = &qsf_ent->guid;
+		reference->ent_guid = qof_instance_get_guid(qsf_ent);
 		copy_param = g_new0(QofParam, 1);
 		copy_param->param_name = g_strdup(cm_param->param_name);
 		copy_param->param_type = g_strdup(cm_param->param_type);

Modified: gnucash/trunk/lib/libqof/qof/deprecated.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/deprecated.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/deprecated.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -109,9 +109,6 @@
 void gnc_engine_suspend_events (void);
 /** \deprecated use qof_event_resume instead. */
 void gnc_engine_resume_events (void);
-/** \deprecated use qof_event_generate instead. */
-void gnc_engine_generate_event (const GUID *guid, QofIdType e_type, 
-         GNCEngineEventType event_type);
 /** \deprecated use QofBookMergeResult instead. */
 #define qof_book_mergeResult QofBookMergeResult
 /** \deprecated use QofBookMergeRule instead. */

Modified: gnucash/trunk/lib/libqof/qof/guid.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/guid.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/guid.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -63,6 +63,26 @@
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = QOF_MOD_ENGINE;
 
+/**
+ * gnc_value_get_guid
+ * @value: a #GValue whose value we want to get.
+ *
+ * Returns: the value stored in @value.
+ */
+G_CONST_RETURN GUID*
+gnc_value_get_guid (const GValue *value)
+{
+        GUID *val;
+
+        g_return_val_if_fail (value && G_IS_VALUE (value), NULL);
+        g_return_val_if_fail (GNC_VALUE_HOLDS_GUID (value), NULL);
+
+        val = (GUID*) g_value_get_boxed (value);
+
+        return val;
+}
+
+
 /* Memory management routines ***************************************/
 #ifdef HAVE_GLIB29
 GUID *
@@ -116,6 +136,17 @@
 #endif
 
 
+GUID *
+guid_copy (const GUID *guid)
+{
+  GUID *copy;
+
+  g_return_val_if_fail(guid, NULL);
+  copy = guid_malloc();
+  *copy = *guid;
+  return copy;
+}
+
 const GUID *
 guid_null(void)
 {
@@ -707,3 +738,57 @@
 {
   return g_hash_table_new (guid_hash_to_guint, guid_g_hash_table_equal);
 }
+
+/***************************/
+static void
+gnc_string_to_guid (const GValue *src, GValue *dest)
+{
+        /* FIXME: add more checks*/
+        GUID *guid;
+        const gchar *as_string;
+
+        g_return_if_fail (G_VALUE_HOLDS_STRING (src) &&
+                          GNC_VALUE_HOLDS_GUID (dest));
+
+        as_string = g_value_get_string (src);
+
+        guid = g_new0 (GUID, 1);
+        string_to_guid(as_string, guid);
+
+        g_value_take_boxed (dest, guid);
+}
+
+static void
+gnc_guid_to_string (const GValue *src, GValue *dest)
+{
+        const gchar *str;
+
+        g_return_if_fail (G_VALUE_HOLDS_STRING (dest) &&
+                          GNC_VALUE_HOLDS_GUID (src));
+
+        str = guid_to_string(gnc_value_get_guid (src));
+
+        g_value_set_string (dest, str);
+}
+
+GType
+gnc_guid_get_type (void)
+{
+        static GType type = 0;
+
+        if (G_UNLIKELY (type == 0)) {
+                type = g_boxed_type_register_static ("GUID",
+                                                     (GBoxedCopyFunc)guid_copy,
+                                                     (GBoxedFreeFunc)guid_free);
+
+                g_value_register_transform_func (G_TYPE_STRING,
+                                                 type,
+                                                 gnc_string_to_guid);
+
+                g_value_register_transform_func (type,
+                                                 G_TYPE_STRING,
+                                                 gnc_guid_to_string);
+        }
+
+        return type;
+}

Modified: gnucash/trunk/lib/libqof/qof/guid.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/guid.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/guid.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -25,6 +25,7 @@
 #define GUID_H 
 
 #include <stddef.h>
+#include <glib-object.h>
 
 /** @addtogroup Entity
     @{ */
@@ -59,6 +60,12 @@
 } GUID;
 
 
+#define GNC_TYPE_GUID (gnc_guid_get_type())
+#define GNC_VALUE_HOLDS_GUID(value) G_VALUE_HOLDS(value, GNC_TYPE_GUID)
+
+GType gnc_guid_get_type (void); 
+G_CONST_RETURN GUID* gnc_value_get_guid (const GValue *value); 
+
 /** number of characters needed to encode a guid as a string
  * not including the null terminator. */
 #define GUID_ENCODING_LENGTH 32
@@ -144,6 +151,8 @@
 /* Return a guid set to all zero's */
 void   guid_free (GUID *guid);
 
+GUID *guid_copy (const GUID *guid);
+
 /** The guid_to_string() routine returns a null-terminated string 
  *  encoding of the id. String encodings of identifiers are hex 
  *  numbers printed only with the characters '0' through '9' and 

Modified: gnucash/trunk/lib/libqof/qof/kvp-util-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/kvp-util-p.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/kvp-util-p.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -88,7 +88,7 @@
  */
 
 KvpFrame * gnc_kvp_bag_find_by_guid (KvpFrame *root,  const char * path,
-                         const char *guid_name, GUID *desired_guid);
+                         const char *guid_name, const GUID *desired_guid);
 
 
 /** Remove the given frame from the bag.  The frame is removed,

Modified: gnucash/trunk/lib/libqof/qof/kvp-util.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/kvp-util.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/kvp-util.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -94,7 +94,7 @@
 
 KvpFrame *
 gnc_kvp_bag_find_by_guid (KvpFrame *root, const char * path,
-                         const char *guid_name, GUID *desired_guid)
+                         const char *guid_name, const GUID *desired_guid)
 {
   KvpValue *arr;
   KvpValueType valtype;

Modified: gnucash/trunk/lib/libqof/qof/qofbookmerge.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbookmerge.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofbookmerge.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -452,7 +452,7 @@
 	currentRule = mergeData->currentRule;
 	g_return_if_fail(currentRule != NULL);
 	g = guid_malloc();
-	*g = mergeEnt->guid;
+	qof_instance_copy_guid(g, mergeEnt);
 	mergeRule = g_new(QofBookMergeRule,1);
 	mergeRule->importEnt = 		mergeEnt;
 	mergeRule->difference = 	difference = 0;

Modified: gnucash/trunk/lib/libqof/qof/qofevent-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofevent-p.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofevent-p.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -39,14 +39,6 @@
   gint handler_id;
 } HandlerInfo;
 
-/** \deprecated Prevents handlers locating the QofCollection or casting
-to the QofInstance and locating the book, editlevel or dirty flag.
-Use qof_event_gen instead.
-*/
-void
-qof_event_generate (const GUID *guid, QofIdType e_type, 
-					QofEventId event_id);
-
 /* generates an event even when events are suspended! */
 void qof_event_force (QofInstance *entity, QofEventId event_id, gpointer event_data);
 

Modified: gnucash/trunk/lib/libqof/qof/qofevent.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofevent.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofevent.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -295,17 +295,4 @@
   qof_event_generate_internal (entity, event_id, event_data);
 }
 
-/* deprecated */
-void 
-qof_event_generate (const GUID *guid, QofIdType e_type, 
-					QofEventId event_id)
-{
-  QofInstance ent;
-  ent.guid = *guid;
-  ent.e_type = e_type;
-  if (suspend_counter) return;
-  /* caution: this is an incomplete entity! */
-  qof_event_generate_internal (&ent, event_id, NULL);
-}
-
 /* =========================== END OF FILE ======================= */

Modified: gnucash/trunk/lib/libqof/qof/qofid-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid-p.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofid-p.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -35,11 +35,6 @@
 /* This file defines an engine-only API for using QOF entity
  * identifiers. */
 
-/** Set the ID of the entity, over-riding the previous ID. 
- *  Very dangerous, use only for file i/o work. 
- */
-void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
-
 /** Take entity, remove it from whatever collection its currently
  *  in, and place it in a new collection.  To be used only for
  *  moving entity from one book to another.

Modified: gnucash/trunk/lib/libqof/qof/qofid.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofid.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -130,10 +130,13 @@
 qof_collection_remove_entity (QofInstance *ent)
 {
   QofCollection *col;
+  const GUID *guid;
+
   if (!ent) return;
   col = qof_instance_get_collection(ent);
   if (!col) return;
-  g_hash_table_remove (col->hash_of_entities, &ent->guid);
+  guid = qof_instance_get_guid(ent);
+  g_hash_table_remove (col->hash_of_entities, guid);
   if (!qof_alt_dirty_mode)
     qof_collection_mark_dirty(col);
   qof_instance_set_collection(ent, NULL);
@@ -142,11 +145,14 @@
 void
 qof_collection_insert_entity (QofCollection *col, QofInstance *ent)
 {
+  const GUID *guid;
+
   if (!col || !ent) return;
-  if (guid_equal(&ent->guid, guid_null())) return;
+  guid = qof_instance_get_guid(ent);
+  if (guid_equal(guid, guid_null())) return;
   g_return_if_fail (col->e_type == ent->e_type);
   qof_collection_remove_entity (ent);
-  g_hash_table_insert (col->hash_of_entities, &ent->guid, ent);
+  g_hash_table_insert (col->hash_of_entities, (gpointer)guid, ent);
   if (!qof_alt_dirty_mode)
     qof_collection_mark_dirty(col);
   qof_instance_set_collection(ent, col);
@@ -156,14 +162,16 @@
 qof_collection_add_entity (QofCollection *coll, QofInstance *ent)
 {
 	QofInstance *e;
+        const GUID *guid;
 
 	e = NULL;
 	if (!coll || !ent) { return FALSE; }
-	if (guid_equal(&ent->guid, guid_null())) { return FALSE; }
+        guid = qof_instance_get_guid(ent);
+        if (guid_equal(guid, guid_null())) { return FALSE; }
 	g_return_val_if_fail (coll->e_type == ent->e_type, FALSE);
-	e = qof_collection_lookup_entity(coll, &ent->guid);
+	e = qof_collection_lookup_entity(coll, guid);
 	if ( e != NULL ) { return FALSE; }
-	g_hash_table_insert (coll->hash_of_entities, &ent->guid, ent);
+	g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
 	if (!qof_alt_dirty_mode)
 	  qof_collection_mark_dirty(coll);
 	return TRUE;
@@ -192,6 +200,7 @@
 {
 	QofCollection *target;
 	QofInstance *e;
+        const GUID *guid;
 	gint value;
 
 	e = NULL;
@@ -199,14 +208,15 @@
 	if (!target || !ent) { return; }
 	value = *(gint*)qof_collection_get_data(target);
 	if (value != 0) { return; }
-	if (guid_equal(&ent->guid, guid_null())) 
+        guid = qof_instance_get_guid(ent);
+        if (guid_equal(guid, guid_null())) 
 	{
 		value = -1;
 		qof_collection_set_data(target, &value);
 		return; 
 	}
 	g_return_if_fail (target->e_type == ent->e_type);
-	e = qof_collection_lookup_entity(target, &ent->guid);
+	e = qof_collection_lookup_entity(target, guid);
 	if ( e == NULL )
 	{
 		value = 1;

Modified: gnucash/trunk/lib/libqof/qof/qofid.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofid.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -152,9 +152,6 @@
  *  collection (and therefore the book) is never changed. */
 void qof_set_alt_dirty_mode (gboolean enabled);
 
-/** Return the GUID of this entity */
-const GUID * qof_instance_get_guid (const QofInstance *);
-
 /** @name Collections of Entities 
  @{ */
 

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -61,7 +61,7 @@
 typedef struct QofInstancePrivate
 {
 //    QofIdType        e_type;    /**<	Entity type */
-//    GUID             guid;      /**< GUID for the entity */
+    GUID guid;                  /**< GUID for the entity */
     QofCollection  *collection; /**< Entity collection */
 
     /* The entity_table in which this instance is stored */
@@ -122,6 +122,15 @@
     g_type_class_add_private(klass, sizeof(QofInstancePrivate));
 
     g_object_class_install_property
+	(object_class,
+	 PROP_GUID,
+	 g_param_spec_boxed ("guid",
+			      "Object GUID",
+			      "The object Globally Unique ID.",
+			      GNC_TYPE_GUID,
+			      G_PARAM_READWRITE));
+
+    g_object_class_install_property
         (object_class,
          PROP_COLLECTION,
          g_param_spec_pointer ("collection",
@@ -243,12 +252,13 @@
             PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type);
             return;
         }
+        priv = GET_PRIVATE(inst);
         inst->e_type = CACHE_INSERT (type);
 
         do {
-          guid_new(&inst->guid);
+          guid_new(&priv->guid);
 
-          if (NULL == qof_collection_lookup_entity (col, &inst->guid))
+          if (NULL == qof_collection_lookup_entity (col, &priv->guid))
             break;
 
           PWARN("duplicate id created, trying again");
@@ -307,7 +317,7 @@
 
     switch (prop_id) {
         case PROP_GUID:
-            g_value_set_boxed(value, &inst->guid);
+            g_value_set_boxed(value, &priv->guid);
             break;
         case PROP_COLLECTION:
             g_value_set_pointer(value, priv->collection);
@@ -384,32 +394,61 @@
 }
 
 const GUID *
-qof_instance_get_guid (const QofInstance *inst)
+qof_instance_get_guid (gconstpointer inst)
 {
     QofInstancePrivate *priv;
 
     if (!inst) return guid_null();
     g_return_val_if_fail(QOF_IS_INSTANCE(inst), guid_null());
     priv = GET_PRIVATE(inst);
-    return &(inst->guid);
+    return &(priv->guid);
 }
 
 void
-qof_instance_set_guid (QofInstance *ent, const GUID *guid)
+qof_instance_set_guid (gpointer ptr, const GUID *guid)
 {
     QofInstancePrivate *priv;
+    QofInstance *inst;
     QofCollection *col;
 
-    priv = GET_PRIVATE(ent);
-    if (guid_equal (guid, &ent->guid))
+    g_return_if_fail(QOF_IS_INSTANCE(ptr));
+
+    inst = QOF_INSTANCE(ptr);
+    priv = GET_PRIVATE(inst);
+    if (guid_equal (guid, &priv->guid))
         return;
 
     col = priv->collection;
-    qof_collection_remove_entity (ent);
-    ent->guid = *guid;
-    qof_collection_insert_entity (col, ent);
+    qof_collection_remove_entity(inst);
+    priv->guid = *guid;
+    qof_collection_insert_entity(col, inst);
 }
 
+void
+qof_instance_copy_guid (gpointer to, gconstpointer from)
+{
+    QofInstancePrivate *to_priv, *from_priv;
+
+    g_return_if_fail(QOF_IS_INSTANCE(to));
+    g_return_if_fail(QOF_IS_INSTANCE(from));
+
+    GET_PRIVATE(to)->guid = GET_PRIVATE(from)->guid;
+}
+
+gint
+qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
+{
+    const QofInstancePrivate *priv1, *priv2;
+
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), -1);
+    g_return_val_if_fail(QOF_IS_INSTANCE(ptr2),  1);
+
+    priv1 = GET_PRIVATE(ptr1);
+    priv2 = GET_PRIVATE(ptr2);
+
+    return guid_compare(&priv1->guid, &priv2->guid);
+}
+
 QofCollection *
 qof_instance_get_collection (gconstpointer ptr)
 {
@@ -596,7 +635,7 @@
     priv = GET_PRIVATE(inst);
     if (priv->dirty) {
         printf("%s instance %s is dirty.\n", inst->e_type,
-               guid_to_string(&inst->guid));
+               guid_to_string(&priv->guid));
     }
 }
 
@@ -662,12 +701,12 @@
 
   /* Make a note of where the copy came from */
   gnc_kvp_bag_add (to->kvp_data, "gemini", now,
-                                  "inst_guid", &from->guid,
-                                  "book_guid", &from_priv->book->inst.guid,
+                                  "inst_guid", &from_priv->guid,
+                                  "book_guid", &fb_priv->guid,
                                   NULL);
   gnc_kvp_bag_add (from->kvp_data, "gemini", now,
-                                  "inst_guid", &to->guid,
-                                  "book_guid", &to_priv->book->inst.guid,
+                                  "inst_guid", &to_priv->guid,
+                                  "book_guid", &tb_priv->guid,
                                   NULL);
 
   to_priv->dirty = TRUE;
@@ -680,12 +719,14 @@
 	KvpFrame *fr;
 	GUID * twin_guid;
 	QofInstance * twin;
+        QofInstancePrivate *bpriv;
 
 	if (!src || !target_book) return NULL;
 	ENTER (" ");
 
+        bpriv = GET_PRIVATE(QOF_INSTANCE(target_book));
 	fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini",
-	                             "book_guid", &target_book->inst.guid);
+	                             "book_guid", &bpriv->guid);
 
 	twin_guid = kvp_frame_get_guid (fr, "inst_guid");
 

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.h	2007-05-02 05:42:41 UTC (rev 16039)
@@ -67,7 +67,6 @@
    GObject object;
 
    QofIdType        e_type;		   /**<	Entity type */
-   GUID             guid;		   /**< GUID for the entity */
 
   /* kvp_data is a key-value pair database for storing arbirtary
    * information associated with this instance.  
@@ -100,14 +99,27 @@
 gboolean qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2);
 
 /** Return the GUID of this instance */
-const GUID * qof_instance_get_guid (const QofInstance *);
+const GUID * qof_instance_get_guid (gconstpointer);
 
 /** Return the collection this instance belongs to */
 QofCollection* qof_instance_get_collection (gconstpointer inst);
 
 /** Set the GUID of this instance */
-void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
+void qof_instance_set_guid (gpointer inst, const GUID *guid);
 
+/** Copy the GUID from one instance to another.  This routine should
+ *  be used with extreme caution, since GUID values are everywhere
+ *  assumed to be unique. */
+void qof_instance_copy_guid (gpointer to, gconstpointer from);
+
+/** Compare the GUID values of two instances.  This routine returns 0
+ *  if the two values are equal, <0 if the first is smaller than the
+ *  second, or >0 if the second is smaller tan the first. */
+gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr2);
+
+//QofIdType qof_instance_get_e_type (const QofInstance *inst);
+//void qof_instance_set_e_type (QofInstance *ent, QofIdType e_type);
+
 /** Return the pointer to the kvp_data */
 KvpFrame* qof_instance_get_slots (const QofInstance *);
 

Modified: gnucash/trunk/lib/libqof/qof/qofreference.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofreference.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofreference.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -127,7 +127,7 @@
 	reference = g_new0(QofInstanceReference, 1);
 	reference->type = ent->e_type;
 	reference->ref_guid = g_new(GUID, 1);
-	reference->ent_guid = &ent->guid;
+	reference->ent_guid = qof_instance_get_guid(ent);
 	if(qof_object_is_choice(ent->e_type)) 
 	{ 
 		reference->choice_type = ref_ent->e_type; 

Modified: gnucash/trunk/lib/libqof/qof/qofsession.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofsession.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/lib/libqof/qof/qofsession.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -373,7 +373,7 @@
 	ref = g_new0(QofInstanceReference, 1);
 	ref->type = ent->e_type;
 	ref->ref_guid = g_new(GUID, 1);
-	ref->ent_guid = &ent->guid;
+	ref->ent_guid = qof_instance_get_guid(ent);
 	ref->param = qof_class_get_parameter(ent->e_type, 
 		qecd->param->param_name);
 	cm_guid = qof_instance_get_guid(ref_ent);

Modified: gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -164,7 +164,7 @@
         ret = xmlNewNode( NULL, BAD_CAST "gnc:freqspec" );
         xmlSetProp( ret, BAD_CAST "version", BAD_CAST freqspec_version_string );
 
-        xmlAddChild( ret, guid_to_dom_tree( "fs:id", &fs->entity.guid ) );
+        xmlAddChild( ret, guid_to_dom_tree( "fs:id", qof_instance_get_guid(fs) ) );
 
         xmlSub = text_to_dom_tree( "fs:ui_type",
                                    uiFreqTypeStrs[ xaccFreqSpecGetUIType(fs) ].str );
@@ -575,7 +575,7 @@
         fsParseData *fspd = data;
         GUID        *guid;
         guid = dom_tree_to_guid( node );
-        fspd->fs->entity.guid = *guid;
+        qof_instance_set_guid(fspd->fs, guid);
         return TRUE;
 }
 

Modified: gnucash/trunk/src/backend/postgres/txn.c
===================================================================
--- gnucash/trunk/src/backend/postgres/txn.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/backend/postgres/txn.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -171,7 +171,7 @@
         {
           Split *s = split_node->data;
 
-          if (s && guid_equal (&s->inst.guid, &dti->guid))
+          if (s && guid_equal (qof_instance_get_guid(s), &dti->guid))
           {
             pgendStoreAuditSplit (be, s, SQL_DELETE);
             break;

Modified: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/business/business-core/gncEntry.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -1231,7 +1231,7 @@
   compare = safe_strcmp (a->action, b->action);
   if (compare) return compare;
 
-  return guid_compare (&(a->inst.guid), &(b->inst.guid));
+  return qof_instance_guid_compare(a, b);
 }
 
 /* ============================================================= */

Modified: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -1512,7 +1512,7 @@
   compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
   if (compare) return compare;
 
-  return guid_compare (&(a->inst.guid), &(b->inst.guid));
+  return qof_instance_guid_compare(a, b);
 }
 
 /* ============================================================= */

Modified: gnucash/trunk/src/business/business-core/gncOrder.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/business/business-core/gncOrder.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -395,7 +395,7 @@
   compare = timespec_cmp (&(a->closed), &(b->closed));
   if (compare) return compare;
 
-  return guid_compare (&(a->inst.guid), &(b->inst.guid));
+  return qof_instance_guid_compare(a, b);
 }
 
 /* =========================================================== */

Modified: gnucash/trunk/src/business/business-core/test/test-address.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-address.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/business/business-core/test/test-address.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -38,18 +38,18 @@
 static void
 test_address (void)
 {
-  QofInstance ent;
+  QofInstance *ent;
   GncAddress *address;
   QofBook *book = qof_book_new ();
 
-  ent.e_type = "asdf";
-  ent.guid = *guid_null();
+  ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
+  ent->e_type = "asdf";
 
   /* Test creation/destruction */
   {
     do_test (gncAddressCreate (NULL,  NULL) == NULL, "address create NULL");
 
-    address = gncAddressCreate (book, &ent);
+    address = gncAddressCreate (book, ent);
     do_test (address != NULL, "address create");
 
     gncAddressBeginEdit (address);
@@ -59,7 +59,7 @@
 
   /* Test setting routines */
   {
-    address = gncAddressCreate (book, &ent);
+    address = gncAddressCreate (book, ent);
     test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
     test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
     test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/Account.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -1316,7 +1316,7 @@
   }
 
   if(check_guids) {
-    if(!guid_equal(&aa->inst.guid, &ab->inst.guid))
+    if(qof_instance_guid_compare(aa, ab) != 0)
     {
       PWARN ("GUIDs differ");
       return FALSE;
@@ -2013,7 +2013,7 @@
     return result;
 
   /* guarantee a stable sort */
-  return guid_compare (&(aa->inst.guid), &(ab->inst.guid));
+  return qof_instance_guid_compare(aa, ab);
 }
 
 static int

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/SchedXaction.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -67,6 +67,7 @@
 xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
 {
    Account        *ra;
+   const GUID *guid;
 
    qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
 
@@ -88,8 +89,8 @@
 
    /* create a new template account for our splits */
    sx->template_acct = xaccMallocAccount(book);
-   xaccAccountSetName( sx->template_acct,
-                       guid_to_string( &sx->inst.guid ));
+   guid = qof_instance_get_guid( sx );
+   xaccAccountSetName( sx->template_acct, guid_to_string( guid ));
    xaccAccountSetCommodity
      (sx->template_acct,
       gnc_commodity_new( book,

Modified: gnucash/trunk/src/engine/Scrub2.c
===================================================================
--- gnucash/trunk/src/engine/Scrub2.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/Scrub2.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -34,6 +34,7 @@
 
 #include <glib.h>
 
+#include "qof.h"
 #include "Account.h"
 #include "AccountP.h"
 #include "Transaction.h"
@@ -320,7 +321,7 @@
 
    /* Find and remove the matching guid's */
    ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->inst.kvp_data, "lot-split",
-                    "peer_guid", &sb->inst.guid);
+                    "peer_guid", qof_instance_get_guid(sb));
    if (ksub) 
    {
       gnc_kvp_bag_remove_frame (sa->inst.kvp_data, "lot-split", ksub);
@@ -329,7 +330,7 @@
 
    /* Now do it in the other direction */
    ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->inst.kvp_data, "lot-split",
-                    "peer_guid", &sa->inst.guid);
+                    "peer_guid", qof_instance_get_guid(sa));
    if (ksub) 
    {
       gnc_kvp_bag_remove_frame (sb->inst.kvp_data, "lot-split", ksub);
@@ -399,6 +400,7 @@
    Transaction *txn;
    SplitList *node;
    GNCLot *lot;
+   const GUID *guid;
 
    if (FALSE == is_subsplit (split)) return FALSE;
 
@@ -422,8 +424,9 @@
        * example.  Only worry about adjacent sub-splits.  By 
        * repeatedly merging adjacent subsplits, we'll get the non-
        * adjacent ones too. */
+      guid = qof_instance_get_guid(s);
       if (gnc_kvp_bag_find_by_guid (split->inst.kvp_data, "lot-split",
-                                    "peer_guid", &s->inst.guid) == NULL)
+                                    "peer_guid", guid) == NULL)
          continue;
          
       merge_splits (split, s);

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/Split.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -34,6 +34,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "qof.h"
 #include "Split.h"
 #include "AccountP.h"
 #include "Scrub.h"
@@ -173,7 +174,7 @@
    * have to fix this up.
    */
   split->inst.e_type = NULL;
-  split->inst.guid = s->inst.guid;
+  qof_instance_copy_guid(split, s);
   qof_instance_copy_book(split, s);
 
   split->parent = s->parent;
@@ -347,7 +348,7 @@
   if (sa == sb) return TRUE;
 
   if (check_guids) {
-    if (!guid_equal(&(sa->inst.guid), &(sb->inst.guid)))
+    if (qof_instance_guid_compare(sa, sb) != 0)
     {
       PWARN ("GUIDs differ");
       return FALSE;
@@ -1166,7 +1167,7 @@
   DATE_CMP(sa,sb,date_reconciled);
 
   /* else, sort on guid - keeps sort stable. */
-  retval = guid_compare(&(sa->inst.guid), &(sb->inst.guid));
+  retval = qof_instance_guid_compare(sa, sb);
   if (retval) return retval;
 
   return 0;

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/Transaction.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -396,7 +396,7 @@
    * use this transaction, we'll have to fix this up.
    */
   trans->inst.e_type = NULL;
-  trans->inst.guid = *guid_null();
+  qof_instance_set_guid(trans, guid_null());
   qof_instance_copy_book(trans, t);
   trans->inst.kvp_data = kvp_frame_copy (t->inst.kvp_data);
 
@@ -538,7 +538,7 @@
   if (ta == tb) return TRUE;
 
   if (check_guids) {
-    if (!guid_equal(&(ta->inst.guid), &(tb->inst.guid)))
+    if (qof_instance_guid_compare(ta, tb) != 0)
     {
       PWARN ("GUIDs differ");
       return FALSE;
@@ -1263,7 +1263,7 @@
     return retval;
 
   /* else, sort on guid - keeps sort stable. */
-  return guid_compare(&(ta->inst.guid), &(tb->inst.guid));
+  return qof_instance_guid_compare(ta, tb);
 }
 
 /********************************************************************\

Modified: gnucash/trunk/src/engine/test/test-guid.c
===================================================================
--- gnucash/trunk/src/engine/test/test-guid.c	2007-05-02 03:18:46 UTC (rev 16038)
+++ gnucash/trunk/src/engine/test/test-guid.c	2007-05-02 05:42:41 UTC (rev 16039)
@@ -58,6 +58,7 @@
   QofInstance *ent, *eblk[NENT];
   QofCollection *col;
   QofIdType type;
+  GUID guid;
 
   sess = get_random_session ();
   book = qof_session_get_book (sess);
@@ -70,11 +71,14 @@
   {
     ent = g_object_new(QOF_TYPE_INSTANCE, NULL);
     eblk[i] = ent;
-    guid_new(&ent->guid);
-    do_test ((NULL == qof_collection_lookup_entity (col, &ent->guid)),
+    guid_new(&guid);
+    ent = g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL);
+    do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
 						  "duplicate guid");
 	 ent->e_type = type;
 	 qof_collection_insert_entity (col, ent);
+         do_test ((NULL != qof_collection_lookup_entity (col, &guid)),
+                  "guid not found");
   }
 
   /* Make valgrind happy -- destroy the session. */



More information about the gnucash-changes mailing list