r14971 - gnucash/branches/swig-redo/src - Move the KVP option registry implementation from guile into C.

Chris Shoemaker chris at cvs.gnucash.org
Mon Oct 9 20:03:23 EDT 2006


Author: chris
Date: 2006-10-09 20:03:22 -0400 (Mon, 09 Oct 2006)
New Revision: 14971
Trac: http://svn.gnucash.org/trac/changeset/14971

Modified:
   gnucash/branches/swig-redo/src/app-utils/app-utils.i
   gnucash/branches/swig-redo/src/app-utils/app-utils.scm
   gnucash/branches/swig-redo/src/app-utils/kvp-option-registry.scm
   gnucash/branches/swig-redo/src/app-utils/option-util.c
   gnucash/branches/swig-redo/src/app-utils/option-util.h
   gnucash/branches/swig-redo/src/business/business-ledger/gncEntryLedgerLoad.c
   gnucash/branches/swig-redo/src/business/business-utils/business-prefs.scm
   gnucash/branches/swig-redo/src/gnome-utils/gnome-utils.scm
   gnucash/branches/swig-redo/src/tax/us/txf-de_DE.scm
Log:
Move the KVP option registry implementation from guile into C.
  - Unwrap some C->guile->C round-trips.
  - This removes a dependence on the gwrap-provided representation of a
    wrapped QofIdType.



Modified: gnucash/branches/swig-redo/src/app-utils/app-utils.i
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/app-utils.i	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/app-utils/app-utils.i	2006-10-10 00:03:22 UTC (rev 14971)
@@ -121,3 +121,9 @@
 time_t gnc_accounting_period_fiscal_start(void);
 time_t gnc_accounting_period_fiscal_end(void);
 
+//temporary, until QofIdType is swigified
+
+%typemap(in) QofIdType { $1 = gw_wcp_get_ptr($input); }
+SCM gnc_make_kvp_options(QofIdType id_type);
+void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
+

Modified: gnucash/branches/swig-redo/src/app-utils/app-utils.scm
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/app-utils.scm	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/app-utils/app-utils.scm	2006-10-10 00:03:22 UTC (rev 14971)
@@ -238,16 +238,12 @@
 (export simple-obj-from-list)
 (export make-simple-obj)
 
