[Gnucash-changes] r13359 - gnucash/trunk/src/engine - Convert Lots from a QofEntity to a QofInstance.

Chris Shoemaker chris at cvs.gnucash.org
Wed Feb 22 01:01:07 EST 2006


Author: chris
Date: 2006-02-22 01:01:07 -0500 (Wed, 22 Feb 2006)
New Revision: 13359
Trac: http://svn.gnucash.org/trac/changeset/13359

Modified:
   gnucash/trunk/src/engine/Period.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-lot-p.h
   gnucash/trunk/src/engine/gnc-lot.c
Log:
   Convert Lots from a QofEntity to a QofInstance.
   They now store their own dirty state.


Modified: gnucash/trunk/src/engine/Period.c
===================================================================
--- gnucash/trunk/src/engine/Period.c	2006-02-22 03:30:48 UTC (rev 13358)
+++ gnucash/trunk/src/engine/Period.c	2006-02-22 06:01:07 UTC (rev 13359)
@@ -216,9 +216,10 @@
    if (!lot || !book) return;
    
    /* If this is the same book, its a no-op. */
-   if (lot->book == book) return;
+   if (gnc_lot_get_book(lot) == book) return;
 
-   if (qof_book_get_backend(book) != qof_book_get_backend(lot->book))
+   if (qof_book_get_backend(book) != 
+       qof_book_get_backend(gnc_lot_get_book(lot)))
    {
       gnc_book_insert_lot_clobber (book, lot);
       return;
@@ -226,8 +227,8 @@
    ENTER ("lot=%p", lot);
 
    col = qof_book_get_collection (book, GNC_ID_LOT);
-   lot->book = book;
-   qof_collection_insert_entity (col, &lot->entity);
+   lot->inst.book = book;
+   qof_collection_insert_entity (col, &lot->inst.entity);
 
    /* Move the splits over (only if they haven't already been moved). */
    col = qof_book_get_collection (book, GNC_ID_SPLIT);

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2006-02-22 03:30:48 UTC (rev 13358)
+++ gnucash/trunk/src/engine/Transaction.c	2006-02-22 06:01:07 UTC (rev 13359)
@@ -602,7 +602,7 @@
   if (lot)
   {
     /* A change of value/amnt affects gains displat, etc. */
-    gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
+    gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
   }
 }
 
@@ -624,7 +624,7 @@
     if (lot)
     {
       /* A change of transaction date might affect opening date of lot */
-      gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
+      gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
     }
   }
 

Modified: gnucash/trunk/src/engine/gnc-lot-p.h
===================================================================
--- gnucash/trunk/src/engine/gnc-lot-p.h	2006-02-22 03:30:48 UTC (rev 13358)
+++ gnucash/trunk/src/engine/gnc-lot-p.h	2006-02-22 06:01:07 UTC (rev 13359)
@@ -42,14 +42,8 @@
 
 struct gnc_lot_struct
 {
-  QofEntity entity;     /* Unique guid for this lot */
+  QofInstance inst;
 
-  /* Book that this lot belongs to */
-  QofBook *book;
-
-  /* Anchor for generic lot-specific data. */
-  KvpFrame *kvp_data;
-
   /* Account to which this lot applies.  All splits in the lot must
    * belong to this account.
    */

Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2006-02-22 03:30:48 UTC (rev 13358)
+++ gnucash/trunk/src/engine/gnc-lot.c	2006-02-22 06:01:07 UTC (rev 13359)
@@ -52,17 +52,13 @@
 static void
 gnc_lot_init (GNCLot *lot, QofBook *book)
 {
-   QofCollection *col;
    ENTER ("(lot=%p, book=%p)", lot, book);
-   lot->kvp_data = kvp_frame_new();
    lot->account = NULL;
    lot->splits = NULL;
    lot->is_closed = -1;
    lot->marker = 0;
   
-   lot->book = book;
-   col = qof_book_get_collection (book, GNC_ID_LOT);
-   qof_entity_init (&lot->entity, GNC_ID_LOT, col);
+   qof_instance_init(&lot->inst, GNC_ID_LOT, book);
    LEAVE ("(lot=%p, book=%p)", lot, book);
 }
 
@@ -74,7 +70,7 @@
 
    lot = g_new (GNCLot, 1);
    gnc_lot_init (lot, book);
-   gnc_engine_gen_event (&lot->entity, GNC_EVENT_CREATE);
+   gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_CREATE);
    return lot;
 }
 
@@ -85,9 +81,8 @@
    if (!lot) return;
    
    ENTER ("(lot=%p)", lot);
-   gnc_engine_gen_event (&lot->entity, GNC_EVENT_DESTROY);
+   gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_DESTROY);
 
-   qof_entity_release (&lot->entity);
    
    for (node=lot->splits; node; node=node->next)
    {
@@ -96,12 +91,9 @@
    }
    g_list_free (lot->splits);
    
-   kvp_frame_delete (lot->kvp_data);
-   lot->kvp_data = NULL;
-   
    lot->account = NULL;
    lot->is_closed = TRUE;
-
+   qof_instance_release (&lot->inst);
    g_free (lot);
 }
 
@@ -119,8 +111,7 @@
 QofBook *
 gnc_lot_get_book (GNCLot *lot)
 {
-  if (!lot) return NULL;
-  return lot->book;
+    return qof_instance_get_book(QOF_INSTANCE(lot));
 }
 
 /* ============================================================= */
@@ -143,8 +134,7 @@
 KvpFrame *
 gnc_lot_get_slots (GNCLot *lot)
 {
-   if (!lot) return NULL;
-   return lot->kvp_data;
+    return qof_instance_get_slots(QOF_INSTANCE(lot));
 }
 
 SplitList *