-;; kvp-option-registry
-(export gnc:register-kvp-option-generator)
-(export gnc:unregister-kvp-option-generator)
-(export gnc:make-kvp-options)
+(define gnc:*kvp-option-path* '("options"))
 (export gnc:*kvp-option-path*)
 
 (load-from-path "c-interface.scm")
 (load-from-path "config-var.scm")
 (load-from-path "options.scm")
-(load-from-path "kvp-option-registry.scm")
 (load-from-path "hooks.scm")
 (load-from-path "prefs.scm")
 (load-from-path "date-utilities.scm")

Modified: gnucash/branches/swig-redo/src/app-utils/kvp-option-registry.scm
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/kvp-option-registry.scm	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/app-utils/kvp-option-registry.scm	2006-10-10 00:03:22 UTC (rev 14971)
@@ -1,61 +1 @@
-;; Code for the kvp/option registry
-;;
-;; Copyright (C) 2002, Derek Atkins  <derek at ihtfp.com>
-;;
-;; 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
-
-
-(use-modules (ice-9 slib))
-(require 'hash)
-
-(define gnc:*kvp-option-path* '("options"))
-
-(define gnc:*kvp-option-registry* (make-hash-table 23))
-
-(define (get-ref id-type)
-  (let ((gen-list (hash-ref gnc:*kvp-option-registry* id-type)))
-    (if gen-list gen-list '())))
-
-
-;;
-;; the generator should be a procedure that takes one argument,
-;; an options object.  The procedure should fill in the options with
-;; its defined kvp options.
-;;
-(define (gnc:register-kvp-option-generator id-type generator)
-  (let ((gen-list (get-ref id-type)))
-    (hash-set! gnc:*kvp-option-registry*
-	       id-type (append gen-list (list generator)))))
-
-(define (gnc:unregister-kvp-option-generator id-type generator)
-  (let ((gen-list (get-ref id-type)))
-    (hash-set! gnc:*kvp-option-registry*
-	       id-type (delq! generator gen-list))))
-
-;;
-;; create a new options object for the requested type
-;;
-(define (gnc:make-kvp-options id-type)
-  (let ((gen-list (get-ref id-type))
-	(options (gnc:new-options)))
-    (map
-     (lambda (generator)
-       (generator options))
-     gen-list)
-
-    options))
+;; svn delete me
\ No newline at end of file

Modified: gnucash/branches/swig-redo/src/app-utils/option-util.c
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/option-util.c	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/app-utils/option-util.c	2006-10-10 00:03:22 UTC (rev 14971)
@@ -268,23 +268,12 @@
 
 /* Create an option DB for a particular data type */
 GNCOptionDB *
-gnc_option_db_new_for_type(SCM id_type)
+gnc_option_db_new_for_type(QofIdType id_type)
 {
-  static SCM make_option_proc = SCM_UNDEFINED;
   SCM options;
 
   if (!id_type) return NULL;
-
-  if (make_option_proc == SCM_UNDEFINED) {
-    make_option_proc = scm_c_eval_string("gnc:make-kvp-options");
-    if (!SCM_PROCEDUREP (make_option_proc)) {
-      PERR ("not a procedure\n");
-      make_option_proc = SCM_UNDEFINED;
-      return NULL;
-    }
-  }
-
-  options = scm_call_1 (make_option_proc, id_type);
+  options = gnc_make_kvp_options(id_type);
   return gnc_option_db_new (options);
 }
 
@@ -2812,3 +2801,50 @@
   return value;
 }
 
+/* For now, this is global, just like when it was in guile.
+   But, it should be make per-book. */
+static GHashTable *kvp_registry = NULL;
+
+static void
+init_table(void)
+{
+    if (!kvp_registry)
+        kvp_registry = g_hash_table_new(g_str_hash, g_str_equal);
+}
+
+/*
+ * the generator should be a procedure that takes one argument,
+ * an options object.  The procedure should fill in the options with
+ * its defined kvp options.
+ */
+void
+gnc_register_kvp_option_generator(QofIdType id_type, SCM generator)
+{
+    GList *list;
+    init_table();
+    list = g_hash_table_lookup(kvp_registry, id_type);
+    list = g_list_prepend(list, generator);
+    g_hash_table_insert(kvp_registry, (gpointer) id_type, list);
+    scm_gc_protect_object(generator);
+}
+
+
+/*  create a new options object for the requested type */
+SCM
+gnc_make_kvp_options(QofIdType id_type)
+{
+    GList *list, *p;
+    SCM gnc_new_options = SCM_UNDEFINED;
+    SCM options = SCM_UNDEFINED;
+
+    init_table();
+    list = g_hash_table_lookup(kvp_registry, id_type);
+    gnc_new_options = scm_c_eval_string("gnc:new-options");
+    options = scm_call_0(gnc_new_options);
+
+    for (p = list; p; p = p->next) {
+        SCM generator = p->data;
+        scm_call_1(generator, options);
+    }
+    return options;
+}

Modified: gnucash/branches/swig-redo/src/app-utils/option-util.h
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/option-util.h	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/app-utils/option-util.h	2006-10-10 00:03:22 UTC (rev 14971)
@@ -65,14 +65,14 @@
 /* Create an option DB for a particular type, and save/load from a kvp.
  * This assumes the gnc:*kvp-option-path* location for the options
  * in the kvp.
- *
- * Note: the id_type MUST be a reference to the actual SCM
- * gnc:id-type.  Just wrapping the type in scheme is *NOT* sufficient.
  */
-GNCOptionDB * gnc_option_db_new_for_type(SCM id_type);
+GNCOptionDB * gnc_option_db_new_for_type(QofIdType id_type);
 void gnc_option_db_load_from_kvp(GNCOptionDB* odb, kvp_frame *slots);
 void gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots);
 
+void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
+SCM gnc_make_kvp_options(QofIdType id_type);
+
 void gnc_option_db_set_ui_callbacks (GNCOptionDB *odb,
                                      GNCOptionGetUIValue get_ui_value,
                                      GNCOptionSetUIValue set_ui_value,

Modified: gnucash/branches/swig-redo/src/business/business-ledger/gncEntryLedgerLoad.c
===================================================================
--- gnucash/branches/swig-redo/src/business/business-ledger/gncEntryLedgerLoad.c	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/business/business-ledger/gncEntryLedgerLoad.c	2006-10-10 00:03:22 UTC (rev 14971)
@@ -276,8 +276,6 @@
  */
 void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
 {
-  static SCM id_book = SCM_UNDEFINED;
-
   GncEntry *blank_entry, *find_entry;
   CursorBuffer *cursor_buffer;
   Table *table;
@@ -359,11 +357,8 @@
 	  break;
 	}
 
-	if (id_book == SCM_UNDEFINED)
-	  id_book = scm_c_eval_string ("gnc:id-book");
-
 	/* Compute the proper taxtable */
-	odb = gnc_option_db_new_for_type (id_book);
+	odb = gnc_option_db_new_for_type (GNC_ID_BOOK);
 	gnc_option_db_load_from_kvp (odb, gnc_book_get_slots (ledger->book));
 
 	switch (gncOwnerGetType (owner)) {

Modified: gnucash/branches/swig-redo/src/business/business-utils/business-prefs.scm
===================================================================
--- gnucash/branches/swig-redo/src/business/business-utils/business-prefs.scm	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/business/business-utils/business-prefs.scm	2006-10-10 00:03:22 UTC (rev 14971)
@@ -83,4 +83,4 @@
     #f))
 )
 
-(gnc:register-kvp-option-generator gnc:id-book book-options-generator)
+(gnc-register-kvp-option-generator gnc:id-book book-options-generator)

Modified: gnucash/branches/swig-redo/src/gnome-utils/gnome-utils.scm
===================================================================
--- gnucash/branches/swig-redo/src/gnome-utils/gnome-utils.scm	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/gnome-utils/gnome-utils.scm	2006-10-10 00:03:22 UTC (rev 14971)
@@ -20,7 +20,7 @@
 (load-from-path "gnc-menu-extensions.scm")
 
 (define (gnc:kvp-option-dialog id-type slots title changed_cb)
-  (let* ((options (gnc:make-kvp-options id-type))
+  (let* ((options (gnc-make-kvp-options id-type))
 	 (optiondb (gnc-option-db-new options))
 	 (optionwin (gnc-options-dialog-new title)))
 

Modified: gnucash/branches/swig-redo/src/tax/us/txf-de_DE.scm
===================================================================
--- gnucash/branches/swig-redo/src/tax/us/txf-de_DE.scm	2006-10-10 00:02:20 UTC (rev 14970)
+++ gnucash/branches/swig-redo/src/tax/us/txf-de_DE.scm	2006-10-10 00:03:22 UTC (rev 14971)
@@ -129,4 +129,4 @@
     "a" (N_ "The electronic tax number of your business") ""))
   )
 
-(gnc:register-kvp-option-generator gnc:id-book book-options-generator)
+(gnc-register-kvp-option-generator gnc:id-book book-options-generator)



More information about the gnucash-changes mailing list