@@ -167,30 +157,30 @@
 gnc_lot_get_title (GNCLot *lot)
 {
    if (!lot) return NULL;
-   return kvp_frame_get_string (lot->kvp_data, "/title");
+   return kvp_frame_get_string (lot->inst.kvp_data, "/title");
 }
 
 const char * 
 gnc_lot_get_notes (GNCLot *lot)
 {
    if (!lot) return NULL;
-   return kvp_frame_get_string (lot->kvp_data, "/notes");
+   return kvp_frame_get_string (lot->inst.kvp_data, "/notes");
 }
 
 void
 gnc_lot_set_title (GNCLot *lot, const char *str)
 {
    if (!lot) return;
-   qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
-   return kvp_frame_set_str (lot->kvp_data, "/title", str);
+   qof_instance_mark_dirty(QOF_INSTANCE(lot));
+   return kvp_frame_set_str (lot->inst.kvp_data, "/title", str);
 }
 
 void
 gnc_lot_set_notes (GNCLot *lot, const char *str)
 {
    if (!lot) return;
-   qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
-   return kvp_frame_set_str (lot->kvp_data, "/notes", str);
+   qof_instance_mark_dirty(QOF_INSTANCE(lot));
+   return kvp_frame_set_str (lot->inst.kvp_data, "/notes", str);
 }
 
 /* ============================================================= */
@@ -245,7 +235,7 @@
         gnc_num_dbg_to_string (split->amount),
         gnc_num_dbg_to_string (split->value));
    acc = xaccSplitGetAccount (split);
-   qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
+   qof_instance_mark_dirty(QOF_INSTANCE(lot));
    if (NULL == lot->account)
    {
       xaccAccountInsertLot (acc, lot);
@@ -271,7 +261,7 @@
     /* for recomputation of is-closed */
    lot->is_closed = -1;
 
-   gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
+   gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
 }
 
 void
@@ -280,7 +270,7 @@
    if (!lot || !split) return;
 
    ENTER ("(lot=%p, split=%p)", lot, split);
-   qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
+   qof_instance_mark_dirty(QOF_INSTANCE(lot));
    lot->splits = g_list_remove (lot->splits, split);
    split->lot = NULL;
    lot->is_closed = -1;   /* force an is-closed computation */
@@ -290,7 +280,7 @@
       xaccAccountRemoveLot (lot->account, lot);
       lot->account = NULL;
    }
-   gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
+   gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
 }
 
 /* ============================================================== */
@@ -356,40 +346,44 @@
 
 /* ============================================================= */
 
-/* Should the object description be enabled?. */
-/*
 static QofObject gncLotDesc =
 {
-interface_version:  QOF_OBJECT_VERSION,
-e_type:             GNC_ID_LOT,
-type_label:         "Lot",
-create:             (gpointer)gnc_lot_new,
-book_begin:         NULL,
-book_end:           NULL,
-is_dirty:           NULL,
-mark_clean:         NULL,
-foreach:            qof_collection_foreach,
-printable:          NULL,
-version_cmp:        (int (*)(gpointer,gpointer))qof_instance_version_cmp,
+    interface_version:  QOF_OBJECT_VERSION,
+    e_type:             GNC_ID_LOT,
+    type_label:         "Lot",
+    create:             (gpointer)gnc_lot_new,
+    book_begin:         NULL,
+    book_end:           NULL,
+    is_dirty:           qof_collection_is_dirty,
+    mark_clean:         qof_collection_mark_clean,
+    foreach:            qof_collection_foreach,
+    printable:          NULL,
+    version_cmp:        (int (*)(gpointer,gpointer))qof_instance_version_cmp,
 };
-*/
 
+
 gboolean gnc_lot_register (void)
 {
-  static const QofParam params[] = {
-   { LOT_TITLE, QOF_TYPE_STRING, (QofAccessFunc)gnc_lot_get_title, (QofSetterFunc)gnc_lot_set_title },
-   { LOT_NOTES,	QOF_TYPE_STRING, (QofAccessFunc)gnc_lot_get_notes, (QofSetterFunc)gnc_lot_set_notes },
-    { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
-    { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)gnc_lot_get_book, NULL },
-    { LOT_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gnc_lot_is_closed, NULL },
-    { LOT_BALANCE, QOF_TYPE_NUMERIC, (QofAccessFunc)gnc_lot_get_balance, NULL },
-    { NULL },
-  };
+    static const QofParam params[] = {
+        { LOT_TITLE, QOF_TYPE_STRING, 
+          (QofAccessFunc) gnc_lot_get_title, 
+          (QofSetterFunc) gnc_lot_set_title },
+        { LOT_NOTES, QOF_TYPE_STRING, 
+          (QofAccessFunc) gnc_lot_get_notes, 
+          (QofSetterFunc) gnc_lot_set_notes },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, 
+          (QofAccessFunc) qof_entity_get_guid, NULL },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, 
+          (QofAccessFunc) gnc_lot_get_book, NULL },
+        { LOT_IS_CLOSED, QOF_TYPE_BOOLEAN, 
+          (QofAccessFunc) gnc_lot_is_closed, NULL },
+        { LOT_BALANCE, QOF_TYPE_NUMERIC, 
+          (QofAccessFunc) gnc_lot_get_balance, NULL },
+        { NULL },
+    };
 
-  qof_class_register (GNC_ID_LOT, NULL, params);
-  return TRUE;
-//  return qof_object_register(&gncLotDesc);
-
+    qof_class_register (GNC_ID_LOT, NULL, params);
+    return qof_object_register(&gncLotDesc);
 }
 
 /* ========================== END OF FILE ========================= */



More information about the gnucash-changes mailing list