Merge branch 'kvp-cleanup'

Remove the KVP C API and consolidate use in a few files in libqof. For
almost all future use KVP should be accessed via
qof_instance_set/get_kvp() or qof_book_get/set_option(). These
interfaces will ensure that changes to KVP are immediately committed
unless they're called from inside a begin_edit/commit block to
consolidate a database transaction.

Some exceptional corner cases where direct access to KvpFrames are
abstracted into new objects in libqof. The KVP "bag" interface of
kvp-utils is removed and its single in Split.c made more direct with
qof_instance_kvp_foo_guid functions.

Account, Transaction, and Split use qof_instance_copy_kvp and
qof_instance_swap_kvp as part of their rollback facilities.

Resolves bugs 87652, 120250, 736139, and 736687.
This commit is contained in:
John Ralls 2015-07-04 17:00:53 -07:00
commit 56c3316379
172 changed files with 4919 additions and 8648 deletions

View File

@ -0,0 +1,41 @@
From b9de55c8711b07c0fdf83d9838c8a5d65222e887 Mon Sep 17 00:00:00 2001
From: John Ralls <jralls@ceridwen.us>
Date: Sun, 24 May 2015 18:05:04 -0700
Subject: [PATCH] Change gtkmacintegration-gtk2 include directory back to
gtkmacintegration.
As of gtk-mac-integration-2.0.8.
---
src/core-utils/binreloc.c | 2 +-
src/gnome-utils/gnc-main-window.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/core-utils/binreloc.c b/src/core-utils/binreloc.c
index 6a2a55f..4e72494 100644
--- a/src/core-utils/binreloc.c
+++ b/src/core-utils/binreloc.c
@@ -24,7 +24,7 @@
#include <sys/stat.h>
#include <unistd.h>
#ifdef MAC_INTEGRATION
-#include <gtkmacintegration-gtk2/gtkosxapplication.h>
+#include <gtkmacintegration/gtkosxapplication.h>
#endif
#endif /* ENABLE_BINRELOC */
#include <stdio.h>
diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c
index 89462ef..c77637d 100644
--- a/src/gnome-utils/gnc-main-window.c
+++ b/src/gnome-utils/gnc-main-window.c
@@ -70,7 +70,7 @@
#include "gnc-autosave.h"
#include "print-session.h"
#ifdef MAC_INTEGRATION
-#include <gtkmacintegration-gtk2/gtkosxapplication.h>
+#include <gtkmacintegration/gtkosxapplication.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/types.h>
--
2.2.2

View File

@ -58,7 +58,7 @@ src/backend/sql/gnc-owner-sql.c
src/backend/sql/gnc-price-sql.c src/backend/sql/gnc-price-sql.c
src/backend/sql/gnc-recurrence-sql.c src/backend/sql/gnc-recurrence-sql.c
src/backend/sql/gnc-schedxaction-sql.c src/backend/sql/gnc-schedxaction-sql.c
src/backend/sql/gnc-slots-sql.c src/backend/sql/gnc-slots-sql.cpp
src/backend/sql/gnc-tax-table-sql.c src/backend/sql/gnc-tax-table-sql.c
src/backend/sql/gnc-transaction-sql.c src/backend/sql/gnc-transaction-sql.c
src/backend/sql/gnc-vendor-sql.c src/backend/sql/gnc-vendor-sql.c
@ -87,12 +87,12 @@ src/backend/xml/gnc-vendor-xml-v2.c
src/backend/xml/gnc-xml-helper.c src/backend/xml/gnc-xml-helper.c
src/backend/xml/io-example-account.c src/backend/xml/io-example-account.c
src/backend/xml/io-gncxml-gen.c src/backend/xml/io-gncxml-gen.c
src/backend/xml/io-gncxml-v1.c src/backend/xml/io-gncxml-v1.cpp
src/backend/xml/io-gncxml-v2.c src/backend/xml/io-gncxml-v2.c
src/backend/xml/io-utils.c src/backend/xml/io-utils.c
src/backend/xml/sixtp.c src/backend/xml/sixtp.c
src/backend/xml/sixtp-dom-generators.c src/backend/xml/sixtp-dom-generators.cpp
src/backend/xml/sixtp-dom-parsers.c src/backend/xml/sixtp-dom-parsers.cpp
src/backend/xml/sixtp-stack.c src/backend/xml/sixtp-stack.c
src/backend/xml/sixtp-to-dom-parser.c src/backend/xml/sixtp-to-dom-parser.c
src/backend/xml/sixtp-utils.c src/backend/xml/sixtp-utils.c
@ -184,7 +184,7 @@ src/engine/gnc-pricedb.c
src/engine/gnc-session.c src/engine/gnc-session.c
src/engine/gncTaxTable.c src/engine/gncTaxTable.c
src/engine/gncVendor.c src/engine/gncVendor.c
src/engine/kvp-scm.c src/engine/kvp-scm.cpp
src/engine/policy.c src/engine/policy.c
src/engine/Query.c src/engine/Query.c
src/engine/Recurrence.c src/engine/Recurrence.c
@ -396,7 +396,6 @@ src/import-export/aqb/gnc-ab-getbalance.c
src/import-export/aqb/gnc-ab-gettrans.c src/import-export/aqb/gnc-ab-gettrans.c
src/import-export/aqb/gnc-ab-kvp.c src/import-export/aqb/gnc-ab-kvp.c
src/import-export/aqb/gnc-ab-transfer.c src/import-export/aqb/gnc-ab-transfer.c
src/import-export/aqb/gnc-ab-trans-templ.c
src/import-export/aqb/gnc-ab-utils.c src/import-export/aqb/gnc-ab-utils.c
src/import-export/aqb/gnc-file-aqb-import.c src/import-export/aqb/gnc-file-aqb-import.c
src/import-export/aqb/gnc-gwen-gui.c src/import-export/aqb/gnc-gwen-gui.c
@ -463,13 +462,13 @@ src/import-export/qif-imp/qif-objects.scm
src/import-export/qif-imp/qif-parse.scm src/import-export/qif-imp/qif-parse.scm
src/import-export/qif-imp/qif-to-gnc.scm src/import-export/qif-imp/qif-to-gnc.scm
src/import-export/qif-imp/qif-utils.scm src/import-export/qif-imp/qif-utils.scm
src/libqof/qof/gnc-aqbanking-templates.cpp
src/libqof/qof/gnc-date.cpp src/libqof/qof/gnc-date.cpp
src/libqof/qof/gnc-int128.cpp src/libqof/qof/gnc-int128.cpp
src/libqof/qof/gnc-numeric.cpp src/libqof/qof/gnc-numeric.cpp
src/libqof/qof/gnc-rational.cpp src/libqof/qof/gnc-rational.cpp
src/libqof/qof/guid.cpp src/libqof/qof/guid.cpp
src/libqof/qof/kvp_frame.cpp src/libqof/qof/kvp_frame.cpp
src/libqof/qof/kvp-util.cpp
src/libqof/qof/kvp-value.cpp src/libqof/qof/kvp-value.cpp
src/libqof/qof/qofbackend.cpp src/libqof/qof/qofbackend.cpp
src/libqof/qof/qofbook.cpp src/libqof/qof/qofbook.cpp

View File

@ -106,7 +106,6 @@ gnc_numeric gnc_convert_from_euro(const gnc_commodity * currency,
time64 gnc_accounting_period_fiscal_start(void); time64 gnc_accounting_period_fiscal_start(void);
time64 gnc_accounting_period_fiscal_end(void); time64 gnc_accounting_period_fiscal_end(void);
SCM gnc_make_kvp_options(QofIdType id_type);
void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator); void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
%typemap(in) GList * { %typemap(in) GList * {

View File

@ -146,6 +146,11 @@
(export gnc:send-options) (export gnc:send-options)
(export gnc:save-options) (export gnc:save-options)
(define (gnc:option-get-value category key)
;;Access an option directly
(qof-book-get-option (gnc-get-current-book)
(list category key)))
(export gnc:option-get-value)
;; config-var.scm ;; config-var.scm
(export gnc:make-config-var) (export gnc:make-config-var)
(export gnc:config-var-description-get) (export gnc:config-var-description-get)
@ -318,9 +323,7 @@
(define (gnc:company-info key) (define (gnc:company-info key)
;; Access company info from key-value pairs for current book ;; Access company info from key-value pairs for current book
(kvp-frame-get-slot-path-gslist (gnc:option-get-value gnc:*business-label* key))
(qof-book-get-slots (gnc-get-current-book))
(append gnc:*kvp-option-path* (list gnc:*business-label* key))))
(export gnc:*business-label* gnc:*company-name* gnc:*company-addy* (export gnc:*business-label* gnc:*company-name* gnc:*company-addy*
gnc:*company-id* gnc:*company-phone* gnc:*company-fax* gnc:*company-id* gnc:*company-phone* gnc:*company-fax*

View File

@ -33,7 +33,7 @@ GncTaxTable* gnc_business_get_default_tax_table (QofBook *book, GncOwnerType own
GNCOptionDB *odb; GNCOptionDB *odb;
odb = gnc_option_db_new_for_type (GNC_ID_BOOK); odb = gnc_option_db_new_for_type (GNC_ID_BOOK);
qof_book_load_options (book, gnc_option_db_load_from_kvp, odb); qof_book_load_options (book, gnc_option_db_load, odb);
switch (ownertype) switch (ownertype)
{ {

View File

@ -73,9 +73,9 @@
(gnc:error "Illegal invoice value set")))) (gnc:error "Illegal invoice value set"))))
(lambda () (convert-to-invoice (default-getter))) (lambda () (convert-to-invoice (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! option v) (set! option v)
@ -134,9 +134,9 @@
(gnc:error "Illegal customer value set")))) (gnc:error "Illegal customer value set"))))
(lambda () (convert-to-customer (default-getter))) (lambda () (convert-to-customer (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! option v) (set! option v)
@ -195,9 +195,9 @@
(gnc:error "Illegal vendor value set")))) (gnc:error "Illegal vendor value set"))))
(lambda () (convert-to-vendor (default-getter))) (lambda () (convert-to-vendor (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! option v) (set! option v)
@ -256,9 +256,9 @@
(gnc:error "Illegal employee value set")))) (gnc:error "Illegal employee value set"))))
(lambda () (convert-to-employee (default-getter))) (lambda () (convert-to-employee (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! option v) (set! option v)
@ -355,14 +355,14 @@
(gnc:error "Illegal owner value set")))) (gnc:error "Illegal owner value set"))))
(lambda () (convert-to-owner (default-getter))) (lambda () (convert-to-owner (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(kvp-frame-set-slot-path-gslist f (symbol->string (car option)) (qof-book-set-option b (symbol->string (car option))
(append p '("type"))) (append p '("type")))
(kvp-frame-set-slot-path-gslist f (cdr option) (qof-book-set-option b (cdr option)
(append p '("value")))) (append p '("value"))))
(lambda (f p) (lambda (b p)
(let ((t (kvp-frame-get-slot-path-gslist f (append p '("type")))) (let ((t (qof-book-get-option b (append p '("type"))))
(v (kvp-frame-get-slot-path-gslist f (append p '("value"))))) (v (qof-book-get-option b (append p '("value")))))
(if (and t v (string? t) (string? v)) (if (and t v (string? t) (string? v))
(begin (begin
(set! option (cons (string->symbol t) v)) (set! option (cons (string->symbol t) v))
@ -422,9 +422,9 @@
(gnc:error "Illegal taxtable value set")))) (gnc:error "Illegal taxtable value set"))))
(lambda () (convert-to-taxtable (default-getter))) (lambda () (convert-to-taxtable (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! option v) (set! option v)
@ -450,9 +450,9 @@
documentation-string documentation-string
default-value) default-value)
(let ((option (gnc:make-number-range-option section name sort-tag documentation-string default-value 0 999999999 0 1))) (let ((option (gnc:make-number-range-option section name sort-tag documentation-string default-value 0 999999999 0 1)))
(gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f (inexact->exact ((gnc:option-getter option))) (list "counters" key)))) (gnc:set-option-scm->kvp option (lambda (b p) (qof-book-set-option b (inexact->exact ((gnc:option-getter option))) (list "counters" key))))
(gnc:set-option-kvp->scm option (lambda (f p) (gnc:set-option-kvp->scm option (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f (list "counters" key)))) (let ((v (qof-book-get-option b (list "counters" key))))
(if (and v (integer? v)) (if (and v (integer? v))
((gnc:option-setter option) v))))) ((gnc:option-setter option) v)))))
option)) option))
@ -467,9 +467,9 @@
documentation-string documentation-string
default-value) default-value)
(let ((option (gnc:make-string-option section name sort-tag documentation-string default-value))) (let ((option (gnc:make-string-option section name sort-tag documentation-string default-value)))
(gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f ((gnc:option-getter option)) (list "counter_formats" key)))) (gnc:set-option-scm->kvp option (lambda (b p) (qof-book-set-option b ((gnc:option-getter option)) (list "counter_formats" key))))
(gnc:set-option-kvp->scm option (lambda (f p) (gnc:set-option-kvp->scm option (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f (list "counter_formats" key)))) (let ((v (qof-book-get-option b (list "counter_formats" key))))
(if (and v (string? v)) (if (and v (string? v))
((gnc:option-setter option) v))))) ((gnc:option-setter option) v)))))
option)) option))

View File

@ -101,7 +101,6 @@ static GDate *
get_fy_end(void) get_fy_end(void)
{ {
QofBook *book; QofBook *book;
KvpFrame *book_frame;
GDate *date = NULL; GDate *date = NULL;
book = gnc_get_current_book(); book = gnc_get_current_book();

View File

@ -1027,7 +1027,6 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data)
g_date_get_month(&creation_data->instance->date), g_date_get_month(&creation_data->instance->date),
g_date_get_year(&creation_data->instance->date)); g_date_get_year(&creation_data->instance->date));
/* the accounts and amounts are in the kvp_frames of the splits. */
template_splits = xaccTransGetSplitList(template_txn); template_splits = xaccTransGetSplitList(template_txn);
txn_splits = xaccTransGetSplitList(new_txn); txn_splits = xaccTransGetSplitList(new_txn);
if ((template_splits == NULL) || (txn_splits == NULL)) if ((template_splits == NULL) || (txn_splits == NULL))
@ -1555,9 +1554,6 @@ create_cashflow_helper(Transaction *template_txn, void *user_data)
xaccTransGetDescription(template_txn), xaccTransGetDescription(template_txn),
xaccSchedXactionGetName(creation_data->sx)); xaccSchedXactionGetName(creation_data->sx));
/* The accounts and amounts are in the kvp_frames of the
* splits. Hence, we iterate over all splits of this
* transaction. */
template_splits = xaccTransGetSplitList(template_txn); template_splits = xaccTransGetSplitList(template_txn);
if (template_splits == NULL) if (template_splits == NULL)

View File

@ -269,6 +269,39 @@ gnc_option_db_find (SCM guile_options)
} }
/* Create an option DB for a particular data type */ /* Create an option DB for a particular data type */
/* 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);
}
/* create a new options object for the requested type */
static 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;
}
GNCOptionDB * GNCOptionDB *
gnc_option_db_new_for_type(QofIdType id_type) gnc_option_db_new_for_type(QofIdType id_type)
{ {
@ -280,13 +313,12 @@ gnc_option_db_new_for_type(QofIdType id_type)
} }
void void
gnc_option_db_load_from_kvp(GNCOptionDB* odb, KvpFrame *slots) gnc_option_db_load(GNCOptionDB* odb, QofBook *book)
{ {
static SCM kvp_to_scm = SCM_UNDEFINED; static SCM kvp_to_scm = SCM_UNDEFINED;
static SCM kvp_option_path = SCM_UNDEFINED; SCM scm_book;
SCM scm_slots;
if (!odb || !slots) return; if (!odb || !book) return;
if (kvp_to_scm == SCM_UNDEFINED) if (kvp_to_scm == SCM_UNDEFINED)
{ {
@ -299,29 +331,19 @@ gnc_option_db_load_from_kvp(GNCOptionDB* odb, KvpFrame *slots)
} }
} }
if (kvp_option_path == SCM_UNDEFINED) scm_book = SWIG_NewPointerObj(book, SWIG_TypeQuery("_p_QofBook"), 0);
{
kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
if (kvp_option_path == SCM_UNDEFINED)
{
PERR ("can't find the option path");
return;
}
}
scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path); scm_call_2 (kvp_to_scm, odb->guile_options, scm_book);
} }
void void
gnc_option_db_save_to_kvp(GNCOptionDB* odb, KvpFrame *slots, gboolean clear_kvp) gnc_option_db_save(GNCOptionDB* odb, QofBook *book, gboolean clear_all)
{ {
static SCM scm_to_kvp = SCM_UNDEFINED; static SCM scm_to_kvp = SCM_UNDEFINED;
static SCM kvp_option_path = SCM_UNDEFINED; SCM scm_book;
SCM scm_slots; SCM scm_clear_all;
SCM scm_clear_kvp;
if (!odb || !slots) return; if (!odb || !book) return;
if (scm_to_kvp == SCM_UNDEFINED) if (scm_to_kvp == SCM_UNDEFINED)
{ {
@ -334,19 +356,10 @@ gnc_option_db_save_to_kvp(GNCOptionDB* odb, KvpFrame *slots, gboolean clear_kvp)
} }
} }
if (kvp_option_path == SCM_UNDEFINED) scm_book = SWIG_NewPointerObj(book, SWIG_TypeQuery("_p_QofBook"), 0);
{ scm_clear_all = scm_from_bool (clear_all);
kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
if (kvp_option_path == SCM_UNDEFINED)
{
PERR ("can't find the option path");
return;
}
}
scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
scm_clear_kvp = scm_from_bool (clear_kvp);
scm_call_4 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path, scm_clear_kvp); scm_call_3 (scm_to_kvp, odb->guile_options, scm_book, scm_clear_all);
} }
/********************************************************************\ /********************************************************************\
* gnc_option_db_destroy * * gnc_option_db_destroy *
@ -2928,17 +2941,6 @@ SCM gnc_dateformat_option_set_value(QofDateFormat format, GNCDateMonthFormat mon
return value; 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, * the generator should be a procedure that takes one argument,
* an options object. The procedure should fill in the options with * an options object. The procedure should fill in the options with
@ -2954,25 +2956,3 @@ gnc_register_kvp_option_generator(QofIdType id_type, SCM generator)
g_hash_table_insert(kvp_registry, (gpointer) id_type, list); g_hash_table_insert(kvp_registry, (gpointer) id_type, list);
scm_gc_protect_object(generator); 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;
}

View File

@ -71,11 +71,10 @@ void gnc_option_db_destroy(GNCOptionDB *odb);
* in the kvp. * in the kvp.
*/ */
GNCOptionDB * gnc_option_db_new_for_type(QofIdType id_type); GNCOptionDB * gnc_option_db_new_for_type(QofIdType id_type);
void gnc_option_db_load_from_kvp(GNCOptionDB* odb, KvpFrame *slots); void gnc_option_db_load(GNCOptionDB* odb, QofBook *book);
void gnc_option_db_save_to_kvp(GNCOptionDB* odb, KvpFrame *slots, gboolean clear_kvp); void gnc_option_db_save(GNCOptionDB* odb, QofBook *book, gboolean clear_all);
void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator); 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, void gnc_option_db_set_ui_callbacks (GNCOptionDB *odb,
GNCOptionGetUIValue get_ui_value, GNCOptionGetUIValue get_ui_value,

View File

@ -37,8 +37,8 @@
;; value. ;; value.
generate-restore-form generate-restore-form
;; the scm->kvp and kvp->scm functions should save and load ;; the scm->kvp and kvp->scm functions should save and load
;; the option to a kvp. The arguments to these function will be ;; the option to the book. The arguments to these function will be
;; a kvp-frame and a base key-path list for this option. ;; a book and a base key-path list for this option.
scm->kvp scm->kvp
kvp->scm kvp->scm
;; Validation func should accept a value and return (#t value) ;; Validation func should accept a value and return (#t value)
@ -211,9 +211,9 @@
(lambda (x) (set! value x)) (lambda (x) (set! value x))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p)) (lambda (b p) (qof-book-set-option b value p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value v)))) (set! value v))))
(lambda (x) (lambda (x)
@ -235,9 +235,9 @@
(lambda (x) (set! value x)) (lambda (x) (set! value x))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p)) (lambda (b p) (qof-book-set-option b value p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value v)))) (set! value v))))
(lambda (x) (lambda (x)
@ -269,9 +269,9 @@
(lambda (x) (set! value x)) (lambda (x) (set! value x))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p)) (lambda (b p) (qof-book-set-option b value p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value v)))) (set! value v))))
(lambda (x) (lambda (x)
@ -308,9 +308,9 @@
(lambda (x) (set! value (currency->scm x))) (lambda (x) (set! value (currency->scm x)))
(lambda () (scm->currency default-value)) (lambda () (scm->currency default-value))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p)) (lambda (b p) (qof-book-set-option b value p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value v)))) (set! value v))))
(lambda (x) (list #t x)) (lambda (x) (list #t x))
@ -369,14 +369,14 @@
" (gnc-get-current-book)))))")) " (gnc-get-current-book)))))"))
;; scm->kvp -- commit the change ;; scm->kvp -- commit the change
;; f -- kvp-frame; p -- key-path ;; b -- book; p -- key-path
(lambda (f p) (lambda (b p)
(kvp-frame-set-slot-path-gslist (qof-book-set-option
f (gncBudgetGetGUID selection-budget) p)) b (gncBudgetGetGUID selection-budget) p))
;; kvp->scm -- get the stored value ;; kvp->scm -- get the stored value
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(begin (begin
(set! selection-budget (gnc-budget-lookup v (gnc-get-current-book))))))) (set! selection-budget (gnc-budget-lookup v (gnc-get-current-book)))))))
@ -441,12 +441,12 @@
(set! value (commodity->scm x)))) (set! value (commodity->scm x))))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(kvp-frame-set-slot-path-gslist f (cadr value) (append p '("ns"))) (qof-book-set-option b (cadr value) (append p '("ns")))
(kvp-frame-set-slot-path-gslist f (caddr value) (append p '("monic")))) (qof-book-set-option b (caddr value) (append p '("monic"))))
(lambda (f p) (lambda (b p)
(let ((ns (kvp-frame-get-slot-path-gslist f (append p '("ns")))) (let ((ns (qof-book-get-option b (append p '("ns"))))
(monic (kvp-frame-get-slot-path-gslist f (append p '("monic"))))) (monic (qof-book-get-option b (append p '("monic")))))
(if (and ns monic (string? ns) (string? monic)) (if (and ns monic (string? ns) (string? monic))
(set! value (list 'commodity-scm ns monic))))) (set! value (list 'commodity-scm ns monic)))))
(lambda (x) (list #t x)) (lambda (x) (list #t x))
@ -500,14 +500,14 @@
(setter-function-called-cb x))) (setter-function-called-cb x)))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f (lambda (b p) (qof-book-set-option b
;; As no boolean KvpValue exists, as a workaround ;; As no boolean KvpValue exists, as a workaround
;; we store the string "t" for TRUE and "f" for ;; we store the string "t" for TRUE and "f" for
;; FALSE in a string KvpValue. ;; FALSE in a string KvpValue.
(if value "t" "f") (if value "t" "f")
p)) p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
;; As no boolean KvpValue exists, as a workaround we store ;; As no boolean KvpValue exists, as a workaround we store
;; the string "t" for TRUE and "f" for FALSE. ;; the string "t" for TRUE and "f" for FALSE.
(cond ((equal? v "t") (set! v #t)) (cond ((equal? v "t") (set! v #t))
@ -582,17 +582,17 @@
(gnc:error "Illegal date value set:" date))) (gnc:error "Illegal date value set:" date)))
default-getter default-getter
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(kvp-frame-set-slot-path-gslist f (symbol->string (car value)) (qof-book-set-option b (symbol->string (car value))
(append p '("type"))) (append p '("type")))
(kvp-frame-set-slot-path-gslist f (qof-book-set-option b
(if (symbol? (cdr value)) (if (symbol? (cdr value))
(symbol->string (cdr value)) (symbol->string (cdr value))
(cdr value)) (cdr value))
(append p '("value")))) (append p '("value"))))
(lambda (f p) (lambda (b p)
(let ((t (kvp-frame-get-slot-path-gslist f (append p '("type")))) (let ((t (qof-book-get-option b (append p '("type"))))
(v (kvp-frame-get-slot-path-gslist f (append p '("value"))))) (v (qof-book-get-option b (append p '("value")))))
(if (and t v (string? t)) (if (and t v (string? t))
(set! value (cons (string->symbol t) (set! value (cons (string->symbol t)
(if (string? v) (string->symbol v) v)))))) (if (string? v) (string->symbol v) v))))))
@ -720,25 +720,25 @@
(gnc:error "Illegal account list value set")))) (gnc:error "Illegal account list value set"))))
(lambda () (map convert-to-account (default-getter))) (lambda () (map convert-to-account (default-getter)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(define (save-acc list count) (define (save-acc list count)
(if (not (null? list)) (if (not (null? list))
(let ((key (string-append "acc" (gnc:value->string count)))) (let ((key (string-append "acc" (gnc:value->string count))))
(kvp-frame-set-slot-path-gslist f (car list) (append p (list key))) (qof-book-set-option b (car list) (append p (list key)))
(save-acc (cdr list) (+ 1 count))))) (save-acc (cdr list) (+ 1 count)))))
(if option-set (if option-set
(begin (begin
(kvp-frame-set-slot-path-gslist f (length option) (qof-book-set-option b (length option)
(append p '("len"))) (append p '("len")))
(save-acc option 0)))) (save-acc option 0))))
(lambda (f p) (lambda (b p)
(let ((len (kvp-frame-get-slot-path-gslist f (append p '("len"))))) (let ((len (qof-book-get-option b (append p '("len")))))
(define (load-acc count) (define (load-acc count)
(if (< count len) (if (< count len)
(let* ((key (string-append "acc" (gnc:value->string count))) (let* ((key (string-append "acc" (gnc:value->string count)))
(guid (kvp-frame-get-slot-path-gslist (guid (qof-book-get-option
f (append p (list key))))) b (append p (list key)))))
(cons guid (load-acc (+ count 1)))) (cons guid (load-acc (+ count 1))))
'())) '()))
@ -839,9 +839,9 @@
(gnc:error "Illegal account value set")))) (gnc:error "Illegal account value set"))))
(lambda () (convert-to-account (get-default))) (lambda () (convert-to-account (get-default)))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f option p)) (lambda (b p) (qof-book-set-option b option p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! option v)))) (set! option v))))
validator validator
@ -918,9 +918,9 @@
(gnc:error "Illegal Multichoice option set"))) (gnc:error "Illegal Multichoice option set")))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f (symbol->string value) p)) (lambda (b p) (qof-book-set-option b (symbol->string value) p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value (string->symbol v))))) (set! value (string->symbol v)))))
(lambda (x) (lambda (x)
@ -1004,9 +1004,9 @@
(gnc:error "Illegal Radiobutton option set"))) (gnc:error "Illegal Radiobutton option set")))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f (symbol->string value) p)) (lambda (b p) (qof-book-set-option b (symbol->string value) p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (string? v)) (if (and v (string? v))
(set! value (string->symbol v))))) (set! value (string->symbol v)))))
(lambda (x) (lambda (x)
@ -1066,21 +1066,21 @@
(gnc:error "Illegal list option set"))) (gnc:error "Illegal list option set")))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(define (save-item list count) (define (save-item list count)
(if (not (null? list)) (if (not (null? list))
(let ((key (string-append "item" (gnc:value->string count)))) (let ((key (string-append "item" (gnc:value->string count))))
(kvp-frame-set-slot-path-gslist f (car list) (append p (list key))) (qof-book-set-option b (car list) (append p (list key)))
(save-item (cdr list) (+ 1 count))))) (save-item (cdr list) (+ 1 count)))))
(kvp-frame-set-slot-path-gslist f (length value) (append p '("len"))) (qof-book-set-option b (length value) (append p '("len")))
(save-item value 0)) (save-item value 0))
(lambda (f p) (lambda (b p)
(let ((len (kvp-frame-get-slot-path-gslist f (append p '("len"))))) (let ((len (qof-book-get-option b (append p '("len")))))
(define (load-item count) (define (load-item count)
(if (< count len) (if (< count len)
(let* ((key (string-append "item" (gnc:value->string count))) (let* ((key (string-append "item" (gnc:value->string count)))
(val (kvp-frame-get-slot-path-gslist (val (qof-book-get-option
f (append p (list key))))) b (append p (list key)))))
(cons val (load-item (+ count 1)))) (cons val (load-item (+ count 1))))
'())) '()))
@ -1118,9 +1118,9 @@
(lambda (x) (set! value x)) (lambda (x) (set! value x))
(lambda () default-value) (lambda () default-value)
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p)) (lambda (b p) (qof-book-set-option b value p))
(lambda (f p) (lambda (b p)
(let ((v (kvp-frame-get-slot-path-gslist f p))) (let ((v (qof-book-get-option b p)))
(if (and v (number? v)) (if (and v (number? v))
(set! value v)))) (set! value v))))
(lambda (x) (lambda (x)
@ -1277,19 +1277,19 @@
(lambda (x) (set! value x)) (lambda (x) (set! value x))
(lambda () (def-value)) (lambda () (def-value))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (b p)
(qof-book-set-option
b (symbol->string (car value)) (append p '("fmt")))
(qof-book-set-option
b (symbol->string (cadr value)) (append p '("month")))
(qof-book-set-option
b (if (caddr value) 1 0) (append p '("years")))
(qof-book-set-option (cadddr value) (append p '("custom"))))
(lambda (f p) (lambda (f p)
(kvp-frame-set-slot-path-gslist (let ((fmt (qof-book-get-option f (append p '("fmt"))))
f (symbol->string (car value)) (append p '("fmt"))) (month (qof-book-get-option f (append p '("month"))))
(kvp-frame-set-slot-path-gslist (years (qof-book-get-option f (append p '("years"))))
f (symbol->string (cadr value)) (append p '("month"))) (custom (qof-book-get-option f (append p '("custom")))))
(kvp-frame-set-slot-path-gslist
f (if (caddr value) 1 0) (append p '("years")))
(kvp-frame-set-slot-path-gslist f (cadddr value) (append p '("custom"))))
(lambda (f p)
(let ((fmt (kvp-frame-get-slot-path-gslist f (append p '("fmt"))))
(month (kvp-frame-get-slot-path-gslist f (append p '("month"))))
(years (kvp-frame-get-slot-path-gslist f (append p '("years"))))
(custom (kvp-frame-get-slot-path-gslist f (append p '("custom")))))
(if (and (if (and
fmt (string? fmt) fmt (string? fmt)
month (string? month) month (string? month)
@ -1364,14 +1364,11 @@
(value->string (lambda () (value->string (lambda ()
(string-append "'" (gnc:value->string (string-append "'" (gnc:value->string
(car value))))) (car value)))))
(trading-accounts-path (list (car gnc:*kvp-option-path*) (trading-accounts-path (list gnc:*option-section-accounts*
gnc:*option-section-accounts*
gnc:*option-name-trading-accounts*)) gnc:*option-name-trading-accounts*))
(book-currency-path (list (car gnc:*kvp-option-path*) (book-currency-path (list gnc:*option-section-accounts*
gnc:*option-section-accounts*
gnc:*option-name-book-currency*)) gnc:*option-name-book-currency*))
(gains-policy-path (list (car gnc:*kvp-option-path*) (gains-policy-path (list gnc:*option-section-accounts*
gnc:*option-section-accounts*
gnc:*option-name-default-gains-policy*))) gnc:*option-name-default-gains-policy*)))
(gnc:make-option (gnc:make-option
section name sort-tag 'currency-accounting section name sort-tag 'currency-accounting
@ -1387,26 +1384,26 @@
(cons default-cap-gains-policy-value '()))) (cons default-cap-gains-policy-value '())))
(cons default-radiobutton-value '()))) (cons default-radiobutton-value '())))
(gnc:restore-form-generator value->string) (gnc:restore-form-generator value->string)
(lambda (f p) (lambda (b p)
(if (eq? 'book-currency (car value)) (if (eq? 'book-currency (car value))
(begin (begin
;; Currency = selected currency ;; Currency = selected currency
(kvp-frame-set-slot-path-gslist (qof-book-set-option
f b
(currency->scm (cadr value)) (currency->scm (cadr value))
book-currency-path) book-currency-path)
;; Default Gains Policy = selected policy ;; Default Gains Policy = selected policy
(kvp-frame-set-slot-path-gslist (qof-book-set-option
f b
(symbol->string (caddr value)) (symbol->string (caddr value))
gains-policy-path)) gains-policy-path))
(if (eq? 'trading (car value)) (if (eq? 'trading (car value))
;; Use Trading Accounts = "t" ;; Use Trading Accounts = "t"
(kvp-frame-set-slot-path-gslist f "t" trading-accounts-path)))) (qof-book-set-option b "t" trading-accounts-path))))
(lambda (f p) (lambda (b p)
(let* ((trading-option-path-kvp? (let* ((trading-option-path-kvp?
(kvp-frame-get-slot-path-gslist (qof-book-get-option
f trading-accounts-path)) b trading-accounts-path))
(trading? (if (and trading-option-path-kvp? (trading? (if (and trading-option-path-kvp?
(string=? "t" trading-option-path-kvp?)) (string=? "t" trading-option-path-kvp?))
#t #t
@ -1416,11 +1413,11 @@
(v (if trading? (v (if trading?
'trading 'trading
(let* ((book-currency-option-path-kvp? (let* ((book-currency-option-path-kvp?
(kvp-frame-get-slot-path-gslist (qof-book-get-option
f book-currency-path)) b book-currency-path))
(gains-policy-option-path-kvp? (gains-policy-option-path-kvp?
(kvp-frame-get-slot-path-gslist (qof-book-get-option
f gains-policy-path)) b gains-policy-path))
(book-currency? (book-currency?
(if (and book-currency-option-path-kvp? (if (and book-currency-option-path-kvp?
gains-policy-option-path-kvp? gains-policy-option-path-kvp?
@ -1650,7 +1647,7 @@
(call-with-output-string generate-forms)) (call-with-output-string generate-forms))
(define (scm->kvp kvp-frame key-path) (define (scm->kvp book)
(options-for-each (options-for-each
(lambda (option) (lambda (option)
(let ((value (gnc:option-value option)) (let ((value (gnc:option-value option))
@ -1663,18 +1660,16 @@
(let ((save-fcn (gnc:option-scm->kvp option))) (let ((save-fcn (gnc:option-scm->kvp option)))
(gnc:debug "save-fcn: " save-fcn) (gnc:debug "save-fcn: " save-fcn)
(if save-fcn (if save-fcn
(save-fcn kvp-frame (append key-path (save-fcn book (list section name)))))))))
(list section name))))))))))
(define (kvp->scm kvp-frame key-path) (define (kvp->scm book)
(options-for-each (options-for-each
(lambda (option) (lambda (option)
(let ((section (gnc:option-section option)) (let ((section (gnc:option-section option))
(name (gnc:option-name option)) (name (gnc:option-name option))
(load-fcn (gnc:option-kvp->scm option))) (load-fcn (gnc:option-kvp->scm option)))
(if load-fcn (if load-fcn
(load-fcn kvp-frame (append key-path (load-fcn book (list section name)))))))
(list section name))))))))
(define (register-callback section name callback) (define (register-callback section name callback)
(let ((id last-callback-id) (let ((id last-callback-id)
@ -1774,13 +1769,13 @@
(define (gnc:generate-restore-forms options options-string) (define (gnc:generate-restore-forms options options-string)
((options 'generate-restore-forms) options-string)) ((options 'generate-restore-forms) options-string))
(define (gnc:options-scm->kvp options kvp-frame key-path clear-kvp?) (define (gnc:options-scm->kvp options book clear-option?)
(if clear-kvp? (if clear-option?
(gnc-kvp-frame-delete-at-path kvp-frame key-path)) (qof-book-options-delete book))
((options 'scm->kvp) kvp-frame key-path)) ((options 'scm->kvp) book))
(define (gnc:options-kvp->scm options kvp-frame key-path) (define (gnc:options-kvp->scm options book)
((options 'kvp->scm) kvp-frame key-path)) ((options 'kvp->scm) book))
(define (gnc:options-clear-changes options) (define (gnc:options-clear-changes options)
((options 'clear-changes))) ((options 'clear-changes)))

View File

@ -8,6 +8,8 @@ check_PROGRAMS = \
test-sx \ test-sx \
test-app-utils test-app-utils
AM_DEFAULT_SOURCE_EXT = .cpp
TESTS = \ TESTS = \
test-load-module \ test-load-module \
${check_PROGRAMS} ${check_PROGRAMS}
@ -16,7 +18,7 @@ test_exp_parser_SOURCES = \
test-exp-parser.c test-exp-parser.c
test_print_parse_amount_SOURCES = \ test_print_parse_amount_SOURCES = \
test-print-parse-amount.c test-print-parse-amount.cpp
GNC_TEST_DEPS = --gnc-module-dir ${top_builddir}/src/engine \ GNC_TEST_DEPS = --gnc-module-dir ${top_builddir}/src/engine \
--gnc-module-dir ${top_builddir}/src/app-utils \ --gnc-module-dir ${top_builddir}/src/app-utils \
@ -67,11 +69,10 @@ AM_CPPFLAGS = \
test_app_utils_SOURCES = \ test_app_utils_SOURCES = \
test-app-utils.c \ test-app-utils.c \
test-option-util.c \ test-option-util.cpp \
test-gnc-ui-util.c test-gnc-ui-util.c
test_app_utils_CXXFLAGS = \
test_app_utils_CFLAGS = \
${DEFAULT_INCLUDES} \ ${DEFAULT_INCLUDES} \
-I${top_srcdir}/${MODULEPATH}/ \ -I${top_srcdir}/${MODULEPATH}/ \
-DTESTPROG=test_app_utils \ -DTESTPROG=test_app_utils \

View File

@ -1,5 +1,5 @@
/******************************************************************** /********************************************************************
* test-option-util.c: GLib g_test test suite for Split.c. * * test-option-util.cpp: GLib test suite for option-util.c. *
* Copyright 2013 John Ralls <jralls@ceridwen.us> * * Copyright 2013 John Ralls <jralls@ceridwen.us> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
@ -21,16 +21,19 @@
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org * * Boston, MA 02110-1301, USA gnu@gnu.org *
********************************************************************/ ********************************************************************/
#include <kvp_frame.hpp>
#include <gmp.h>
extern "C"
{
#include <config.h> #include <config.h>
#include <glib.h> #include <glib.h>
#include <unittest-support.h> #include <unittest-support.h>
#include <qofbookslots.h> #include <qofbookslots.h>
#include "../option-util.h" #include "../option-util.h"
}
static const gchar *suitename = "/app-utils/option-util"; static const gchar *suitename = "/app-utils/option-util";
void test_suite_option_util (void); extern "C" void test_suite_option_util (void);
typedef struct typedef struct
{ {
@ -41,7 +44,7 @@ typedef struct
/* Expose a mostly-private QofInstance function to load options into /* Expose a mostly-private QofInstance function to load options into
* the Book. * the Book.
*/ */
extern KvpFrame *qof_instance_get_slots (const QofInstance*); extern "C" KvpFrame *qof_instance_get_slots (const QofInstance*);
static void static void
setup (Fixture *fixture, gconstpointer pData) setup (Fixture *fixture, gconstpointer pData)
@ -65,8 +68,8 @@ setup_kvp (Fixture *fixture, gconstpointer pData)
"autoreadonly-days", (double)21, "autoreadonly-days", (double)21,
NULL); NULL);
kvp_frame_set_string (slots, "options/Business/Company Name", slots->set_path("options/Business/Company Name",
"Bogus Company"); new KvpValue("Bogus Company"));
qof_commit_edit (QOF_INSTANCE (book)); qof_commit_edit (QOF_INSTANCE (book));
} }
@ -93,14 +96,14 @@ teardown (Fixture *fixture, gconstpointer pData)
} }
static void static void
test_option_load_from_kvp (Fixture *fixture, gconstpointer pData) test_option_load (Fixture *fixture, gconstpointer pData)
{ {
gchar *str = NULL; gchar *str = NULL;
SCM symbol_value; SCM symbol_value;
QofBook *book = fixture->book; QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK); GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
qof_book_load_options (book, gnc_option_db_load_from_kvp, odb); qof_book_load_options (book, gnc_option_db_load, odb);
symbol_value = gnc_currency_accounting_option_value_get_method ( symbol_value = gnc_currency_accounting_option_value_get_method (
gnc_option_db_lookup_option (odb, gnc_option_db_lookup_option (odb,
OPTION_SECTION_ACCOUNTS, OPTION_SECTION_ACCOUNTS,
@ -127,7 +130,7 @@ test_option_load_from_kvp (Fixture *fixture, gconstpointer pData)
} }
static void static void
test_option_load_from_kvp_book_currency (Fixture *fixture, gconstpointer pData) test_option_load_book_currency (Fixture *fixture, gconstpointer pData)
{ {
gchar *str = NULL; gchar *str = NULL;
SCM symbol_value; SCM symbol_value;
@ -137,7 +140,7 @@ test_option_load_from_kvp_book_currency (Fixture *fixture, gconstpointer pData)
QofBook *book = fixture->book; QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK); GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
qof_book_load_options (book, gnc_option_db_load_from_kvp, odb); qof_book_load_options (book, gnc_option_db_load, odb);
symbol_value = gnc_currency_accounting_option_value_get_method ( symbol_value = gnc_currency_accounting_option_value_get_method (
gnc_option_db_lookup_option (odb, gnc_option_db_lookup_option (odb,
OPTION_SECTION_ACCOUNTS, OPTION_SECTION_ACCOUNTS,
@ -186,7 +189,7 @@ test_option_load_from_kvp_book_currency (Fixture *fixture, gconstpointer pData)
} }
static void static void
test_option_save_to_kvp (Fixture *fixture, gconstpointer pData) test_option_save (Fixture *fixture, gconstpointer pData)
{ {
QofBook *book = fixture->book; QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK); GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
@ -203,17 +206,17 @@ test_option_save_to_kvp (Fixture *fixture, gconstpointer pData)
g_assert (gnc_option_db_set_number_option (odb, OPTION_SECTION_ACCOUNTS, g_assert (gnc_option_db_set_number_option (odb, OPTION_SECTION_ACCOUNTS,
OPTION_NAME_AUTO_READONLY_DAYS, OPTION_NAME_AUTO_READONLY_DAYS,
17)); 17));
qof_book_save_options (book, gnc_option_db_save_to_kvp, odb, TRUE); qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Trading Accounts"), == , "t"); g_assert_cmpstr (slots->get_slot("options/Accounts/Use Trading Accounts")->get<const char*>(), == , "t");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Split Action Field for Number"), == , "t"); g_assert_cmpstr (slots->get_slot("options/Accounts/Use Split Action Field for Number")->get<const char*>(), == , "t");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Business/Company Name"), ==, "Bogus Company"); g_assert_cmpstr (slots->get_slot("options/Business/Company Name")->get<const char*>(), ==, "Bogus Company");
g_assert_cmpfloat (kvp_frame_get_double (slots, "options/Accounts/Day Threshold for Read-Only Transactions (red line)"), ==, 17); g_assert_cmpfloat (slots->get_slot("options/Accounts/Day Threshold for Read-Only Transactions (red line)")->get<double>(), ==, 17);
gnc_option_db_destroy (odb); gnc_option_db_destroy (odb);
} }
static void static void
test_option_save_to_kvp_book_currency (Fixture *fixture, gconstpointer pData) test_option_save_book_currency (Fixture *fixture, gconstpointer pData)
{ {
QofBook *book = fixture->book; QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK); GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
@ -224,19 +227,18 @@ test_option_save_to_kvp_book_currency (Fixture *fixture, gconstpointer pData)
scm_cons (scm_from_locale_symbol("book-currency"), scm_cons (scm_from_locale_symbol("book-currency"),
scm_cons (scm_from_utf8_string("GTQ"), scm_cons (scm_from_utf8_string("GTQ"),
scm_cons (scm_from_locale_symbol("fifo"), SCM_EOL))))); scm_cons (scm_from_locale_symbol("fifo"), SCM_EOL)))));
qof_book_save_options (book, gnc_option_db_save_to_kvp, odb, TRUE); qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Book Currency"), == , "GTQ"); g_assert_cmpstr (slots->get_slot("options/Accounts/Book Currency")->get<const char*>(), == , "GTQ");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Default Gains Policy"), == , "fifo"); g_assert_cmpstr (slots->get_slot("options/Accounts/Default Gains Policy")->get<const char*>(), == , "fifo");
gnc_option_db_destroy (odb); gnc_option_db_destroy (odb);
} }
void extern "C" void
test_suite_option_util (void) test_suite_option_util (void)
{ {
GNC_TEST_ADD (suitename, "Option DB Load from KVP", Fixture, NULL, setup_kvp, test_option_load_from_kvp, teardown); GNC_TEST_ADD (suitename, "Option DB Load", Fixture, NULL, setup_kvp, test_option_load, teardown);
GNC_TEST_ADD (suitename, "Option DB Load from KVP - Book Currency", Fixture, NULL, setup_kvp_book_currency, test_option_load_from_kvp_book_currency, teardown); GNC_TEST_ADD (suitename, "Option DB Load - Book Currency", Fixture, NULL, setup_kvp_book_currency, test_option_load_book_currency, teardown);
GNC_TEST_ADD (suitename, "Option DB Save to KVP", Fixture, NULL, setup, test_option_save_to_kvp, teardown); GNC_TEST_ADD (suitename, "Option DB Save", Fixture, NULL, setup, test_option_save, teardown);
GNC_TEST_ADD (suitename, "Option DB Save to KVP - Book Currency", Fixture, NULL, setup, test_option_save_to_kvp_book_currency, teardown); GNC_TEST_ADD (suitename, "Option DB Save - Book Currency", Fixture, NULL, setup, test_option_save_book_currency, teardown);
} }

View File

@ -1,3 +1,5 @@
extern "C"
{
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdlib.h> #include <stdlib.h>
@ -8,6 +10,7 @@
#include "test-engine-stuff.h" #include "test-engine-stuff.h"
#include "test-stuff.h" #include "test-stuff.h"
#include <unittest-support.h> #include <unittest-support.h>
}
static void static void
test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line) test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
@ -16,13 +19,13 @@ test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
const char *s; const char *s;
gboolean ok, print_ok; gboolean ok, print_ok;
gchar *msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW."; auto msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW.";
gchar *log_domain = "gnc.gui"; auto log_domain = "gnc.gui";
guint loglevel = G_LOG_LEVEL_WARNING, hdlr; auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING);
TestErrorStruct check = { loglevel, log_domain, msg }; auto check = test_error_struct_new (log_domain, loglevel, msg);
/* Throws overflows during rounding step in xaccPrintAmount when the "fraction" is high. See bug 665707. */ /* Throws overflows during rounding step in xaccPrintAmount when the "fraction" is high. See bug 665707. */
hdlr = g_log_set_handler (log_domain, loglevel, auto hdlr = g_log_set_handler (log_domain, loglevel,
(GLogFunc)test_checked_handler, &check); (GLogFunc)test_checked_handler, &check);
s = xaccPrintAmount (n, print_info); s = xaccPrintAmount (n, print_info);
print_ok = (s && s[0] != '\0'); print_ok = (s && s[0] != '\0');
@ -41,6 +44,7 @@ test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
"start: %s, string %s, finish: %s (line %d)", "start: %s, string %s, finish: %s (line %d)",
gnc_numeric_to_string (n), s, gnc_numeric_to_string (n), s,
gnc_numeric_to_string (n_parsed), line); gnc_numeric_to_string (n_parsed), line);
test_error_struct_free (check);
} }

View File

@ -96,9 +96,6 @@ main_helper (void *closure, int argc, char **argv)
xaccLogDisable (); xaccLogDisable ();
/* double->string->double is not idempotent */
kvp_exclude_type (KVP_TYPE_DOUBLE);
/* Initialize to a known RNG position */ /* Initialize to a known RNG position */
srand(1); srand(1);

View File

@ -1763,8 +1763,6 @@ init_sql_backend( GncDbiBackend* dbi_be )
* configured for multiuser access. */ * configured for multiuser access. */
be->sync = gnc_dbi_safe_sync_all; be->sync = gnc_dbi_safe_sync_all;
be->safe_sync = gnc_dbi_safe_sync_all; be->safe_sync = gnc_dbi_safe_sync_all;
be->load_config = NULL;
be->get_config = NULL;
be->compile_query = gnc_sql_compile_query; be->compile_query = gnc_sql_compile_query;
be->run_query = gnc_sql_run_query; be->run_query = gnc_sql_run_query;

View File

@ -58,8 +58,8 @@ endif
test_backend_dbi_SOURCES = \ test_backend_dbi_SOURCES = \
test-backend-dbi.c \ test-backend-dbi.c \
test-backend-dbi-basic.c \ test-backend-dbi-basic.cpp \
test-dbi-stuff.c \ test-dbi-stuff.cpp \
test-dbi-business-stuff.c test-dbi-business-stuff.c
test_backend_dbi_LDFLAGS="-ldbi" test_backend_dbi_LDFLAGS="-ldbi"

View File

@ -4,7 +4,10 @@
* Created on: 2011-04-23 * Created on: 2011-04-23
* Author: phil * Author: phil
*/ */
#include <kvp_frame.hpp>
extern "C"
{
#include "config.h" #include "config.h"
#include <sys/types.h> #include <sys/types.h>
@ -33,6 +36,7 @@
/* For version_control */ /* For version_control */
#include <gnc-prefs.h> #include <gnc-prefs.h>
#include <qofsession-p.h> #include <qofsession-p.h>
}
#if LIBDBI_VERSION >= 900 #if LIBDBI_VERSION >= 900
#define HAVE_LIBDBI_R 1 #define HAVE_LIBDBI_R 1
@ -42,7 +46,7 @@ static dbi_inst dbi_instance = NULL;
#endif #endif
static const gchar* suitename = "/backend/dbi"; static const gchar* suitename = "/backend/dbi";
void test_suite_gnc_backend_dbi (void); extern "C" void test_suite_gnc_backend_dbi (void);
typedef struct typedef struct
{ {
@ -79,7 +83,6 @@ setup_memory (Fixture *fixture, gconstpointer pData)
gchar *url = (gchar*)pData; gchar *url = (gchar*)pData;
QofBook* book; QofBook* book;
Account *root, *acct1, *acct2; Account *root, *acct1, *acct2;
KvpFrame* frame;
Transaction* tx; Transaction* tx;
Split *spl1, *spl2; Split *spl1, *spl2;
gnc_commodity_table* table; gnc_commodity_table* table;
@ -97,15 +100,16 @@ setup_memory (Fixture *fixture, gconstpointer pData)
xaccAccountSetName (acct1, "Bank 1"); xaccAccountSetName (acct1, "Bank 1");
xaccAccountSetCommodity (acct1, currency); xaccAccountSetCommodity (acct1, currency);
frame = qof_instance_get_slots (QOF_INSTANCE(acct1)); auto frame = qof_instance_get_slots (QOF_INSTANCE(acct1));
kvp_frame_set_gint64 (frame, "int64-val", 100); frame->set("int64-val", new KvpValue(INT64_C(100)));
kvp_frame_set_double (frame, "double-val", 3.14159); frame->set("double-val", new KvpValue(3.14159));
kvp_frame_set_numeric (frame, "numeric-val", gnc_numeric_zero()); frame->set("numeric-val", new KvpValue(gnc_numeric_zero()));
kvp_frame_set_timespec (frame, "timespec-val", timespec_now ()); frame->set("timespec-val", new KvpValue(timespec_now ()));
kvp_frame_set_string (frame, "string-val", "abcdefghijklmnop"); frame->set("string-val", new KvpValue("abcdefghijklmnop"));
kvp_frame_set_guid (frame, "guid-val", qof_instance_get_guid (QOF_INSTANCE(acct1))); auto guid = qof_instance_get_guid (QOF_INSTANCE(acct1));
frame->set("guid-val", new KvpValue(const_cast<GncGUID*>(guid)));
gnc_account_append_child (root, acct1); gnc_account_append_child (root, acct1);
@ -227,9 +231,9 @@ destroy_database (gchar* url)
gchar *basename = NULL; gchar *basename = NULL;
gint portnum = 0; gint portnum = 0;
gchar *port = NULL; gchar *port = NULL;
gchar *pgsql = "pgsql"; auto pgsql = "pgsql";
dbi_conn conn = NULL; dbi_conn conn = NULL;
gchar *errfmt = "Unable to delete tables in %s: %s"; auto errfmt = "Unable to delete tables in %s: %s";
gint fail = 0; gint fail = 0;
dbi_result tables; dbi_result tables;
GSList *list = NULL; GSList *list = NULL;
@ -295,11 +299,11 @@ destroy_database (gchar* url)
static void static void
teardown (Fixture *fixture, gconstpointer pData) teardown (Fixture *fixture, gconstpointer pData)
{ {
gchar *lockfile = g_strdup_printf ("%s/test-dbi.xml.LCK", auto lockfile = g_strdup_printf ("%s/test-dbi.xml.LCK",
g_path_get_dirname (DBI_TEST_XML_FILENAME)); g_path_get_dirname (DBI_TEST_XML_FILENAME));
gchar *msg = g_strdup_printf ("[xml_session_end()] Error on g_unlink(%s): 2: No such file or directory", lockfile); auto msg = g_strdup_printf ("[xml_session_end()] Error on g_unlink(%s): 2: No such file or directory", lockfile);
gchar *logdomain = "gnc.backend"; auto logdomain = "gnc.backend";
guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL);
TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg); TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg);
fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
(GLogFunc)test_checked_handler); (GLogFunc)test_checked_handler);
@ -334,7 +338,8 @@ test_conn_index_functions (QofBackend *qbe)
for (iter = index_list; iter != NULL; iter = g_slist_next (iter)) for (iter = index_list; iter != NULL; iter = g_slist_next (iter))
{ {
const char *errmsg; const char *errmsg;
conn->provider->drop_index (be->conn, iter->data); conn->provider->drop_index (be->conn,
static_cast<const char*>(iter->data));
g_assert (DBI_ERROR_NONE == dbi_conn_error (conn->conn, &errmsg)); g_assert (DBI_ERROR_NONE == dbi_conn_error (conn->conn, &errmsg));
} }
@ -353,9 +358,9 @@ test_dbi_store_and_reload (Fixture *fixture, gconstpointer pData)
QofSession* session_3; QofSession* session_3;
QofBackend *be; QofBackend *be;
gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
gchar *log_domain = "gnc.backend.dbi"; auto log_domain = "gnc.backend.dbi";
guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL);
TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg);
fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
(GLogFunc)test_checked_handler); (GLogFunc)test_checked_handler);
@ -401,13 +406,13 @@ test_dbi_store_and_reload (Fixture *fixture, gconstpointer pData)
static void static void
test_dbi_safe_save (Fixture *fixture, gconstpointer pData) test_dbi_safe_save (Fixture *fixture, gconstpointer pData)
{ {
gchar *url = (gchar*)pData; auto url = (gchar*)pData;
QofSession *session_1 = NULL, *session_2 = NULL; QofSession *session_1 = NULL, *session_2 = NULL;
QofBackend *be; QofBackend *be;
gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
gchar *log_domain = "gnc.backend.dbi"; auto log_domain = "gnc.backend.dbi";
guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL);
TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg);
if (fixture->filename) if (fixture->filename)
@ -478,7 +483,7 @@ cleanup:
static void static void
test_dbi_version_control (Fixture *fixture, gconstpointer pData) test_dbi_version_control (Fixture *fixture, gconstpointer pData)
{ {
gchar *url = (gchar*)pData; auto url = (gchar*)pData;
QofSession *sess; QofSession *sess;
QofBook *book; QofBook *book;
QofBackend *qbe; QofBackend *qbe;
@ -547,9 +552,9 @@ test_dbi_business_store_and_reload (Fixture *fixture, gconstpointer pData)
QofSession* session_3; QofSession* session_3;
const gchar* url = (gchar*)pData; const gchar* url = (gchar*)pData;
gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
gchar *log_domain = "gnc.backend.dbi"; auto log_domain = "gnc.backend.dbi";
guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL);
TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg);
if (fixture->filename) if (fixture->filename)
url = fixture->filename; url = fixture->filename;
@ -576,9 +581,9 @@ test_dbi_business_store_and_reload (Fixture *fixture, gconstpointer pData)
} }
static void static void
create_dbi_test_suite (gchar *dbm_name, gchar *url) create_dbi_test_suite (const char *dbm_name, const char *url)
{ {
gchar *subsuite = g_strdup_printf ("%s/%s", suitename, dbm_name); auto subsuite = g_strdup_printf ("%s/%s", suitename, dbm_name);
GNC_TEST_ADD (subsuite, "store_and_reload", Fixture, url, setup, GNC_TEST_ADD (subsuite, "store_and_reload", Fixture, url, setup,
test_dbi_store_and_reload, teardown); test_dbi_store_and_reload, teardown);
GNC_TEST_ADD (subsuite, "safe_save", Fixture, url, setup_memory, GNC_TEST_ADD (subsuite, "safe_save", Fixture, url, setup_memory,
@ -591,7 +596,7 @@ create_dbi_test_suite (gchar *dbm_name, gchar *url)
} }
void extern "C" void
test_suite_gnc_backend_dbi (void) test_suite_gnc_backend_dbi (void)
{ {
dbi_driver driver = NULL; dbi_driver driver = NULL;

View File

@ -22,21 +22,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA. * 02110-1301, USA.
*/ */
extern "C"
#include "config.h" {
#include "qof.h" #include <config.h>
#include "qofsession-p.h" #include <qof.h>
#include "cashobjects.h" #include <qofsession-p.h>
#include "test-dbi-stuff.h" #include <cashobjects.h>
#include <test-dbi-stuff.h>
#include <unittest-support.h> #include <unittest-support.h>
#include "Account.h" #include <Account.h>
#include "Split.h" #include <Split.h>
#include "Transaction.h" #include <Transaction.h>
#include "gnc-commodity.h" #include <gnc-commodity.h>
#include <SX-book.h> #include <SX-book.h>
#include <gnc-lot.h> #include <gnc-lot.h>
#include "../gnc-backend-dbi-priv.h" #include "../gnc-backend-dbi-priv.h"
}
#include <kvp_frame.hpp>
G_GNUC_UNUSED static QofLogModule log_module = "test-dbi"; G_GNUC_UNUSED static QofLogModule log_module = "test-dbi";
@ -97,7 +101,7 @@ get_sx_by_guid (QofBook* book, const GncGUID *guid)
const GncGUID *sx_guid; const GncGUID *sx_guid;
sx_guid = qof_instance_get_guid (QOF_INSTANCE(sxitem->data)); sx_guid = qof_instance_get_guid (QOF_INSTANCE(sxitem->data));
if (guid_equal (sx_guid, guid)) if (guid_equal (sx_guid, guid))
return sxitem->data; return static_cast<SchedXaction*>(sxitem->data);
} }
return NULL; return NULL;
} }
@ -126,7 +130,8 @@ compare_recurrences (GList *rl_1, GList *rl_2)
for (ritem1 = rl_1, ritem2 = rl_2; ritem1 != NULL && ritem2 != NULL; for (ritem1 = rl_1, ritem2 = rl_2; ritem1 != NULL && ritem2 != NULL;
ritem1 = g_list_next (ritem1), ritem2 = g_list_next (ritem2)) ritem1 = g_list_next (ritem1), ritem2 = g_list_next (ritem2))
{ {
Recurrence *r1 = ritem1->data, *r2 = ritem2->data; auto r1 = static_cast<Recurrence*>(ritem1->data);
auto r2 = static_cast<Recurrence*>(ritem2->data);
TEST_GDATES_EQUAL (&r1->start, &r2->start); TEST_GDATES_EQUAL (&r1->start, &r2->start);
g_assert_cmpint (r1->ptype, ==, r2->ptype); g_assert_cmpint (r1->ptype, ==, r2->ptype);
@ -184,8 +189,8 @@ compare_single_lot( QofInstance* inst, gpointer user_data )
gnc_lot_get_account (lot_2), FALSE )); gnc_lot_get_account (lot_2), FALSE ));
g_assert_cmpint (gnc_lot_is_closed (lot_1), ==, gnc_lot_is_closed (lot_2)); g_assert_cmpint (gnc_lot_is_closed (lot_1), ==, gnc_lot_is_closed (lot_2));
g_assert (kvp_frame_compare (qof_instance_get_slots (QOF_INSTANCE (lot_1)), g_assert (compare (qof_instance_get_slots (QOF_INSTANCE (lot_1)),
qof_instance_get_slots (QOF_INSTANCE (lot_2))) == 0); qof_instance_get_slots (QOF_INSTANCE (lot_2))) == 0);
splits1 = gnc_lot_get_split_list (lot_1); splits1 = gnc_lot_get_split_list (lot_1);
splits2 = gnc_lot_get_split_list (lot_2); splits2 = gnc_lot_get_split_list (lot_2);
g_assert_cmpint (g_list_length (splits1), ==, g_list_length (splits2)); g_assert_cmpint (g_list_length (splits1), ==, g_list_length (splits2));
@ -196,7 +201,8 @@ compare_single_lot( QofInstance* inst, gpointer user_data )
split2 = xaccSplitLookup (qof_instance_get_guid (split1->data), split2 = xaccSplitLookup (qof_instance_get_guid (split1->data),
info->book_2); info->book_2);
g_assert (GNC_IS_SPLIT (split2)); g_assert (GNC_IS_SPLIT (split2));
g_assert (xaccSplitEqual (split1->data, split2, TRUE, TRUE, TRUE)); g_assert (xaccSplitEqual (static_cast<Split*>(split1->data),
split2, TRUE, TRUE, TRUE));
} }
} }
@ -220,7 +226,8 @@ test_conn_index_functions( QofBackend *qbe )
for ( iter = index_list; iter != NULL; iter = g_slist_next( iter) ) for ( iter = index_list; iter != NULL; iter = g_slist_next( iter) )
{ {
const char *errmsg; const char *errmsg;
conn->provider->drop_index (be->conn, iter->data); conn->provider->drop_index (be->conn,
static_cast<const char*>(iter->data));
g_assert (DBI_ERROR_NONE == dbi_conn_error( conn->conn, &errmsg)); g_assert (DBI_ERROR_NONE == dbi_conn_error( conn->conn, &errmsg));
} }

View File

@ -25,7 +25,10 @@
#ifndef _TEST_DBI_STUFF_H_ #ifndef _TEST_DBI_STUFF_H_
#define _TEST_DBI_STUFF_H_ #define _TEST_DBI_STUFF_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include "qof.h" #include "qof.h"
typedef struct typedef struct
@ -37,5 +40,7 @@ typedef struct
void compare_books( QofBook* book_1, QofBook* book_2 ); void compare_books( QofBook* book_1, QofBook* book_2 );
void do_compare( QofBook* book_1, QofBook* book_2, const gchar* id, QofInstanceForeachCB cb, const gchar* msg ); void do_compare( QofBook* book_1, QofBook* book_2, const gchar* id, QofInstanceForeachCB cb, const gchar* msg );
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -34,7 +34,7 @@ SET (libgnc_backend_sql_SOURCES
gnc-price-sql.c gnc-price-sql.c
gnc-recurrence-sql.c gnc-recurrence-sql.c
gnc-schedxaction-sql.c gnc-schedxaction-sql.c
gnc-slots-sql.c gnc-slots-sql.cpp
gnc-tax-table-sql.c gnc-tax-table-sql.c
gnc-transaction-sql.c gnc-transaction-sql.c
gnc-vendor-sql.c gnc-vendor-sql.c

View File

@ -38,7 +38,7 @@ libgnc_backend_sql_la_SOURCES = \
gnc-price-sql.c \ gnc-price-sql.c \
gnc-recurrence-sql.c \ gnc-recurrence-sql.c \
gnc-schedxaction-sql.c \ gnc-schedxaction-sql.c \
gnc-slots-sql.c \ gnc-slots-sql.cpp \
gnc-tax-table-sql.c \ gnc-tax-table-sql.c \
gnc-transaction-sql.c \ gnc-transaction-sql.c \
gnc-vendor-sql.c \ gnc-vendor-sql.c \

View File

@ -383,7 +383,7 @@ gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -34,17 +34,17 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include "qof.h" #include <qof.h>
#include "qofquery-p.h" #include <qofquery-p.h>
#include "qofquerycore-p.h" #include <qofquerycore-p.h>
#include "Account.h" #include <Account.h>
#include "TransLog.h" #include <TransLog.h>
#include "gnc-engine.h" #include <gnc-engine.h>
#include "SX-book.h" #include <SX-book.h>
#include "Recurrence.h" #include <Recurrence.h>
#include "gncBillTerm.h" #include <gncBillTerm.h>
#include "gncTaxTable.h" #include <gncTaxTable.h>
#include "gncInvoice.h" #include <gncInvoice.h>
#include "gnc-backend-sql.h" #include "gnc-backend-sql.h"
@ -3072,7 +3072,7 @@ gnc_sql_commit_standard_item( GncSqlBackend* be, QofInstance* inst, const gchar*
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -430,7 +430,7 @@ save_budget( GncSqlBackend* be, QofInstance* inst )
} }
if ( is_ok ) if ( is_ok )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
} }
else else

View File

@ -213,7 +213,7 @@ do_commit_commodity( GncSqlBackend* be, QofInstance* inst, gboolean force_insert
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -198,7 +198,7 @@ save_employee( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -221,7 +221,7 @@ save_invoice( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -206,7 +206,7 @@ gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
// Now, commit any slots // Now, commit any slots
if ( op == OP_DB_INSERT || op == OP_DB_UPDATE ) if ( op == OP_DB_INSERT || op == OP_DB_UPDATE )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -25,14 +25,14 @@
* This file implements the top-level QofBackend API for saving/ * This file implements the top-level QofBackend API for saving/
* restoring data to/from an SQL db * restoring data to/from an SQL db
*/ */
extern "C"
{
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include "qof.h" #include <qof.h>
#include "gnc-engine.h" #include <gnc-engine.h>
#include "gnc-backend-sql.h" #include "gnc-backend-sql.h"
#include "gnc-slots-sql.h" #include "gnc-slots-sql.h"
@ -40,6 +40,9 @@
#ifdef S_SPLINT_S #ifdef S_SPLINT_S
#include "splint-defs.h" #include "splint-defs.h"
#endif #endif
}
#include <kvp_frame.hpp>
/*@ unused @*/ static QofLogModule log_module = G_LOG_DOMAIN; /*@ unused @*/ static QofLogModule log_module = G_LOG_DOMAIN;
@ -61,7 +64,7 @@ typedef struct
gboolean is_ok; gboolean is_ok;
/*@ dependent @*/ /*@ dependent @*/
KvpFrame* pKvpFrame; KvpFrame* pKvpFrame;
KvpValueType value_type; KvpValue::Type value_type;
GList *pList; GList *pList;
context_t context; context_t context;
/*@ dependent @*/ /*@ dependent @*/
@ -74,7 +77,7 @@ static /*@ null @*/ gpointer get_obj_guid( gpointer pObject );
static void set_obj_guid( void ); static void set_obj_guid( void );
static /*@ null @*/ gpointer get_path( gpointer pObject ); static /*@ null @*/ gpointer get_path( gpointer pObject );
static void set_path( gpointer pObject, /*@ null @*/ gpointer pValue ); static void set_path( gpointer pObject, /*@ null @*/ gpointer pValue );
static KvpValueType get_slot_type( gpointer pObject ); static KvpValue::Type get_slot_type( gpointer pObject );
static void set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue ); static void set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue );
static gint64 get_int64_val( gpointer pObject ); static gint64 get_int64_val( gpointer pObject );
static void set_int64_val( gpointer pObject, gint64 pValue ); static void set_int64_val( gpointer pObject, gint64 pValue );
@ -250,7 +253,7 @@ set_slot_from_value( slot_info_t *pInfo, KvpValue *pValue)
case FRAME: case FRAME:
{ {
gchar *key = get_key_from_path( pInfo->path ); gchar *key = get_key_from_path( pInfo->path );
kvp_frame_set_value_nc( pInfo->pKvpFrame, key, pValue ); pInfo->pKvpFrame->set(key, pValue);
g_free( key ); g_free( key );
break; break;
} }
@ -264,13 +267,14 @@ set_slot_from_value( slot_info_t *pInfo, KvpValue *pValue)
{ {
gchar *key = get_key_from_path( pInfo->path ); gchar *key = get_key_from_path( pInfo->path );
gchar *path = get_path_from_path( pInfo->path ); gchar *path = get_path_from_path( pInfo->path );
KvpFrame* frame = pInfo->pKvpFrame; auto frame = pInfo->pKvpFrame;
if ( path ) if ( path )
{ {
frame = kvp_frame_get_frame_slash( frame, path ); frame->set_path({path, key}, pValue);
g_free( path ); g_free( path );
} }
kvp_frame_set_value_nc( frame, key, pValue ); else
frame->set(key, pValue);
g_free( key ); g_free( key );
break; break;
} }
@ -318,12 +322,12 @@ set_path( gpointer pObject, /*@ null @*/ gpointer pValue )
pInfo->path = g_string_new( (gchar*)pValue ); pInfo->path = g_string_new( (gchar*)pValue );
} }
static KvpValueType static KvpValue::Type
get_slot_type( gpointer pObject ) get_slot_type( gpointer pObject )
{ {
slot_info_t* pInfo = (slot_info_t*)pObject; slot_info_t* pInfo = (slot_info_t*)pObject;
g_return_val_if_fail( pObject != NULL, 0 ); g_return_val_if_fail( pObject != NULL, KvpValue::Type::INVALID );
// return (gpointer)kvp_value_get_type( pInfo->pKvpValue ); // return (gpointer)kvp_value_get_type( pInfo->pKvpValue );
return pInfo->value_type; return pInfo->value_type;
@ -337,7 +341,7 @@ set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
g_return_if_fail( pValue != NULL ); g_return_if_fail( pValue != NULL );
pInfo->value_type = (KvpValueType)pValue; pInfo->value_type = static_cast<KvpValue::Type>(GPOINTER_TO_INT(pValue));
} }
static gint64 static gint64
@ -347,9 +351,9 @@ get_int64_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, 0 ); g_return_val_if_fail( pObject != NULL, 0 );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GINT64 ) if ( pInfo->pKvpValue->get_type() == KvpValue::Type::INT64 )
{ {
return kvp_value_get_gint64( pInfo->pKvpValue ); return pInfo->pKvpValue->get<int64_t>();
} }
else else
{ {
@ -365,8 +369,8 @@ set_int64_val( gpointer pObject, gint64 value )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_GINT64 ) return; if ( pInfo->value_type != KvpValue::Type::INT64 ) return;
pValue = kvp_value_new_gint64( value ); pValue = new KvpValue{value};
set_slot_from_value( pInfo, pValue ); set_slot_from_value( pInfo, pValue );
} }
@ -377,9 +381,9 @@ get_string_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, NULL ); g_return_val_if_fail( pObject != NULL, NULL );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_STRING ) if ( pInfo->pKvpValue->get_type() == KvpValue::Type::STRING )
{ {
return (gpointer)kvp_value_get_string( pInfo->pKvpValue ); return (gpointer)pInfo->pKvpValue->get<const char*>();
} }
else else
{ {
@ -391,12 +395,12 @@ static void
set_string_val( gpointer pObject, /*@ null @*/ gpointer pValue ) set_string_val( gpointer pObject, /*@ null @*/ gpointer pValue )
{ {
slot_info_t* pInfo = (slot_info_t*)pObject; slot_info_t* pInfo = (slot_info_t*)pObject;
KvpValue *value = NULL;
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_STRING || pValue == NULL ) return; if (pInfo->value_type != KvpValue::Type::STRING || pValue == NULL)
value = kvp_value_new_string( (gchar*)pValue ); return;
auto string = g_strdup(static_cast<const char*>(pValue));
auto value = new KvpValue{string};
set_slot_from_value( pInfo, value ); set_slot_from_value( pInfo, value );
} }
@ -408,9 +412,9 @@ get_double_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, NULL ); g_return_val_if_fail( pObject != NULL, NULL );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_DOUBLE ) if (pInfo->pKvpValue->get_type() == KvpValue::Type::DOUBLE)
{ {
d_val = kvp_value_get_double( pInfo->pKvpValue ); d_val = pInfo->pKvpValue->get<double>();
return (gpointer)&d_val; return (gpointer)&d_val;
} }
else else
@ -427,8 +431,8 @@ set_double_val( gpointer pObject, /*@ null @*/ gpointer pValue )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_DOUBLE || pValue == NULL ) return; if ( pInfo->value_type != KvpValue::Type::DOUBLE || pValue == NULL ) return;
value = kvp_value_new_double( *((double*)pValue) ); value = new KvpValue{*(static_cast<double*>(pValue))};
set_slot_from_value( pInfo, value ); set_slot_from_value( pInfo, value );
} }
@ -439,8 +443,8 @@ get_timespec_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) ); g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) );
//if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) { //if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIMESPEC ) {
return kvp_value_get_timespec( pInfo->pKvpValue ); return pInfo->pKvpValue->get<Timespec>();
} }
static void static void
@ -451,8 +455,8 @@ set_timespec_val( gpointer pObject, Timespec ts )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_TIMESPEC ) return; if ( pInfo->value_type != KvpValue::Type::TIMESPEC ) return;
value = kvp_value_new_timespec( ts ); value = new KvpValue{ts};
set_slot_from_value( pInfo, value ); set_slot_from_value( pInfo, value );
} }
@ -463,9 +467,9 @@ get_guid_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, NULL ); g_return_val_if_fail( pObject != NULL, NULL );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GUID ) if (pInfo->pKvpValue->get_type() == KvpValue::Type::GUID)
{ {
return (gpointer)kvp_value_get_guid( pInfo->pKvpValue ); return (gpointer)pInfo->pKvpValue->get<GncGUID*>();
} }
else else
{ {
@ -483,13 +487,13 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue )
switch ( pInfo->value_type) switch ( pInfo->value_type)
{ {
case KVP_TYPE_GUID: case KvpValue::Type::GUID:
{ {
KvpValue *value = kvp_value_new_guid( (GncGUID*)pValue ); auto new_guid = guid_copy(static_cast<GncGUID*>(pValue));
set_slot_from_value( pInfo, value ); set_slot_from_value(pInfo, new KvpValue{new_guid});
break; break;
} }
case KVP_TYPE_GLIST: case KvpValue::Type::GLIST:
{ {
slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ); slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue );
KvpValue *pValue = NULL; KvpValue *pValue = NULL;
@ -498,24 +502,24 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue )
newInfo->context = LIST; newInfo->context = LIST;
slots_load_info( newInfo ); slots_load_info( newInfo );
pValue = kvp_value_new_glist_nc( newInfo->pList ); pValue = new KvpValue{newInfo->pList};
kvp_frame_set_slot_nc(pInfo->pKvpFrame, key, pValue); pInfo->pKvpFrame->set(key, pValue);
g_string_free( newInfo->path, TRUE ); g_string_free( newInfo->path, TRUE );
g_slice_free( slot_info_t, newInfo ); g_slice_free( slot_info_t, newInfo );
g_free( key ); g_free( key );
break; break;
} }
case KVP_TYPE_FRAME: case KvpValue::Type::FRAME:
{ {
slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ) ; slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ) ;
KvpFrame *newFrame = kvp_frame_new(); auto newFrame = new KvpFrame;
newInfo->pKvpFrame = newFrame; newInfo->pKvpFrame = newFrame;
switch ( pInfo->context ) switch ( pInfo->context )
{ {
case LIST: case LIST:
{ {
KvpValue *value = kvp_value_new_frame_nc( newFrame ); auto value = new KvpValue{newFrame};
gchar *key = get_key_from_path( pInfo->path ); gchar *key = get_key_from_path( pInfo->path );
newInfo->path = g_string_assign( newInfo->path, key ); newInfo->path = g_string_assign( newInfo->path, key );
pInfo->pList = g_list_append( pInfo->pList, value ); pInfo->pList = g_list_append( pInfo->pList, value );
@ -526,7 +530,7 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue )
default: default:
{ {
gchar *key = get_key_from_path( pInfo->path ); gchar *key = get_key_from_path( pInfo->path );
kvp_frame_set_frame_nc( pInfo->pKvpFrame, key, newFrame ); pInfo->pKvpFrame->set(key, new KvpValue{newFrame});
g_free( key ); g_free( key );
break; break;
} }
@ -550,9 +554,9 @@ get_numeric_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() ); g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_NUMERIC ) if (pInfo->pKvpValue->get_type() == KvpValue::Type::NUMERIC)
{ {
return kvp_value_get_numeric( pInfo->pKvpValue ); return pInfo->pKvpValue->get<gnc_numeric>();
} }
else else
{ {
@ -568,9 +572,8 @@ set_numeric_val( gpointer pObject, gnc_numeric value )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_NUMERIC ) return; if ( pInfo->value_type != KvpValue::Type::NUMERIC ) return;
pValue = kvp_value_new_numeric( value ); set_slot_from_value(pInfo, new KvpValue{value});
set_slot_from_value( pInfo, pValue );
} }
static GDate* static GDate*
@ -581,9 +584,9 @@ get_gdate_val( gpointer pObject )
g_return_val_if_fail( pObject != NULL, NULL ); g_return_val_if_fail( pObject != NULL, NULL );
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GDATE ) if (pInfo->pKvpValue->get_type() == KvpValue::Type::GDATE)
{ {
date = kvp_value_get_gdate( pInfo->pKvpValue ); date = pInfo->pKvpValue->get<GDate>();
return &date; return &date;
} }
else else
@ -600,9 +603,8 @@ set_gdate_val( gpointer pObject, GDate* value )
g_return_if_fail( pObject != NULL ); g_return_if_fail( pObject != NULL );
if ( pInfo->value_type != KVP_TYPE_GDATE ) return; if ( pInfo->value_type != KvpValue::Type::GDATE ) return;
pValue = kvp_value_new_gdate( *value ); set_slot_from_value(pInfo, new KvpValue{*value});
set_slot_from_value( pInfo, pValue );
} }
static slot_info_t * static slot_info_t *
@ -647,47 +649,46 @@ save_slot( const gchar* key, KvpValue* value, gpointer data )
(void)g_string_append( pSlot_info->path, "/" ); (void)g_string_append( pSlot_info->path, "/" );
} }
(void)g_string_append( pSlot_info->path, key ); (void)g_string_append( pSlot_info->path, key );
pSlot_info->value_type = kvp_value_get_type( value ); pSlot_info->value_type = value->get_type();
switch ( pSlot_info->value_type ) switch ( pSlot_info->value_type )
{ {
case KVP_TYPE_FRAME: case KvpValue::Type::FRAME:
{ {
KvpFrame* pKvpFrame = kvp_value_get_frame( value ); auto pKvpFrame = value->get<KvpFrame*>();
GncGUID guid = guid_new_return(); auto guid = guid_new();
slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, guid );
KvpValue *oldValue = pSlot_info->pKvpValue; KvpValue *oldValue = pSlot_info->pKvpValue;
pSlot_info->pKvpValue = kvp_value_new_guid( &guid ); pSlot_info->pKvpValue = new KvpValue{guid};
pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
OP_DB_INSERT, TABLE_NAME, OP_DB_INSERT, TABLE_NAME,
TABLE_NAME, pSlot_info, TABLE_NAME, pSlot_info,
col_table ); col_table );
g_return_if_fail( pSlot_info->is_ok ); g_return_if_fail( pSlot_info->is_ok );
kvp_frame_for_each_slot( pKvpFrame, save_slot, pNewInfo ); pKvpFrame->for_each_slot(save_slot, pNewInfo);
kvp_value_delete( pSlot_info->pKvpValue ); delete pSlot_info->pKvpValue;
pSlot_info->pKvpValue = oldValue; pSlot_info->pKvpValue = oldValue;
g_string_free( pNewInfo->path, TRUE ); g_string_free( pNewInfo->path, TRUE );
g_slice_free( slot_info_t, pNewInfo ); g_slice_free( slot_info_t, pNewInfo );
} }
break; break;
case KVP_TYPE_GLIST: case KvpValue::Type::GLIST:
{ {
GList *cursor;
GncGUID guid = guid_new_return(); GncGUID guid = guid_new_return();
slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
KvpValue *oldValue = pSlot_info->pKvpValue; KvpValue *oldValue = pSlot_info->pKvpValue;
pSlot_info->pKvpValue = kvp_value_new_guid( &guid ); pSlot_info->pKvpValue = new KvpValue{&guid};
pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
OP_DB_INSERT, TABLE_NAME, OP_DB_INSERT, TABLE_NAME,
TABLE_NAME, pSlot_info, TABLE_NAME, pSlot_info,
col_table ); col_table );
g_return_if_fail( pSlot_info->is_ok ); g_return_if_fail( pSlot_info->is_ok );
for (cursor = kvp_value_get_glist(value); cursor; cursor = cursor->next) for (auto cursor = value->get<GList*>(); cursor; cursor = cursor->next)
{ {
KvpValue *val = (KvpValue*)cursor->data; auto val = static_cast<KvpValue*>(cursor->data);
save_slot("", val, pNewInfo); save_slot("", val, pNewInfo);
} }
kvp_value_delete( pSlot_info->pKvpValue ); delete pSlot_info->pKvpValue;
pSlot_info->pKvpValue = oldValue; pSlot_info->pKvpValue = oldValue;
g_string_free( pNewInfo->path, TRUE ); g_string_free( pNewInfo->path, TRUE );
g_slice_free( slot_info_t, pNewInfo ); g_slice_free( slot_info_t, pNewInfo );
@ -707,9 +708,11 @@ save_slot( const gchar* key, KvpValue* value, gpointer data )
} }
gboolean gboolean
gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant, KvpFrame* pFrame ) gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant,
QofInstance *inst)
{ {
slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new(NULL) }; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) };
KvpFrame *pFrame = qof_instance_get_slots (inst);
g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( be != NULL, FALSE );
g_return_val_if_fail( guid != NULL, FALSE ); g_return_val_if_fail( guid != NULL, FALSE );
@ -723,7 +726,7 @@ gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant,
slot_info.be = be; slot_info.be = be;
slot_info.guid = guid; slot_info.guid = guid;
kvp_frame_for_each_slot( pFrame, save_slot, &slot_info ); pFrame->for_each_slot(save_slot, &slot_info);
(void)g_string_free( slot_info.path, TRUE ); (void)g_string_free( slot_info.path, TRUE );
return slot_info.is_ok; return slot_info.is_ok;
@ -736,7 +739,7 @@ gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid )
GncSqlResult* result; GncSqlResult* result;
gchar guid_buf[GUID_ENCODING_LENGTH + 1]; gchar guid_buf[GUID_ENCODING_LENGTH + 1];
GncSqlStatement* stmt; GncSqlStatement* stmt;
slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new(NULL) }; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) };
g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( be != NULL, FALSE );
g_return_val_if_fail( guid != NULL, FALSE ); g_return_val_if_fail( guid != NULL, FALSE );
@ -744,7 +747,7 @@ gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid )
(void)guid_to_string_buff( guid, guid_buf ); (void)guid_to_string_buff( guid, guid_buf );
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s' and slot_type in ('%d', '%d') and not guid_val is null", buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s' and slot_type in ('%d', '%d') and not guid_val is null",
TABLE_NAME, guid_buf, KVP_TYPE_FRAME, KVP_TYPE_GLIST ); TABLE_NAME, guid_buf, KvpValue::Type::FRAME, KvpValue::Type::GLIST );
stmt = gnc_sql_create_statement_from_sql( be, buf ); stmt = gnc_sql_create_statement_from_sql( be, buf );
g_free( buf ); g_free( buf );
if ( stmt != NULL ) if ( stmt != NULL )
@ -818,7 +821,7 @@ load_slot( slot_info_t *pInfo, GncSqlRow* row )
void void
gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst ) gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst )
{ {
slot_info_t info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new(NULL) }; slot_info_t info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) };
g_return_if_fail( be != NULL ); g_return_if_fail( be != NULL );
g_return_if_fail( inst != NULL ); g_return_if_fail( inst != NULL );
@ -883,7 +886,7 @@ load_obj_guid( const GncSqlBackend* be, GncSqlRow* row )
static void static void
load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll ) load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll )
{ {
slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, NULL }; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, NULL };
const GncGUID* guid; const GncGUID* guid;
QofInstance* inst; QofInstance* inst;
@ -969,7 +972,7 @@ gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
static void static void
load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn lookup_fn ) load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn lookup_fn )
{ {
slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, NULL }; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, NULL };
const GncGUID* guid; const GncGUID* guid;
QofInstance* inst; QofInstance* inst;

View File

@ -28,10 +28,13 @@
#ifndef GNC_SLOTS_SQL_H #ifndef GNC_SLOTS_SQL_H
#define GNC_SLOTS_SQL_H #define GNC_SLOTS_SQL_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
#include "guid.h" #include "guid.h"
#include "kvp_frame.h"
#include "qof.h" #include "qof.h"
#include "gnc-backend-sql.h" #include "gnc-backend-sql.h"
@ -41,11 +44,11 @@
* @param be SQL backend * @param be SQL backend
* @param guid Object guid * @param guid Object guid
* @param is_infant Is this an infant object? * @param is_infant Is this an infant object?
* @param pFrame Top-level KVP frame * @param inst The QodInstance owning the slots.
* @return TRUE if successful, FALSE if error * @return TRUE if successful, FALSE if error
*/ */
gboolean gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid,
gboolean is_infant, KvpFrame* pFrame ); gboolean is_infant, QofInstance *inst );
/** /**
* gnc_sql_slots_delete - Deletes slots for an object from the db. * gnc_sql_slots_delete - Deletes slots for an object from the db.
@ -88,4 +91,7 @@ void gnc_sql_slots_load_for_sql_subquery( GncSqlBackend* be, const gchar* subque
void gnc_sql_init_slots_handler( void ); void gnc_sql_init_slots_handler( void );
#ifdef __cplusplus
}
#endif
#endif /* GNC_SLOTS_SQL_H */ #endif /* GNC_SLOTS_SQL_H */

View File

@ -454,7 +454,7 @@ save_taxtable( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
if ( is_ok ) if ( is_ok )
{ {
is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) ); is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) );

View File

@ -627,10 +627,7 @@ commit_split( GncSqlBackend* be, QofInstance* inst )
if ( is_ok && !qof_instance_get_destroying (inst)) if ( is_ok && !qof_instance_get_destroying (inst))
{ {
is_ok = gnc_sql_slots_save( be, is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
guid,
is_infant,
qof_instance_get_slots( inst ) );
} }
return is_ok; return is_ok;
@ -724,7 +721,7 @@ save_transaction( GncSqlBackend* be, Transaction* pTx, gboolean do_save_splits )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
if ( ! is_ok ) if ( ! is_ok )
{ {
err = "Slots save failed. Check trace log for SQL errors"; err = "Slots save failed. Check trace log for SQL errors";

View File

@ -194,7 +194,7 @@ save_vendor( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( inst ); guid = qof_instance_get_guid( inst );
if ( !qof_instance_get_destroying(inst) ) if ( !qof_instance_get_destroying(inst) )
{ {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); is_ok = gnc_sql_slots_save( be, guid, is_infant, inst);
} }
else else
{ {

View File

@ -583,7 +583,7 @@ test_gnc_sql_convert_timespec_to_string ()
GncSqlBackend be = {{ GncSqlBackend be = {{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
0, NULL, 0, "", NULL, 0, "", NULL, NULL 0, NULL, 0, "", NULL
}, },
NULL, NULL, FALSE, FALSE, FALSE, 0, 0, NULL, NULL, NULL, FALSE, FALSE, FALSE, 0, 0, NULL,
"%4d-%02d-%02d %02d:%02d:%02d" "%4d-%02d-%02d %02d:%02d:%02d"

View File

@ -49,8 +49,8 @@ SET (libgnc_backend_xml_SOURCES
io-gncxml-v1.c io-gncxml-v1.c
io-gncxml-v2.c io-gncxml-v2.c
io-utils.c io-utils.c
sixtp-dom-generators.c sixtp-dom-generators.cpp
sixtp-dom-parsers.c sixtp-dom-parsers.cpp
sixtp-stack.c sixtp-stack.c
sixtp-to-dom-parser.c sixtp-to-dom-parser.c
sixtp-utils.c sixtp-utils.c

View File

@ -42,11 +42,11 @@ libgnc_backend_xml_utils_la_SOURCES = \
gnc-xml-helper.c \ gnc-xml-helper.c \
io-example-account.c \ io-example-account.c \
io-gncxml-gen.c \ io-gncxml-gen.c \
io-gncxml-v1.c \ io-gncxml-v1.cpp \
io-gncxml-v2.c \ io-gncxml-v2.c \
io-utils.c \ io-utils.c \
sixtp-dom-generators.c \ sixtp-dom-generators.cpp \
sixtp-dom-parsers.c \ sixtp-dom-parsers.cpp \
sixtp-stack.c \ sixtp-stack.c \
sixtp-to-dom-parser.c \ sixtp-to-dom-parser.c \
sixtp-utils.c \ sixtp-utils.c \

View File

@ -71,16 +71,12 @@ const gchar *account_version_string = "2.0.0";
#define act_hidden_string "act:hidden" #define act_hidden_string "act:hidden"
#define act_placeholder_string "act:placeholder" #define act_placeholder_string "act:placeholder"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
xmlNodePtr xmlNodePtr
gnc_account_dom_tree_create(Account *act, gnc_account_dom_tree_create(Account *act,
gboolean exporting, gboolean exporting,
gboolean allow_incompat) gboolean allow_incompat)
{ {
const char *str; const char *str;
KvpFrame *kf;
xmlNodePtr ret; xmlNodePtr ret;
GList *lots, *n; GList *lots, *n;
Account *parent; Account *parent;
@ -137,16 +133,9 @@ gnc_account_dom_tree_create(Account *act,
xmlAddChild(ret, text_to_dom_tree(act_description_string, str)); xmlAddChild(ret, text_to_dom_tree(act_description_string, str));
} }
kf = qof_instance_get_slots (QOF_INSTANCE (act)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(act_slots_string,
{ QOF_INSTANCE(act)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(act_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
parent = gnc_account_get_parent(act); parent = gnc_account_get_parent(act);
if (parent) if (parent)
{ {
@ -371,9 +360,7 @@ static gboolean
account_slots_handler (xmlNodePtr node, gpointer act_pdata) account_slots_handler (xmlNodePtr node, gpointer act_pdata)
{ {
struct account_pdata *pdata = act_pdata; struct account_pdata *pdata = act_pdata;
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->account));
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->account)));
} }
static gboolean static gboolean

View File

@ -58,9 +58,6 @@ const gchar *address_version_string = "2.0.0";
#define addr_email_string "addr:email" #define addr_email_string "addr:email"
#define addr_slots_string "addr:slots" #define addr_slots_string "addr:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{ {
@ -72,7 +69,6 @@ xmlNodePtr
gnc_address_to_dom_tree (const char *tag, GncAddress *addr) gnc_address_to_dom_tree (const char *tag, GncAddress *addr)
{ {
xmlNodePtr ret; xmlNodePtr ret;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST tag); ret = xmlNewNode(NULL, BAD_CAST tag);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST address_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST address_version_string);
@ -88,16 +84,9 @@ gnc_address_to_dom_tree (const char *tag, GncAddress *addr)
maybe_add_string (ret, addr_fax_string, gncAddressGetFax (addr)); maybe_add_string (ret, addr_fax_string, gncAddressGetFax (addr));
maybe_add_string (ret, addr_email_string, gncAddressGetEmail (addr)); maybe_add_string (ret, addr_email_string, gncAddressGetEmail (addr));
kf = qof_instance_get_slots (QOF_INSTANCE(addr)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(addr_slots_string,
{ QOF_INSTANCE(addr)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(addr_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -190,9 +179,7 @@ static gboolean
address_slots_handler (xmlNodePtr node, gpointer addr_pdata) address_slots_handler (xmlNodePtr node, gpointer addr_pdata)
{ {
struct address_pdata *pdata = addr_pdata; struct address_pdata *pdata = addr_pdata;
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->address));
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->address)));
} }
static struct dom_tree_handler address_handlers_v2[] = static struct dom_tree_handler address_handlers_v2[] =

View File

@ -1251,8 +1251,6 @@ gnc_backend_new(void)
be->process_events = NULL; be->process_events = NULL;
be->sync = xml_sync_all; be->sync = xml_sync_all;
be->load_config = NULL;
be->get_config = NULL;
be->export_fn = gnc_xml_be_write_accounts_to_file; be->export_fn = gnc_xml_be_write_accounts_to_file;

View File

@ -79,7 +79,7 @@ const gchar *billterm_version_string = "2.0.0";
static xmlNodePtr static xmlNodePtr
billterm_dom_tree_create (GncBillTerm *term) billterm_dom_tree_create (GncBillTerm *term)
{ {
xmlNodePtr ret, data, kvpnode; xmlNodePtr ret, data;
ret = xmlNewNode(NULL, BAD_CAST gnc_billterm_string); ret = xmlNewNode(NULL, BAD_CAST gnc_billterm_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST billterm_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST billterm_version_string);
@ -95,10 +95,9 @@ billterm_dom_tree_create (GncBillTerm *term)
xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string, xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string,
gncBillTermGetInvisible (term))); gncBillTermGetInvisible (term)));
kvpnode = kvp_frame_to_dom_tree (billterm_slots_string, /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
qof_instance_get_slots (QOF_INSTANCE(term))); xmlAddChild(ret, qof_instance_slots_to_dom_tree(billterm_slots_string,
if (kvpnode) xmlAddChild (ret, kvpnode); QOF_INSTANCE(term)));
/* We should not be our own child */ /* We should not be our own child */
if (gncBillTermGetChild(term) != term) if (gncBillTermGetChild(term) != term)
@ -401,8 +400,7 @@ static gboolean
billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata) billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata)
{ {
struct billterm_pdata *pdata = billterm_pdata; struct billterm_pdata *pdata = billterm_pdata;
return dom_tree_to_kvp_frame_given (node, return dom_tree_create_instance_slots (node, QOF_INSTANCE(pdata->term));
qof_instance_get_slots (QOF_INSTANCE(pdata->term)));
} }
static struct dom_tree_handler billterm_handlers_v2[] = static struct dom_tree_handler billterm_handlers_v2[] =

View File

@ -109,13 +109,9 @@ gnc_book_dom_tree_create(QofBook *book)
xmlAddChild(ret, guid_to_dom_tree(book_id_string, xmlAddChild(ret, guid_to_dom_tree(book_id_string,
qof_book_get_guid(book))); qof_book_get_guid(book)));
if (qof_instance_get_slots (QOF_INSTANCE (book))) /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
{ xmlAddChild(ret, qof_instance_slots_to_dom_tree(book_slots_string,
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string, QOF_INSTANCE(book)));
qof_instance_get_slots (QOF_INSTANCE (book)));
if (kvpnode)
xmlAddChild(ret, kvpnode);
}
#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER #ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
/* theoretically, we should be adding all the below to the book /* theoretically, we should be adding all the below to the book
@ -153,7 +149,7 @@ gnc_book_dom_tree_create(QofBook *book)
gboolean gboolean
write_book_parts(FILE *out, QofBook *book) write_book_parts(FILE *out, QofBook *book)
{ {
xmlNodePtr domnode; xmlNodePtr domnode, slotsnode;
domnode = guid_to_dom_tree(book_id_string, qof_book_get_guid(book)); domnode = guid_to_dom_tree(book_id_string, qof_book_get_guid(book));
xmlElemDump(out, NULL, domnode); xmlElemDump(out, NULL, domnode);
@ -162,18 +158,16 @@ write_book_parts(FILE *out, QofBook *book)
if (ferror(out) || fprintf(out, "\n") < 0) if (ferror(out) || fprintf(out, "\n") < 0)
return FALSE; return FALSE;
if (qof_instance_get_slots (QOF_INSTANCE (book)))
slotsnode = qof_instance_slots_to_dom_tree(book_slots_string,
QOF_INSTANCE(book));
if (slotsnode)
{ {
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string, xmlElemDump(out, NULL, slotsnode);
qof_instance_get_slots (QOF_INSTANCE (book))); xmlFreeNode(slotsnode);
if (kvpnode)
{
xmlElemDump(out, NULL, kvpnode);
xmlFreeNode(kvpnode);
if (ferror(out) || fprintf(out, "\n") < 0) if (ferror(out) || fprintf(out, "\n") < 0)
return FALSE; return FALSE;
}
} }
return TRUE; return TRUE;
@ -203,7 +197,7 @@ book_slots_handler (xmlNodePtr node, gpointer book_pdata)
/* the below works only because the get is gaurenteed to return /* the below works only because the get is gaurenteed to return
* a frame, even if its empty */ * a frame, even if its empty */
success = dom_tree_to_kvp_frame_given (node, qof_instance_get_slots (QOF_INSTANCE (book))); success = dom_tree_create_instance_slots(node, QOF_INSTANCE (book));
g_return_val_if_fail(success, FALSE); g_return_val_if_fail(success, FALSE);

View File

@ -57,7 +57,6 @@ xmlNodePtr
gnc_budget_dom_tree_create(GncBudget *bgt) gnc_budget_dom_tree_create(GncBudget *bgt)
{ {
xmlNodePtr ret; xmlNodePtr ret;
KvpFrame *kf;
ENTER ("(budget=%p)", bgt); ENTER ("(budget=%p)", bgt);
@ -79,14 +78,9 @@ gnc_budget_dom_tree_create(GncBudget *bgt)
/* field: Recurrence* */ /* field: Recurrence* */
xmlAddChild(ret, recurrence_to_dom_tree(bgt_recurrence_string, xmlAddChild(ret, recurrence_to_dom_tree(bgt_recurrence_string,
gnc_budget_get_recurrence(bgt))); gnc_budget_get_recurrence(bgt)));
/* slots */ /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
kf = qof_instance_get_slots(QOF_INSTANCE(bgt)); xmlAddChild(ret, qof_instance_slots_to_dom_tree(bgt_slots_string,
if (kf) QOF_INSTANCE(bgt)));
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(bgt_slots_string, kf);
if (kvpnode)
xmlAddChild(ret, kvpnode);
}
LEAVE (" "); LEAVE (" ");
return ret; return ret;
@ -159,8 +153,7 @@ budget_recurrence_handler (xmlNodePtr node, gpointer bgt)
static gboolean static gboolean
budget_slots_handler (xmlNodePtr node, gpointer bgt) budget_slots_handler (xmlNodePtr node, gpointer bgt)
{ {
return dom_tree_to_kvp_frame_given( return dom_tree_create_instance_slots(node, QOF_INSTANCE(bgt));
node, qof_instance_get_slots(QOF_INSTANCE(bgt)));
} }
static struct dom_tree_handler budget_handlers[] = static struct dom_tree_handler budget_handlers[] =

View File

@ -66,11 +66,10 @@ gnc_commodity_dom_tree_create(const gnc_commodity *com)
const char *string; const char *string;
xmlNodePtr ret; xmlNodePtr ret;
gboolean currency = gnc_commodity_is_iso(com); gboolean currency = gnc_commodity_is_iso(com);
xmlNodePtr kvpnode = xmlNodePtr slotsnode =
kvp_frame_to_dom_tree(cmdty_slots, qof_instance_slots_to_dom_tree(cmdty_slots, QOF_INSTANCE(com));
qof_instance_get_slots(QOF_INSTANCE(com)));
if (currency && !gnc_commodity_get_quote_flag(com) && !kvpnode) if (currency && !gnc_commodity_get_quote_flag(com) && !slotsnode)
return NULL; return NULL;
ret = xmlNewNode(NULL, BAD_CAST gnc_commodity_string); ret = xmlNewNode(NULL, BAD_CAST gnc_commodity_string);
@ -114,8 +113,8 @@ gnc_commodity_dom_tree_create(const gnc_commodity *com)
xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string)); xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string));
} }
if (kvpnode) if (slotsnode)
xmlAddChild(ret, kvpnode); xmlAddChild(ret, slotsnode);
return ret; return ret;
} }
@ -172,8 +171,7 @@ set_commodity_value(xmlNodePtr node, gnc_commodity* com)
else if (g_strcmp0((char*)node->name, cmdty_slots) == 0) else if (g_strcmp0((char*)node->name, cmdty_slots) == 0)
{ {
/* We ignore the results here */ /* We ignore the results here */
dom_tree_to_kvp_frame_given(node, dom_tree_create_instance_slots(node, QOF_INSTANCE(com));
qof_instance_get_slots(QOF_INSTANCE(com)));
} }
else else
{ {

View File

@ -77,7 +77,7 @@ const gchar *customer_version_string = "2.0.0";
static xmlNodePtr static xmlNodePtr
customer_dom_tree_create (GncCustomer *cust) customer_dom_tree_create (GncCustomer *cust)
{ {
xmlNodePtr ret, kvpnode; xmlNodePtr ret;
gnc_numeric num; gnc_numeric num;
GncBillTerm *term; GncBillTerm *term;
GncTaxTable *taxtable; GncTaxTable *taxtable;
@ -132,9 +132,9 @@ customer_dom_tree_create (GncCustomer *cust)
xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string, xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
qof_instance_get_guid(QOF_INSTANCE(taxtable)))); qof_instance_get_guid(QOF_INSTANCE(taxtable))));
kvpnode = kvp_frame_to_dom_tree (cust_slots_string, /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
qof_instance_get_slots (QOF_INSTANCE(cust))); xmlAddChild(ret, qof_instance_slots_to_dom_tree(cust_slots_string,
if (kvpnode) xmlAddChild (ret, kvpnode); QOF_INSTANCE(cust)));
return ret; return ret;
} }
@ -367,8 +367,7 @@ static gboolean
customer_slots_handler (xmlNodePtr node, gpointer cust_pdata) customer_slots_handler (xmlNodePtr node, gpointer cust_pdata)
{ {
struct customer_pdata *pdata = cust_pdata; struct customer_pdata *pdata = cust_pdata;
return dom_tree_to_kvp_frame_given (node, return dom_tree_create_instance_slots(node, QOF_INSTANCE(pdata->customer));
qof_instance_get_slots (QOF_INSTANCE(pdata->customer)));
} }
static struct dom_tree_handler customer_handlers_v2[] = static struct dom_tree_handler customer_handlers_v2[] =

View File

@ -76,7 +76,7 @@ maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
static xmlNodePtr static xmlNodePtr
employee_dom_tree_create (GncEmployee *employee) employee_dom_tree_create (GncEmployee *employee)
{ {
xmlNodePtr ret, kvpnode; xmlNodePtr ret;
gnc_numeric num; gnc_numeric num;
Account* ccard_acc; Account* ccard_acc;
@ -118,10 +118,9 @@ employee_dom_tree_create (GncEmployee *employee)
xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string, xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string,
qof_instance_get_guid(QOF_INSTANCE(ccard_acc)))); qof_instance_get_guid(QOF_INSTANCE(ccard_acc))));
kvpnode = kvp_frame_to_dom_tree (employee_slots_string, /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
qof_instance_get_slots (QOF_INSTANCE(employee))); xmlAddChild(ret, qof_instance_slots_to_dom_tree(employee_slots_string,
if (kvpnode) xmlAddChild (ret, kvpnode); QOF_INSTANCE(employee)));
return ret; return ret;
} }
@ -294,8 +293,7 @@ static gboolean
employee_slots_handler (xmlNodePtr node, gpointer employee_pdata) employee_slots_handler (xmlNodePtr node, gpointer employee_pdata)
{ {
struct employee_pdata *pdata = employee_pdata; struct employee_pdata *pdata = employee_pdata;
return dom_tree_to_kvp_frame_given ( return dom_tree_create_instance_slots (node, QOF_INSTANCE(pdata->employee));
node, qof_instance_get_slots (QOF_INSTANCE(pdata->employee)));
} }
static struct dom_tree_handler employee_handlers_v2[] = static struct dom_tree_handler employee_handlers_v2[] =

View File

@ -92,9 +92,6 @@ const gchar *entry_version_string = "2.0.0";
#define entry_bill_string "entry:bill" #define entry_bill_string "entry:bill"
#define entry_slots_string "entry:slots" #define entry_slots_string "entry:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{ {
@ -118,7 +115,6 @@ entry_dom_tree_create (GncEntry *entry)
GncTaxTable *taxtable; GncTaxTable *taxtable;
GncOrder *order; GncOrder *order;
GncInvoice *invoice; GncInvoice *invoice;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_entry_string); ret = xmlNewNode(NULL, BAD_CAST gnc_entry_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST entry_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST entry_version_string);
@ -215,16 +211,9 @@ entry_dom_tree_create (GncEntry *entry)
xmlAddChild (ret, guid_to_dom_tree (entry_order_string, xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
qof_instance_get_guid(QOF_INSTANCE (order)))); qof_instance_get_guid(QOF_INSTANCE (order))));
kf = qof_instance_get_slots (QOF_INSTANCE(entry)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(entry_slots_string,
{ QOF_INSTANCE(entry)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(entry_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -677,8 +666,7 @@ entry_slots_handler (xmlNodePtr node, gpointer entry_pdata)
{ {
struct entry_pdata *pdata = entry_pdata; struct entry_pdata *pdata = entry_pdata;
return dom_tree_to_kvp_frame_given return dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->entry));
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->entry)));
} }
static struct dom_tree_handler entry_handlers_v2[] = static struct dom_tree_handler entry_handlers_v2[] =

View File

@ -72,9 +72,6 @@ const gchar *invoice_version_string = "2.0.0";
#define invoice_tochargeamt_string "invoice:charge-amt" #define invoice_tochargeamt_string "invoice:charge-amt"
#define invoice_slots_string "invoice:slots" #define invoice_slots_string "invoice:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
static void static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{ {
@ -93,7 +90,6 @@ static xmlNodePtr
invoice_dom_tree_create (GncInvoice *invoice) invoice_dom_tree_create (GncInvoice *invoice)
{ {
xmlNodePtr ret; xmlNodePtr ret;
KvpFrame *kf;
Timespec ts; Timespec ts;
Transaction *txn; Transaction *txn;
GNCLot *lot; GNCLot *lot;
@ -160,16 +156,9 @@ invoice_dom_tree_create (GncInvoice *invoice)
if (! gnc_numeric_zero_p (amt)) if (! gnc_numeric_zero_p (amt))
xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt)); xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt));
kf = qof_instance_get_slots (QOF_INSTANCE(invoice)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(invoice_slots_string,
{ QOF_INSTANCE(invoice)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(invoice_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -411,9 +400,7 @@ static gboolean
invoice_slots_handler (xmlNodePtr node, gpointer invoice_pdata) invoice_slots_handler (xmlNodePtr node, gpointer invoice_pdata)
{ {
struct invoice_pdata *pdata = invoice_pdata; struct invoice_pdata *pdata = invoice_pdata;
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->invoice));
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->invoice)));
} }
static struct dom_tree_handler invoice_handlers_v2[] = static struct dom_tree_handler invoice_handlers_v2[] =

View File

@ -62,14 +62,10 @@ const gchar *job_version_string = "2.0.0";
#define job_active_string "job:active" #define job_active_string "job:active"
#define job_slots_string "job:slots" #define job_slots_string "job:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static xmlNodePtr static xmlNodePtr
job_dom_tree_create (GncJob *job) job_dom_tree_create (GncJob *job)
{ {
xmlNodePtr ret; xmlNodePtr ret;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_job_string); ret = xmlNewNode(NULL, BAD_CAST gnc_job_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST job_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST job_version_string);
@ -91,15 +87,9 @@ job_dom_tree_create (GncJob *job)
xmlAddChild(ret, int_to_dom_tree(job_active_string, xmlAddChild(ret, int_to_dom_tree(job_active_string,
gncJobGetActive (job))); gncJobGetActive (job)));
kf = qof_instance_get_slots (QOF_INSTANCE(job)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(job_slots_string,
{ QOF_INSTANCE(job)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(job_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -209,8 +199,7 @@ job_slots_handler (xmlNodePtr node, gpointer job_pdata)
{ {
struct job_pdata *pdata = job_pdata; struct job_pdata *pdata = job_pdata;
return dom_tree_to_kvp_frame_given return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->job));
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->job)));
} }
static struct dom_tree_handler job_handlers_v2[] = static struct dom_tree_handler job_handlers_v2[] =

View File

@ -53,30 +53,20 @@ const gchar *lot_version_string = "2.0.0";
#define gnc_lot_string "gnc:lot" #define gnc_lot_string "gnc:lot"
#define lot_id_string "lot:id" #define lot_id_string "lot:id"
#define lot_slots_string "lot:slots" #define lot_slots_string "lot:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
xmlNodePtr xmlNodePtr
gnc_lot_dom_tree_create(GNCLot *lot) gnc_lot_dom_tree_create(GNCLot *lot)
{ {
xmlNodePtr ret; xmlNodePtr ret;
KvpFrame *kf;
ENTER("(lot=%p)", lot); ENTER("(lot=%p)", lot);
ret = xmlNewNode(NULL, BAD_CAST gnc_lot_string); ret = xmlNewNode(NULL, BAD_CAST gnc_lot_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST lot_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST lot_version_string);
xmlAddChild(ret, guid_to_dom_tree(lot_id_string, gnc_lot_get_guid(lot))); xmlAddChild(ret, guid_to_dom_tree(lot_id_string, gnc_lot_get_guid(lot)));
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
kf = qof_instance_get_slots (QOF_INSTANCE (lot)); xmlAddChild(ret, qof_instance_slots_to_dom_tree(lot_slots_string,
if (kf) QOF_INSTANCE(lot)));
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(lot_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
LEAVE(""); LEAVE("");
return ret; return ret;
@ -113,8 +103,7 @@ lot_slots_handler (xmlNodePtr node, gpointer p)
gboolean success; gboolean success;
ENTER("(lot=%p)", pdata->lot); ENTER("(lot=%p)", pdata->lot);
success = dom_tree_to_kvp_frame_given success = dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->lot));
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->lot)));
LEAVE(""); LEAVE("");
g_return_val_if_fail(success, FALSE); g_return_val_if_fail(success, FALSE);

View File

@ -64,9 +64,6 @@ const gchar *order_version_string = "2.0.0";
#define order_active_string "order:active" #define order_active_string "order:active"
#define order_slots_string "order:slots" #define order_slots_string "order:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{ {
@ -79,7 +76,6 @@ order_dom_tree_create (GncOrder *order)
{ {
xmlNodePtr ret; xmlNodePtr ret;
Timespec ts; Timespec ts;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_order_string); ret = xmlNewNode(NULL, BAD_CAST gnc_order_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST order_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST order_version_string);
@ -106,15 +102,9 @@ order_dom_tree_create (GncOrder *order)
xmlAddChild(ret, int_to_dom_tree(order_active_string, xmlAddChild(ret, int_to_dom_tree(order_active_string,
gncOrderGetActive (order))); gncOrderGetActive (order)));
kf = qof_instance_get_slots (QOF_INSTANCE(order)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(order_slots_string,
{ QOF_INSTANCE(order)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(order_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -250,8 +240,7 @@ order_slots_handler (xmlNodePtr node, gpointer order_pdata)
{ {
struct order_pdata *pdata = order_pdata; struct order_pdata *pdata = order_pdata;
return dom_tree_to_kvp_frame_given return dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->order));
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->order)));
} }
static struct dom_tree_handler order_handlers_v2[] = static struct dom_tree_handler order_handlers_v2[] =

View File

@ -190,17 +190,9 @@ gnc_schedXaction_dom_tree_create(SchedXaction *sx)
} }
} }
/* output kvp_frame */ /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
{ xmlAddChild(ret, qof_instance_slots_to_dom_tree(SX_SLOTS,
xmlNodePtr kvpnode = QOF_INSTANCE(sx)));
kvp_frame_to_dom_tree( SX_SLOTS,
xaccSchedXactionGetSlots(sx) );
if ( kvpnode )
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -629,7 +621,7 @@ sx_slots_handler( xmlNodePtr node, gpointer sx_pdata )
struct sx_pdata *pdata = sx_pdata; struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx; SchedXaction *sx = pdata->sx;
return dom_tree_to_kvp_frame_given( node, xaccSchedXactionGetSlots (sx) ); return dom_tree_create_instance_slots(node, QOF_INSTANCE(sx));
} }
struct dom_tree_handler sx_dom_handlers[] = struct dom_tree_handler sx_dom_handlers[] =

View File

@ -67,9 +67,6 @@ const gchar *taxtable_version_string = "2.0.0";
#define ttentry_type_string "tte:type" #define ttentry_type_string "tte:type"
#define ttentry_amount_string "tte:amount" #define ttentry_amount_string "tte:amount"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void static void
maybe_add_guid (xmlNodePtr ptr, const char *tag, GncTaxTable *table) maybe_add_guid (xmlNodePtr ptr, const char *tag, GncTaxTable *table)
{ {
@ -107,7 +104,6 @@ taxtable_dom_tree_create (GncTaxTable *table)
{ {
xmlNodePtr ret, entries; xmlNodePtr ret, entries;
GList *list; GList *list;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_taxtable_string); ret = xmlNewNode(NULL, BAD_CAST gnc_taxtable_string);
xmlSetProp(ret, BAD_CAST "version", BAD_CAST taxtable_version_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST taxtable_version_string);
@ -134,16 +130,9 @@ taxtable_dom_tree_create (GncTaxTable *table)
xmlAddChild(entries, ttentry_dom_tree_create (entry)); xmlAddChild(entries, ttentry_dom_tree_create (entry));
} }
kf = qof_instance_get_slots (QOF_INSTANCE(table)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
if (kf) xmlAddChild(ret, qof_instance_slots_to_dom_tree(taxtable_slots_string,
{ QOF_INSTANCE(table)));
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(taxtable_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -384,8 +373,7 @@ taxtable_slots_handler (xmlNodePtr node, gpointer taxtable_pdata)
{ {
struct taxtable_pdata *pdata = taxtable_pdata; struct taxtable_pdata *pdata = taxtable_pdata;
return dom_tree_to_kvp_frame_given return dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->table));
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->table)));
} }
static struct dom_tree_handler taxtable_handlers_v2[] = static struct dom_tree_handler taxtable_handlers_v2[] =

View File

@ -49,9 +49,6 @@
const gchar *transaction_version_string = "2.0.0"; const gchar *transaction_version_string = "2.0.0";
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
static void static void
add_gnc_num(xmlNodePtr node, const gchar *tag, gnc_numeric num) add_gnc_num(xmlNodePtr node, const gchar *tag, gnc_numeric num)
{ {
@ -130,15 +127,9 @@ split_to_dom_tree(const gchar *tag, Split *spl)
gnc_lot_get_guid(lot))); gnc_lot_get_guid(lot)));
} }
} }
{ /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlNodePtr kvpnode = kvp_frame_to_dom_tree("split:slots", xmlAddChild(ret, qof_instance_slots_to_dom_tree("split:slots",
qof_instance_get_slots (QOF_INSTANCE (spl))); QOF_INSTANCE(spl)));
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
return ret; return ret;
} }
@ -193,14 +184,9 @@ gnc_transaction_dom_tree_create(Transaction *trn)
} }
g_free (str); g_free (str);
{ /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlNodePtr kvpnode = kvp_frame_to_dom_tree("trn:slots", xmlAddChild(ret, qof_instance_slots_to_dom_tree("trn:slots",
qof_instance_get_slots (QOF_INSTANCE (trn))); QOF_INSTANCE(trn)));
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
add_trans_splits(ret, trn); add_trans_splits(ret, trn);
@ -370,8 +356,8 @@ spl_slots_handler(xmlNodePtr node, gpointer data)
struct split_pdata *pdata = data; struct split_pdata *pdata = data;
gboolean successful; gboolean successful;
successful = dom_tree_to_kvp_frame_given(node, successful = dom_tree_create_instance_slots(node,
qof_instance_get_slots (QOF_INSTANCE (pdata->split))); QOF_INSTANCE (pdata->split));
g_return_val_if_fail(successful, FALSE); g_return_val_if_fail(successful, FALSE);
return TRUE; return TRUE;
@ -530,7 +516,7 @@ trn_slots_handler(xmlNodePtr node, gpointer trans_pdata)
Transaction *trn = pdata->trans; Transaction *trn = pdata->trans;
gboolean successful; gboolean successful;
successful = dom_tree_to_kvp_frame_given(node, qof_instance_get_slots (QOF_INSTANCE (trn))); successful = dom_tree_create_instance_slots(node, QOF_INSTANCE (trn));
g_return_val_if_fail(successful, FALSE); g_return_val_if_fail(successful, FALSE);

View File

@ -73,7 +73,7 @@ const gchar *vendor_version_string = "2.0.0";
static xmlNodePtr static xmlNodePtr
vendor_dom_tree_create (GncVendor *vendor) vendor_dom_tree_create (GncVendor *vendor)
{ {
xmlNodePtr ret, kvpnode; xmlNodePtr ret;
GncBillTerm *term; GncBillTerm *term;
GncTaxTable *taxtable; GncTaxTable *taxtable;
@ -118,10 +118,9 @@ vendor_dom_tree_create (GncVendor *vendor)
xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string, xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
qof_instance_get_guid(QOF_INSTANCE(taxtable)))); qof_instance_get_guid(QOF_INSTANCE(taxtable))));
kvpnode = kvp_frame_to_dom_tree (vendor_slots_string, /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
qof_instance_get_slots (QOF_INSTANCE(vendor))); xmlAddChild(ret, qof_instance_slots_to_dom_tree(vendor_slots_string,
if (kvpnode) xmlAddChild (ret, kvpnode); QOF_INSTANCE(vendor)));
return ret; return ret;
} }
@ -313,8 +312,7 @@ static gboolean
vendor_slots_handler (xmlNodePtr node, gpointer vendor_pdata) vendor_slots_handler (xmlNodePtr node, gpointer vendor_pdata)
{ {
struct vendor_pdata *pdata = vendor_pdata; struct vendor_pdata *pdata = vendor_pdata;
return dom_tree_to_kvp_frame_given ( return dom_tree_create_instance_slots(node, QOF_INSTANCE(pdata->vendor));
node, qof_instance_get_slots (QOF_INSTANCE(pdata->vendor)));
} }

View File

@ -24,7 +24,8 @@
* Boston, MA 02110-1301, USA gnu@gnu.org * * Boston, MA 02110-1301, USA gnu@gnu.org *
* * * *
*******************************************************************/ *******************************************************************/
extern "C"
{
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
@ -32,16 +33,16 @@
#include <glib.h> #include <glib.h>
#include "gnc-xml-helper.h" #include <gnc-xml-helper.h>
#include "Account.h" #include <Account.h>
#include "AccountP.h" #include <AccountP.h>
#include "Query.h" #include <Query.h>
#include "Scrub.h" #include <Scrub.h>
#include "Transaction.h" #include <Transaction.h>
#include "TransactionP.h" #include <TransactionP.h>
#include "TransLog.h" #include <TransLog.h>
#include "gnc-pricedb.h" #include <gnc-pricedb.h>
#include "gnc-pricedb-p.h" #include <gnc-pricedb-p.h>
#include "io-gncxml.h" #include "io-gncxml.h"
#include "sixtp.h" #include "sixtp.h"
@ -49,6 +50,8 @@
#include "sixtp-stack.h" #include "sixtp-stack.h"
#include "sixtp-parsers.h" #include "sixtp-parsers.h"
#include "sixtp-utils.h" #include "sixtp-utils.h"
}
#include <kvp_frame.hpp>
/* from Transaction-xml-parser-v1.c */ /* from Transaction-xml-parser-v1.c */
static sixtp* gnc_transaction_parser_new(void); static sixtp* gnc_transaction_parser_new(void);
@ -435,8 +438,8 @@ gnc_is_xml_data_file(const gchar *filename)
static void static void
kvp_value_result_cleanup(sixtp_child_result *cr) kvp_value_result_cleanup(sixtp_child_result *cr)
{ {
KvpValue *v = (KvpValue *) cr->data;; KvpValue *v = static_cast<KvpValue*>(cr->data);
if (v) kvp_value_delete(v); if (v) delete v;
} }
static sixtp* static sixtp*
@ -486,7 +489,7 @@ simple_kvp_value_parser_new(sixtp_end_handler end_handler)
g_free(txt); \ g_free(txt); \
g_return_val_if_fail(ok, FALSE); \ g_return_val_if_fail(ok, FALSE); \
\ \
kvpv = kvp_value_new_##TYPE(val); \ kvpv = new KvpValue{val}; \
g_return_val_if_fail(kvpv, FALSE); \ g_return_val_if_fail(kvpv, FALSE); \
\ \
*result = kvpv; \ *result = kvpv; \
@ -564,7 +567,7 @@ string_kvp_value_end_handler(gpointer data_for_children,
txt = concatenate_child_result_chars(data_from_children); txt = concatenate_child_result_chars(data_from_children);
g_return_val_if_fail(txt, FALSE); g_return_val_if_fail(txt, FALSE);
kvpv = kvp_value_new_string(txt); kvpv = new KvpValue{g_strdup(txt)};
g_free(txt); g_free(txt);
g_return_val_if_fail(kvpv, FALSE); g_return_val_if_fail(kvpv, FALSE);
@ -602,7 +605,7 @@ guid_kvp_value_end_handler(gpointer data_for_children,
g_return_val_if_fail(ok, FALSE); g_return_val_if_fail(ok, FALSE);
kvpv = kvp_value_new_guid(&val); kvpv = new KvpValue{guid_copy(&val)};
g_return_val_if_fail(kvpv, FALSE); g_return_val_if_fail(kvpv, FALSE);
*result = kvpv; *result = kvpv;
@ -657,11 +660,10 @@ glist_kvp_value_end_handler(gpointer data_for_children,
cr->should_cleanup = FALSE; cr->should_cleanup = FALSE;
} }
kvp_result = kvp_value_new_glist_nc(result_glist); kvp_result = new KvpValue{result_glist};
if (!kvp_result) if (!kvp_result)
{ g_list_free_full(result_glist,
kvp_glist_delete(result_glist); [](void* data){ delete static_cast<KvpValue*>(data);});
}
*result = kvp_result; *result = kvp_result;
return(TRUE); return(TRUE);
} }
@ -787,13 +789,13 @@ kvp_frame_slot_end_handler(gpointer data_for_children,
{ {
if (is_child_result_from_node_named(cr, "frame")) if (is_child_result_from_node_named(cr, "frame"))
{ {
KvpFrame *frame = cr->data; KvpFrame *frame = static_cast<KvpFrame*>(cr->data);
value = kvp_value_new_frame (frame); value = new KvpValue{frame};
delete_value = TRUE; delete_value = TRUE;
} }
else else
{ {
value = cr->data; value = static_cast<KvpValue*>(cr->data);
delete_value = FALSE; delete_value = FALSE;
} }
@ -804,9 +806,9 @@ kvp_frame_slot_end_handler(gpointer data_for_children,
if (key_node_count != 1) return(FALSE); if (key_node_count != 1) return(FALSE);
value_cr->should_cleanup = TRUE; value_cr->should_cleanup = TRUE;
kvp_frame_set_slot(f, key, value); f->set(key, value);
if (delete_value) if (delete_value)
kvp_value_delete (value); delete value;
return(TRUE); return(TRUE);
} }
@ -877,8 +879,7 @@ kvp_frame_start_handler(GSList* sibling_data, gpointer parent_data,
gpointer global_data, gpointer *data_for_children, gpointer global_data, gpointer *data_for_children,
gpointer *result, const gchar *tag, gchar **attrs) gpointer *result, const gchar *tag, gchar **attrs)
{ {
KvpFrame *f = kvp_frame_new(); auto f = new KvpFrame;
g_return_val_if_fail(f, FALSE);
*data_for_children = f; *data_for_children = f;
return(TRUE); return(TRUE);
} }
@ -889,9 +890,8 @@ kvp_frame_end_handler(gpointer data_for_children,
gpointer parent_data, gpointer global_data, gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag) gpointer *result, const gchar *tag)
{ {
KvpFrame *f = (KvpFrame *) data_for_children; g_return_val_if_fail(data_for_children != NULL, FALSE);
g_return_val_if_fail(f, FALSE); *result = data_for_children;
*result = f;
return(TRUE); return(TRUE);
} }
@ -904,15 +904,15 @@ kvp_frame_fail_handler(gpointer data_for_children,
gpointer *result, gpointer *result,
const gchar *tag) const gchar *tag)
{ {
KvpFrame *f = (KvpFrame *) data_for_children; auto f = static_cast<KvpFrame*>(data_for_children);
if (f) kvp_frame_delete(f); if (f) delete f;
} }
static void static void
kvp_frame_result_cleanup(sixtp_child_result *cr) kvp_frame_result_cleanup(sixtp_child_result *cr)
{ {
KvpFrame *f = (KvpFrame *) cr->data;; auto f = static_cast<KvpFrame*>(cr->data);;
if (f) kvp_frame_delete(f); if (f) delete f;
} }
static sixtp* static sixtp*
@ -1244,9 +1244,9 @@ account_restore_after_child_handler(gpointer data_for_children,
if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE); if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
if (strcmp(child_result->tag, "slots") == 0) if (strcmp(child_result->tag, "slots") == 0)
{ {
KvpFrame *f = (KvpFrame *) child_result->data; auto f = static_cast<KvpFrame*>(child_result->data);
g_return_val_if_fail(f, FALSE); g_return_val_if_fail(f, FALSE);
if (a->inst.kvp_data) kvp_frame_delete(a->inst.kvp_data); if (a->inst.kvp_data) delete a->inst.kvp_data;
a->inst.kvp_data = f; a->inst.kvp_data = f;
child_result->should_cleanup = FALSE; child_result->should_cleanup = FALSE;
} }
@ -1401,7 +1401,7 @@ acc_restore_type_end_handler(gpointer data_for_children,
{ {
Account *acc = (Account *) parent_data; Account *acc = (Account *) parent_data;
gchar *txt = NULL; gchar *txt = NULL;
int type; GNCAccountType type;
gboolean ok; gboolean ok;
g_return_val_if_fail(acc, FALSE); g_return_val_if_fail(acc, FALSE);
@ -2478,9 +2478,9 @@ txn_restore_split_after_child_handler(gpointer data_for_children,
if (strcmp(child_result->tag, "slots") == 0) if (strcmp(child_result->tag, "slots") == 0)
{ {
KvpFrame *f = (KvpFrame *) child_result->data; KvpFrame *f = static_cast<KvpFrame*>(child_result->data);
g_return_val_if_fail(f, FALSE); g_return_val_if_fail(f, FALSE);
if (s->inst.kvp_data) kvp_frame_delete(s->inst.kvp_data); if (s->inst.kvp_data) delete s->inst.kvp_data;
s->inst.kvp_data = f; s->inst.kvp_data = f;
child_result->should_cleanup = FALSE; child_result->should_cleanup = FALSE;
} }

View File

@ -32,6 +32,10 @@
#ifndef IO_GNCXML_H #ifndef IO_GNCXML_H
#define IO_GNCXML_H #define IO_GNCXML_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
#include "qof.h" #include "qof.h"
@ -47,4 +51,7 @@ gboolean qof_session_load_from_xml_file(QofBook *, const char * filename);
*/ */
gboolean gnc_is_xml_data_file(const gchar *name); gboolean gnc_is_xml_data_file(const gchar *name);
#ifdef __cplusplus
}
#endif
#endif /* IO_GNCXML_H */ #endif /* IO_GNCXML_H */

View File

@ -20,7 +20,8 @@
* Boston, MA 02110-1301, USA gnu@gnu.org * * Boston, MA 02110-1301, USA gnu@gnu.org *
* * * *
********************************************************************/ ********************************************************************/
extern "C"
{
#define __EXTENSIONS__ #define __EXTENSIONS__
#include "config.h" #include "config.h"
@ -31,6 +32,9 @@
#include "sixtp-dom-generators.h" #include "sixtp-dom-generators.h"
#include "sixtp-utils.h" #include "sixtp-utils.h"
}
#include <kvp_frame.hpp>
static QofLogModule log_module = GNC_MOD_IO; static QofLogModule log_module = GNC_MOD_IO;
@ -237,124 +241,113 @@ double_to_string(double value)
} }
static void static void
add_text_to_node(xmlNodePtr node, gchar *type, gchar *val) add_text_to_node(xmlNodePtr node, const gchar *type, gchar *val)
{ {
gchar *newtype = g_strdup (type); gchar *newtype = g_strdup (type);
gchar *newval = g_strdup (val); gchar *newval = g_strdup (val);
xmlSetProp(node, BAD_CAST "type", checked_char_cast (type)); xmlSetProp(node, BAD_CAST "type", BAD_CAST type);
xmlNodeSetContent(node, checked_char_cast (val)); xmlNodeSetContent(node, checked_char_cast (val));
g_free (newtype); g_free (newtype);
g_free(newval); g_free(newval);
} }
static void static void add_kvp_slot(const char * key, KvpValue* value, void* data);
add_kvp_slot(const char * key, KvpValue* value, xmlNodePtr node);
static void static void
add_kvp_value_node(xmlNodePtr node, gchar *tag, KvpValue* val) add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val)
{ {
xmlNodePtr val_node; xmlNodePtr val_node;
kvp_value_t kvp_type;
kvp_type = kvp_value_get_type(val); switch (val->get_type())
if (kvp_type == KVP_TYPE_STRING)
{ {
gchar *newstr = g_strdup (kvp_value_get_string(val)); case KvpValue::Type::STRING:
{
auto newstr = g_strdup(val->get<const char*>());
val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, val_node = xmlNewTextChild(node, NULL, BAD_CAST tag,
checked_char_cast (newstr)); checked_char_cast (newstr));
g_free (newstr); g_free (newstr);
break;
} }
else if (kvp_type == KVP_TYPE_TIMESPEC) case KvpValue::Type::TIMESPEC:
val_node = NULL; val_node = NULL;
else if (kvp_type == KVP_TYPE_GDATE) break;
case KvpValue::Type::GDATE:
{ {
GDate d = kvp_value_get_gdate(val); auto d = val->get<GDate>();
val_node = gdate_to_dom_tree(tag, &d); val_node = gdate_to_dom_tree(tag, &d);
xmlAddChild (node, val_node); xmlAddChild (node, val_node);
break;
} }
else default:
val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL); val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL);
break;
}
switch (kvp_value_get_type(val)) switch (val->get_type())
{ {
case KVP_TYPE_GINT64: case KvpValue::Type::INT64:
add_text_to_node(val_node, "integer", add_text_to_node(val_node, "integer",
g_strdup_printf("%" G_GINT64_FORMAT, g_strdup_printf("%" G_GINT64_FORMAT,
kvp_value_get_gint64(val))); val->get<int64_t>()));
break; break;
case KVP_TYPE_DOUBLE: case KvpValue::Type::DOUBLE:
add_text_to_node(val_node, "double", add_text_to_node(val_node, "double",
double_to_string(kvp_value_get_double(val))); double_to_string(val->get<double>()));
break; break;
case KVP_TYPE_NUMERIC: case KvpValue::Type::NUMERIC:
add_text_to_node(val_node, "numeric", add_text_to_node(val_node, "numeric",
gnc_numeric_to_string(kvp_value_get_numeric(val))); gnc_numeric_to_string(val->get<gnc_numeric>()));
break; break;
case KVP_TYPE_STRING: case KvpValue::Type::STRING:
xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string"); xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string");
break; break;
case KVP_TYPE_GUID: case KvpValue::Type::GUID:
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1]; gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(kvp_value_get_guid(val), guidstr); guid_to_string_buff(val->get<GncGUID*>(), guidstr);
add_text_to_node(val_node, "guid", guidstr); add_text_to_node(val_node, "guid", guidstr);
break; break;
} }
case KVP_TYPE_TIMESPEC: case KvpValue::Type::TIMESPEC:
{ {
Timespec ts = kvp_value_get_timespec (val); auto ts = val->get<Timespec>();
val_node = timespec_to_dom_tree (tag, &ts); val_node = timespec_to_dom_tree (tag, &ts);
xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec"); xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
xmlAddChild (node, val_node); xmlAddChild (node, val_node);
break;
} }
break; case KvpValue::Type::GDATE:
case KVP_TYPE_GDATE:
xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "gdate"); xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "gdate");
break; break;
case KVP_TYPE_GLIST: case KvpValue::Type::GLIST:
{
GList *cursor;
xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list"); xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list");
for (cursor = kvp_value_get_glist(val); cursor; cursor = cursor->next) for (auto cursor = val->get<GList*>(); cursor; cursor = cursor->next)
{ {
KvpValue *val = (KvpValue*)cursor->data; auto val = static_cast<KvpValue*>(cursor->data);
add_kvp_value_node(val_node, "slot:value", val); add_kvp_value_node(val_node, "slot:value", val);
} }
} break;
case KvpValue::Type::FRAME:
break;
case KVP_TYPE_FRAME:
{ {
KvpFrame *frame;
const char ** keys;
unsigned int i;
xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "frame"); xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "frame");
frame = kvp_value_get_frame (val); auto frame = val->get<KvpFrame*>();
if (!frame) if (!frame)
break; break;
frame->for_each_slot(add_kvp_slot, static_cast<void*>(val_node));
keys = kvp_frame_get_keys(frame); break;
for (i = 0; keys[i]; ++i)
add_kvp_slot(keys[i], kvp_frame_get_value(frame, keys[i]), val_node);
g_free(keys);
} }
break;
default: default:
break; break;
} }
} }
static void static void
add_kvp_slot(const char * key, KvpValue* value, xmlNodePtr node) add_kvp_slot(const char * key, KvpValue* value, void* data)
{ {
xmlNodePtr slot_node; auto newkey = g_strdup ((gchar*)key);
gchar *newkey = g_strdup ((gchar*)key); auto node = static_cast<xmlNodePtr>(data);
slot_node = xmlNewChild(node, NULL, BAD_CAST "slot", NULL); auto slot_node = xmlNewChild(node, NULL, BAD_CAST "slot", NULL);
xmlNewTextChild(slot_node, NULL, BAD_CAST "slot:key", xmlNewTextChild(slot_node, NULL, BAD_CAST "slot:key",
checked_char_cast (newkey)); checked_char_cast (newkey));
@ -363,24 +356,17 @@ add_kvp_slot(const char * key, KvpValue* value, xmlNodePtr node)
} }
xmlNodePtr xmlNodePtr
kvp_frame_to_dom_tree(const char *tag, const KvpFrame *frame) qof_instance_slots_to_dom_tree(const char *tag, const QofInstance* inst)
{ {
xmlNodePtr ret; xmlNodePtr ret;
const char ** keys; const char ** keys;
unsigned int i; unsigned int i;
KvpFrame *frame = qof_instance_get_slots(inst);
if (!frame) if (!frame)
{ return nullptr;
return NULL;
}
ret = xmlNewNode(NULL, BAD_CAST tag);
keys = kvp_frame_get_keys(frame);
for (i = 0; keys[i]; ++i)
add_kvp_slot(keys[i], kvp_frame_get_value(frame, keys[i]), ret);
g_free(keys);
ret = xmlNewNode(nullptr, BAD_CAST tag);
frame->for_each_slot(add_kvp_slot, static_cast<void*>(ret));
return ret; return ret;
} }

View File

@ -24,6 +24,10 @@
#ifndef SIXTP_DOM_GENERATORS_H #ifndef SIXTP_DOM_GENERATORS_H
#define SIXTP_DOM_GENERATORS_H #define SIXTP_DOM_GENERATORS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
#include "gnc-xml-helper.h" #include "gnc-xml-helper.h"
@ -43,10 +47,14 @@ gchar * timespec_nsec_to_string(const Timespec *ts);
gchar * timespec_sec_to_string(const Timespec *ts); gchar * timespec_sec_to_string(const Timespec *ts);
xmlNodePtr gdate_to_dom_tree(const char *tag, const GDate *spec); xmlNodePtr gdate_to_dom_tree(const char *tag, const GDate *spec);
xmlNodePtr gnc_numeric_to_dom_tree(const char *tag, const gnc_numeric *num); xmlNodePtr gnc_numeric_to_dom_tree(const char *tag, const gnc_numeric *num);
xmlNodePtr kvp_frame_to_dom_tree(const char *tag, const KvpFrame *frame); xmlNodePtr qof_instance_slots_to_dom_tree(const char *tag,
const QofInstance *inst);
xmlNodePtr guint_to_dom_tree(const char *tag, guint an_int); xmlNodePtr guint_to_dom_tree(const char *tag, guint an_int);
xmlNodePtr recurrence_to_dom_tree(const gchar *tag, const Recurrence *r); xmlNodePtr recurrence_to_dom_tree(const gchar *tag, const Recurrence *r);
gchar* double_to_string(double value); gchar* double_to_string(double value);
#ifdef __cplusplus
}
#endif
#endif /* _SIXTP_DOM_GENERATORS_H_ */ #endif /* _SIXTP_DOM_GENERATORS_H_ */

View File

@ -20,16 +20,20 @@
* Boston, MA 02110-1301, USA gnu@gnu.org * * Boston, MA 02110-1301, USA gnu@gnu.org *
* * * *
********************************************************************/ ********************************************************************/
extern "C"
{
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include "gnc-xml-helper.h" #include "gnc-xml-helper.h"
#include "gnc-engine.h" #include <gnc-engine.h>
#include "sixtp-utils.h" #include "sixtp-utils.h"
#include "sixtp-dom-parsers.h" #include "sixtp-dom-parsers.h"
}
#include <kvp_frame.hpp>
static QofLogModule log_module = GNC_MOD_IO; static QofLogModule log_module = GNC_MOD_IO;
@ -57,7 +61,7 @@ dom_tree_to_guid(xmlNodePtr node)
/* handle new and guid the same for the moment */ /* handle new and guid the same for the moment */
if ((g_strcmp0("guid", type) == 0) || (g_strcmp0("new", type) == 0)) if ((g_strcmp0("guid", type) == 0) || (g_strcmp0("new", type) == 0))
{ {
GncGUID *gid = g_new(GncGUID, 1); auto gid = guid_new();
char *guid_str; char *guid_str;
guid_str = (char*)xmlNodeGetContent (node->xmlChildrenNode); guid_str = (char*)xmlNodeGetContent (node->xmlChildrenNode);
@ -78,7 +82,7 @@ dom_tree_to_guid(xmlNodePtr node)
} }
} }
KvpValue* static KvpValue*
dom_tree_to_integer_kvp_value(xmlNodePtr node) dom_tree_to_integer_kvp_value(xmlNodePtr node)
{ {
gchar *text; gchar *text;
@ -89,7 +93,7 @@ dom_tree_to_integer_kvp_value(xmlNodePtr node)
if (string_to_gint64(text, &daint)) if (string_to_gint64(text, &daint))
{ {
ret = kvp_value_new_gint64(daint); ret = new KvpValue{daint};
} }
g_free(text); g_free(text);
@ -161,7 +165,7 @@ dom_tree_to_boolean(xmlNodePtr node, gboolean* b)
} }
} }
KvpValue* static KvpValue*
dom_tree_to_double_kvp_value(xmlNodePtr node) dom_tree_to_double_kvp_value(xmlNodePtr node)
{ {
gchar *text; gchar *text;
@ -172,7 +176,7 @@ dom_tree_to_double_kvp_value(xmlNodePtr node)
if (string_to_double(text, &dadoub)) if (string_to_double(text, &dadoub))
{ {
ret = kvp_value_new_double(dadoub); ret = new KvpValue{dadoub};
} }
g_free(text); g_free(text);
@ -180,7 +184,7 @@ dom_tree_to_double_kvp_value(xmlNodePtr node)
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_numeric_kvp_value(xmlNodePtr node) dom_tree_to_numeric_kvp_value(xmlNodePtr node)
{ {
gnc_numeric *danum; gnc_numeric *danum;
@ -190,7 +194,7 @@ dom_tree_to_numeric_kvp_value(xmlNodePtr node)
if (danum) if (danum)
{ {
ret = kvp_value_new_gnc_numeric(*danum); ret = new KvpValue{*danum};
} }
g_free(danum); g_free(danum);
@ -198,7 +202,7 @@ dom_tree_to_numeric_kvp_value(xmlNodePtr node)
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_string_kvp_value(xmlNodePtr node) dom_tree_to_string_kvp_value(xmlNodePtr node)
{ {
gchar *datext; gchar *datext;
@ -207,15 +211,13 @@ dom_tree_to_string_kvp_value(xmlNodePtr node)
datext = dom_tree_to_text(node); datext = dom_tree_to_text(node);
if (datext) if (datext)
{ {
ret = kvp_value_new_string(datext); ret = new KvpValue{datext};
} }
g_free(datext);
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_guid_kvp_value(xmlNodePtr node) dom_tree_to_guid_kvp_value(xmlNodePtr node)
{ {
GncGUID *daguid; GncGUID *daguid;
@ -224,29 +226,24 @@ dom_tree_to_guid_kvp_value(xmlNodePtr node)
daguid = dom_tree_to_guid(node); daguid = dom_tree_to_guid(node);
if (daguid) if (daguid)
{ {
ret = kvp_value_new_guid(daguid); ret = new KvpValue{daguid};
} }
g_free(daguid);
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_timespec_kvp_value (xmlNodePtr node) dom_tree_to_timespec_kvp_value (xmlNodePtr node)
{ {
Timespec ts; Timespec ts;
KvpValue * ret = NULL; KvpValue * ret = nullptr;
ts = dom_tree_to_timespec (node); ts = dom_tree_to_timespec (node);
if (ts.tv_sec || ts.tv_nsec) ret = new KvpValue{ts};
{
ret = kvp_value_new_timespec (ts);
}
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_gdate_kvp_value (xmlNodePtr node) dom_tree_to_gdate_kvp_value (xmlNodePtr node)
{ {
GDate *date; GDate *date;
@ -256,7 +253,7 @@ dom_tree_to_gdate_kvp_value (xmlNodePtr node)
if (date) if (date)
{ {
ret = kvp_value_new_gdate(*date); ret = new KvpValue{*date};
} }
g_free(date); g_free(date);
@ -303,7 +300,14 @@ string_to_binary(const gchar *str, void **v, guint64 *data_len)
return(TRUE); return(TRUE);
} }
KvpValue* static KvpValue* dom_tree_to_kvp_value(xmlNodePtr node);
//needed for test access as well as internal use.
extern "C"
{
KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node);
}
static KvpValue*
dom_tree_to_list_kvp_value(xmlNodePtr node) dom_tree_to_list_kvp_value(xmlNodePtr node)
{ {
GList *list = NULL; GList *list = NULL;
@ -324,12 +328,12 @@ dom_tree_to_list_kvp_value(xmlNodePtr node)
} }
} }
ret = kvp_value_new_glist_nc(list); ret = new KvpValue{list};
return ret; return ret;
} }
KvpValue* static KvpValue*
dom_tree_to_frame_kvp_value(xmlNodePtr node) dom_tree_to_frame_kvp_value(xmlNodePtr node)
{ {
KvpFrame *frame; KvpFrame *frame;
@ -339,18 +343,16 @@ dom_tree_to_frame_kvp_value(xmlNodePtr node)
if (frame) if (frame)
{ {
ret = kvp_value_new_frame(frame); ret = new KvpValue{frame};
} }
kvp_frame_delete(frame);
return ret; return ret;
} }
struct kvp_val_converter struct kvp_val_converter
{ {
gchar *tag; const gchar *tag;
KvpValue* (*converter)(xmlNodePtr node); KvpValue* (*converter)(xmlNodePtr node);
}; };
@ -368,7 +370,7 @@ struct kvp_val_converter val_converters[] =
{ 0, 0 }, { 0, 0 },
}; };
KvpValue* static KvpValue*
dom_tree_to_kvp_value(xmlNodePtr node) dom_tree_to_kvp_value(xmlNodePtr node)
{ {
xmlChar *xml_type; xmlChar *xml_type;
@ -403,7 +405,7 @@ dom_tree_to_kvp_value(xmlNodePtr node)
return ret; return ret;
} }
gboolean static gboolean
dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame) dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
{ {
xmlNodePtr mark; xmlNodePtr mark;
@ -440,7 +442,8 @@ dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
{ {
if (val) if (val)
{ {
kvp_frame_set_slot_nc(frame, key, val); //We're deleting the old KvpValue returned by replace_nc().
delete frame->set(key, val);
} }
else else
{ {
@ -458,20 +461,23 @@ dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
KvpFrame* KvpFrame*
dom_tree_to_kvp_frame(xmlNodePtr node) dom_tree_to_kvp_frame(xmlNodePtr node)
{ {
KvpFrame *ret;
g_return_val_if_fail(node, NULL); g_return_val_if_fail(node, NULL);
ret = kvp_frame_new(); auto ret = new KvpFrame;
if (dom_tree_to_kvp_frame_given(node, ret)) if (dom_tree_to_kvp_frame_given(node, ret))
return ret; return ret;
kvp_frame_delete(ret); delete ret;
return NULL; return NULL;
} }
gboolean
dom_tree_create_instance_slots(xmlNodePtr node, QofInstance *inst)
{
KvpFrame *frame = qof_instance_get_slots(inst);
return dom_tree_to_kvp_frame_given(node, frame);
}
gchar * gchar *
dom_tree_to_text(xmlNodePtr tree) dom_tree_to_text(xmlNodePtr tree)
@ -683,7 +689,8 @@ dom_tree_to_gdate(xmlNodePtr node)
} }
g_free(content); g_free(content);
seen_date = TRUE; seen_date = TRUE;
g_date_set_dmy( ret, day, month, year ); g_date_set_dmy( ret, day, static_cast<GDateMonth>(month),
year );
if ( !g_date_valid( ret ) ) if ( !g_date_valid( ret ) )
{ {
PWARN("invalid date"); PWARN("invalid date");

View File

@ -23,6 +23,10 @@
#ifndef SIXTP_DOM_PARSERS_H #ifndef SIXTP_DOM_PARSERS_H
#define SIXTP_DOM_PARSERS_H #define SIXTP_DOM_PARSERS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
@ -46,21 +50,7 @@ GDate* dom_tree_to_gdate(xmlNodePtr node);
gnc_numeric* dom_tree_to_gnc_numeric(xmlNodePtr node); gnc_numeric* dom_tree_to_gnc_numeric(xmlNodePtr node);
gchar * dom_tree_to_text(xmlNodePtr tree); gchar * dom_tree_to_text(xmlNodePtr tree);
gboolean string_to_binary(const gchar *str, void **v, guint64 *data_len); gboolean string_to_binary(const gchar *str, void **v, guint64 *data_len);
gboolean dom_tree_create_instance_slots(xmlNodePtr node, QofInstance *inst);
gboolean dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame);
KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node);
KvpValue* dom_tree_to_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_integer_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_double_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_numeric_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_string_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_guid_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_timespec_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_binary_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_list_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_frame_kvp_value(xmlNodePtr node);
KvpValue* dom_tree_to_gdate_kvp_value (xmlNodePtr node);
gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint); gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint);
gboolean dom_tree_to_guint16(xmlNodePtr node, guint16 *i); gboolean dom_tree_to_guint16(xmlNodePtr node, guint16 *i);
@ -88,5 +78,7 @@ gboolean dom_tree_generic_parse(xmlNodePtr node,
struct dom_tree_handler *handlers, struct dom_tree_handler *handlers,
gpointer data); gpointer data);
#ifdef __cplusplus
}
#endif
#endif /* _SIXTP_DOM_PARSERS_H_ */ #endif /* _SIXTP_DOM_PARSERS_H_ */

View File

@ -2,8 +2,8 @@
SUBDIRS = test-files SUBDIRS = test-files
test_date_converting_SOURCES = \ test_date_converting_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -12,8 +12,8 @@ test_date_converting_SOURCES = \
test-date-converting.c test-date-converting.c
test_dom_converters1_SOURCES = \ test_dom_converters1_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -22,22 +22,22 @@ test_dom_converters1_SOURCES = \
test-dom-converters1.c test-dom-converters1.c
test_kvp_frames_SOURCES = \ test_kvp_frames_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
${top_srcdir}/src/backend/xml/sixtp-to-dom-parser.c \ ${top_srcdir}/src/backend/xml/sixtp-to-dom-parser.c \
${top_srcdir}/src/backend/xml/gnc-xml-helper.c \ ${top_srcdir}/src/backend/xml/gnc-xml-helper.c \
test-kvp-frames.c test-kvp-frames.cpp
# the xml backend is now a GModule - this test does # the xml backend is now a GModule - this test does
# not load it as a module and cannot link to it # not load it as a module and cannot link to it
# and remain portable. # and remain portable.
test_load_example_account_SOURCES = \ test_load_example_account_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -60,8 +60,8 @@ test_load_example_account_SOURCES = \
test-load-example-account.c test-load-example-account.c
test_string_converters_SOURCES = \ test_string_converters_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -70,8 +70,8 @@ test_string_converters_SOURCES = \
test-string-converters.c test-string-converters.c
test_xml_account_SOURCES = \ test_xml_account_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -93,8 +93,8 @@ test_xml_account_SOURCES = \
test-xml-account.c test-xml-account.c
test_xml_commodity_SOURCES = \ test_xml_commodity_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -116,8 +116,8 @@ test_xml_commodity_SOURCES = \
test-xml-commodity.c test-xml-commodity.c
test_xml_pricedb_SOURCES = \ test_xml_pricedb_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -139,8 +139,8 @@ test_xml_pricedb_SOURCES = \
test-xml-pricedb.c test-xml-pricedb.c
test_xml_transaction_SOURCES = \ test_xml_transaction_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -162,8 +162,8 @@ test_xml_transaction_SOURCES = \
test-xml-transaction.c test-xml-transaction.c
test_xml2_is_file_SOURCES = \ test_xml2_is_file_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \ ${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \ ${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \ ${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -221,7 +221,7 @@ TESTS_ENVIRONMENT = \
check_LTLIBRARIES = libgnc-test-file-stuff.la check_LTLIBRARIES = libgnc-test-file-stuff.la
libgnc_test_file_stuff_la_SOURCES = test-file-stuff.c libgnc_test_file_stuff_la_SOURCES = test-file-stuff.cpp
libgnc_test_file_stuff_la_LIBADD = \ libgnc_test_file_stuff_la_LIBADD = \
${top_builddir}/src/engine/libgncmod-engine.la ${top_builddir}/src/engine/libgncmod-engine.la

View File

@ -20,7 +20,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA. * 02110-1301, USA.
*/ */
#include <kvp_frame.hpp>
extern "C"
{
#include "config.h" #include "config.h"
#include <unistd.h> #include <unistd.h>
@ -40,12 +43,14 @@
#include "test-stuff.h" #include "test-stuff.h"
#include "io-gncxml-gen.h" #include "io-gncxml-gen.h"
#include "sixtp-utils.h" #include "sixtp-utils.h"
/* /*
#define __DEBUG 1 #define __DEBUG 1
*/ */
/***********************************************************************/ /***********************************************************************/
extern KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node);
}
static int static int
files_return(int ret, const char* msg) files_return(int ret, const char* msg)
{ {
@ -107,7 +112,7 @@ print_dom_tree(gpointer data_for_children, GSList* data_from_children,
if (parent_data == NULL) if (parent_data == NULL)
{ {
xmlElemDump((FILE*)global_data, NULL, (xmlNodePtr)data_for_children); xmlElemDump((FILE*)global_data, NULL, (xmlNodePtr)data_for_children);
xmlFreeNode(data_for_children); xmlFreeNode(static_cast<xmlNodePtr>(data_for_children));
} }
return TRUE; return TRUE;
} }
@ -250,25 +255,22 @@ equals_node_val_vs_kvp_frame(xmlNodePtr node, const KvpFrame *frm)
g_return_val_if_fail(cmpfrm, FALSE); g_return_val_if_fail(cmpfrm, FALSE);
if (kvp_frame_compare(frm, cmpfrm) == 0) if (compare(frm, cmpfrm) == 0)
{ {
kvp_frame_delete(cmpfrm); delete cmpfrm;
return TRUE; return TRUE;
} }
else else
{ {
gchar *frm1str; auto frm1str = g_strdup(frm->to_string().c_str());
gchar *frm2str; auto frm2str = g_strdup(cmpfrm->to_string().c_str());
frm1str = kvp_frame_to_string(frm);
frm2str = kvp_frame_to_string(cmpfrm);
printf("%s vs %s\n", frm1str, frm2str); printf("%s vs %s\n", frm1str, frm2str);
g_free(frm1str); g_free(frm1str);
g_free(frm2str); g_free(frm2str);
kvp_frame_delete(cmpfrm); delete cmpfrm;
return FALSE; return FALSE;
} }
} }

View File

@ -4,16 +4,19 @@
#ifndef TEST_FILE_STUFF_H #ifndef TEST_FILE_STUFF_H
#define TEST_FILE_STUFF_H #define TEST_FILE_STUFF_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
#include "gnc-commodity.h" #include <gnc-commodity.h>
#include "gnc-engine.h" #include <gnc-engine.h>
#include "gnc-xml-helper.h" #include <gnc-xml-helper.h>
#include "io-gncxml-gen.h" #include <io-gncxml-gen.h>
#include "sixtp.h" #include <sixtp.h>
typedef struct KvpFrameImpl KvpFrame;
void write_dom_node_to_file(xmlNodePtr node, int fd); void write_dom_node_to_file(xmlNodePtr node, int fd);
@ -39,5 +42,7 @@ void
test_files_in_dir(int argc, char **argv, gxpf_callback cb, test_files_in_dir(int argc, char **argv, gxpf_callback cb,
sixtp *parser, const char *parser_tag, sixtp *parser, const char *parser_tag,
QofBook *book); QofBook *book);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,227 +0,0 @@
#include "config.h"
#include <stdlib.h>
#include "test-stuff.h"
#include "test-engine-stuff.h"
#include "test-file-stuff.h"
#include "qof.h"
#include "sixtp-dom-generators.h"
#include "sixtp-dom-parsers.h"
#define GNC_V2_STRING "gnc-v2"
const gchar *gnc_v2_xml_version_string = GNC_V2_STRING;
static void
test_kvp_get_slot(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
const KvpValue *test_val2;
test_val2 = kvp_frame_get_slot(test_frame1, test_key);
if (kvp_value_compare(test_val1, test_val2) == 0)
{
success_args("kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args("kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run);
tmp = kvp_value_to_string(test_val2);
printf(" Value is %s\n", tmp);
g_free(tmp);
}
}
static void
test_kvp_copy_compare(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
KvpFrame *test_frame2;
test_frame2 = kvp_frame_copy(test_frame1);
do_test_args(test_frame2 != NULL, "kvp_frame_copy",
__FILE__, __LINE__, "run=%d", run);
if (kvp_frame_compare(test_frame1, test_frame2) == 0)
{
success_args("kvp_frame_copy->kvp_frame_compare",
__FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args("kvp_frame_copy->kvp_frame_compare",
__FILE__, __LINE__, "run=%d", run);
tmp = kvp_frame_to_string(test_frame1);
printf("Frame1 is %s\n", tmp);
g_free(tmp);
tmp = kvp_frame_to_string(test_frame2);
printf("Frame2 is %s\n", tmp);
g_free(tmp);
}
kvp_frame_delete(test_frame2);
}
static void
test_kvp_copy_get_slot(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
KvpFrame *test_frame2;
const KvpValue *test_val2;
test_frame2 = kvp_frame_copy(test_frame1);
test_val2 = kvp_frame_get_slot(test_frame2, test_key);
if (kvp_value_compare(test_val1, test_val2) == 0)
{
success_args("kvp_frame_copy->kvp_frame_get_slot",
__FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args("kvp_frame_copy->kvp_frame_get_slot",
__FILE__, __LINE__, "run=%d", run);
tmp = kvp_frame_to_string(test_frame1);
printf("Frame1 is %s\n", tmp);
g_free(tmp);
tmp = kvp_frame_to_string(test_frame2);
printf("Frame2 is %s\n", tmp);
g_free(tmp);
}
kvp_frame_delete(test_frame2);
}
static void
test_kvp_create_delete(void)
{
KvpFrame *test_frame;
test_frame = kvp_frame_new();
if (test_frame != NULL)
{
kvp_frame_delete(test_frame);
test_frame = NULL;
success("kvp_frame_new");
}
else
{
failure("kvp_frame_new");
}
}
static void
test_kvp_frames1(void)
{
int i;
for (i = 0; i < 20; i++)
{
KvpFrame *test_frame1;
gchar *test_key;
KvpValue *test_val1;
test_val1 = get_random_kvp_value(i % KVP_TYPE_FRAME);
test_frame1 = kvp_frame_new();
test_key = get_random_string();
kvp_frame_set_slot(test_frame1, test_key, test_val1);
test_kvp_get_slot(i, test_frame1, test_val1, test_key);
test_kvp_copy_compare(i, test_frame1, test_val1, test_key);
test_kvp_copy_get_slot(i, test_frame1, test_val1, test_key);
kvp_value_delete(test_val1);
g_free(test_key);
kvp_frame_delete(test_frame1);
}
}
static void
test_kvp_printing(void)
{
int i;
for (i = 0; i < 20; i++)
{
KvpFrame *ran_frame;
gchar *char_rep;
ran_frame = get_random_kvp_frame();
char_rep = kvp_frame_to_string(ran_frame);
/* if we don't crash it's good :) */
/* puts(char_rep); */
g_free(char_rep);
kvp_frame_delete(ran_frame);
}
}
static void
test_kvp_xml_stuff(void)
{
int i;
for (i = 0; i < 20; i++)
{
KvpFrame *test_frame1;
KvpFrame *test_frame2;
xmlNodePtr test_node;
test_frame1 = get_random_kvp_frame();
test_node = kvp_frame_to_dom_tree("test-kvp", test_frame1);
if (!test_node)
{
failure_args("xml stuff", __FILE__, __LINE__,
"kvp_frame_to_dom_tree produced NULL");
}
else
{
test_frame2 = dom_tree_to_kvp_frame(test_node);
if (kvp_frame_compare(test_frame1, test_frame2) == 0)
{
success("xml stuff");
}
else
{
gchar *tmp;
failure("xml stuff");
tmp = kvp_frame_to_string(test_frame1);
printf(" with kvp_frame 1:\n%s\n", tmp);
g_free(tmp);
printf(" and xml:\n");
xmlElemDump(stdout, NULL, test_node);
printf("\n");
tmp = kvp_frame_to_string(test_frame2);
printf(" and kvp_frame 2:\n%s\n", tmp);
g_free(tmp);
}
kvp_frame_delete(test_frame2);
xmlFreeNode(test_node);
}
kvp_frame_delete(test_frame1);
}
}
int
main(int argc, char** argv)
{
qof_init();
test_kvp_create_delete();
test_kvp_printing();
test_kvp_frames1();
test_kvp_xml_stuff();
print_test_results();
exit(get_rv());
}

View File

@ -0,0 +1,196 @@
#include <kvp_frame.hpp>
extern "C"
{
#include "config.h"
#include <stdlib.h>
#include "test-stuff.h"
#include "test-engine-stuff.h"
#include "test-file-stuff.h"
#include "qof.h"
#include "sixtp-dom-generators.h"
#include "sixtp-dom-parsers.h"
#define GNC_V2_STRING "gnc-v2"
const gchar *gnc_v2_xml_version_string = GNC_V2_STRING;
extern KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node);
}
static void
test_kvp_get_slot(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
auto test_val2 = test_frame1->get_slot(test_key);
auto msg = "KvpFrame::get_slot";
if (compare(test_val1, test_val2) == 0)
{
success_args(msg, __FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args(msg, __FILE__, __LINE__, "run=%d", run);
printf(" Value is %s\n", test_val2->to_string());
}
}
static void
test_kvp_copy_compare(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
auto test_frame2 = new KvpFrame(*test_frame1);
auto msg = "compare after KvpFrame copy construction";
do_test_args(test_frame2 != NULL, "KvpFrame Copy Constructor",
__FILE__, __LINE__, "run=%d", run);
if (compare(test_frame1, test_frame2) == 0)
{
success_args(msg, __FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args(msg, __FILE__, __LINE__, "run=%d", run);
printf("Frame1 is %s\n", test_frame1->to_string().c_str());
printf("Frame2 is %s\n",test_frame2->to_string().c_str());
}
delete test_frame2;
}
static void
test_kvp_copy_get_slot(int run,
KvpFrame *test_frame1, const KvpValue *test_val1,
const gchar *test_key)
{
auto test_frame2 = new KvpFrame(*test_frame1);
auto test_val2 = test_frame2->get_slot(test_key);
auto msg = "KvpFrame::get_slot() from a copy-constructed frame";
if (compare(test_val1, test_val2) == 0)
{
success_args(msg, __FILE__, __LINE__, "run=%d", run);
}
else
{
gchar *tmp;
failure_args(msg, __FILE__, __LINE__, "run=%d", run);
printf("Frame1 is %s\n", test_frame1->to_string().c_str());
printf("Frame2 is %s\n", test_frame2->to_string().c_str());
}
delete test_frame2;
}
static void
test_kvp_create_delete(void)
{
auto test_frame = new KvpFrame;
auto msg = "KvpFrame default constructor";
if (test_frame != nullptr)
{
delete test_frame;
test_frame = nullptr;
success(msg);
}
else
{
failure(msg);
}
}
static void
test_kvp_frames1(void)
{
int i;
for (i = 0; i < 20; i++)
{
auto test_val1 = get_random_kvp_value(i % KvpValue::Type::FRAME);
auto test_frame1 = new KvpFrame;
auto test_key = get_random_string_without("/");
test_frame1->set(test_key, test_val1);
test_kvp_get_slot(i, test_frame1, test_val1, test_key);
test_kvp_copy_compare(i, test_frame1, test_val1, test_key);
test_kvp_copy_get_slot(i, test_frame1, test_val1, test_key);
delete test_val1;
g_free(test_key);
delete test_frame1;
}
}
static void
test_kvp_printing(void)
{
int i;
for (i = 0; i < 20; i++)
{
auto ran_frame = get_random_kvp_frame();
assert(!ran_frame->to_string().empty());
delete ran_frame;
}
}
static void
test_kvp_xml_stuff(void)
{
int i;
for (i = 0; i < 20; i++)
{
auto inst = static_cast<QofInstance *>(g_object_new (QOF_TYPE_INSTANCE, NULL));
KvpFrame *test_frame2;
xmlNodePtr test_node;
inst->kvp_data = get_random_kvp_frame();
auto msg = "XML Stuff";
test_node = qof_instance_slots_to_dom_tree("test-kvp", inst);
if (!test_node)
{
failure_args("xml stuff", __FILE__, __LINE__,
"kvp_frame_to_dom_tree produced NULL");
}
else
{
test_frame2 = dom_tree_to_kvp_frame(test_node);
if (compare(inst->kvp_data, test_frame2) == 0)
{
success(msg);
}
else
{
failure(msg);
printf(" With KvpFrame 1:\n%s\n",
inst->kvp_data->to_string().c_str());
printf(" and XML:\n");
xmlElemDump(stdout, NULL, test_node);
printf("\n and kvp_frame 2:\n%s\n",
test_frame2->to_string().c_str());
}
delete test_frame2;
xmlFreeNode(test_node);
}
g_object_unref (inst);
}
}
int
main(int argc, char** argv)
{
qof_init();
test_kvp_create_delete();
test_kvp_printing();
test_kvp_frames1();
test_kvp_xml_stuff();
print_test_results();
exit(get_rv());
}

View File

@ -124,7 +124,7 @@ gchar *gnc_features_test_unknown (QofBook *book)
g_list_free(features_list); g_list_free(features_list);
return msg; return msg;
} }
g_hash_table_unref (features_used);
return NULL; return NULL;
} }

View File

@ -283,11 +283,6 @@ Plan A has been implemented in the engine. To quickly summarize:
it with the appropriate keys, markup, etc. and to carry balances it with the appropriate keys, markup, etc. and to carry balances
forward, etc. forward, etc.
- src/engine/kvp-util.[ch]
Gemini code: code which allows 'linked lists' to be created, using
nothing but kvp trees and guid's. These links are used to identify
peer accounts/ peer transactions, etc.
- src/engine/gnc-lot.[ch] - src/engine/gnc-lot.[ch]
Implements accounting Lots. Implements accounting Lots.

View File

@ -153,7 +153,7 @@ SHORT_NAMES = NO
# comments will behave just like regular Qt-style comments # comments will behave just like regular Qt-style comments
# (thus requiring an explicit @brief command for a brief description.) # (thus requiring an explicit @brief command for a brief description.)
JAVADOC_AUTOBRIEF = NO JAVADOC_AUTOBRIEF = YES
# If the QT_AUTOBRIEF tag is set to YES then Doxygen will # If the QT_AUTOBRIEF tag is set to YES then Doxygen will
# interpret the first line (until the first dot) of a Qt-style # interpret the first line (until the first dot) of a Qt-style
@ -186,7 +186,7 @@ SEPARATE_MEMBER_PAGES = NO
# The TAB_SIZE tag can be used to set the number of spaces in a tab. # The TAB_SIZE tag can be used to set the number of spaces in a tab.
# Doxygen uses this value to replace tabs by spaces in code fragments. # Doxygen uses this value to replace tabs by spaces in code fragments.
TAB_SIZE = 8 TAB_SIZE = 4
# This tag can be used to specify a number of aliases that acts # This tag can be used to specify a number of aliases that acts
# as commands in the documentation. An alias has the form "name=value". # as commands in the documentation. An alias has the form "name=value".
@ -266,7 +266,7 @@ AUTOLINK_SUPPORT = YES
# func(std::string) {}). This also makes the inheritance and collaboration # func(std::string) {}). This also makes the inheritance and collaboration
# diagrams that involve STL classes more complete and accurate. # diagrams that involve STL classes more complete and accurate.
BUILTIN_STL_SUPPORT = NO BUILTIN_STL_SUPPORT = YES
# If you use Microsoft's C++/CLI language, you should set this option to YES to # If you use Microsoft's C++/CLI language, you should set this option to YES to
# enable parsing support. # enable parsing support.
@ -675,7 +675,9 @@ FILE_PATTERNS = *.c \
*.h \ *.h \
*.txt \ *.txt \
*.py \ *.py \
*.pl *.pl \
*.cpp \
*.hpp
# The RECURSIVE tag can be used to turn specify whether or not subdirectories # The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO. # should be searched for input files as well. Possible values are YES and NO.
@ -703,7 +705,7 @@ EXCLUDE_SYMLINKS = YES
# against the file with absolute path, so to exclude all test directories # against the file with absolute path, so to exclude all test directories
# for example use the pattern */test/* # for example use the pattern */test/*
EXCLUDE_PATTERNS = EXCLUDE_PATTERNS = */test/*
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the # (namespaces, classes, functions, etc.) that should be excluded from the
@ -1460,18 +1462,6 @@ GENERATE_XML = NO
XML_OUTPUT = xml XML_OUTPUT = xml
# The XML_SCHEMA tag can be used to specify an XML schema,
# which can be used by a validating XML parser to check the
# syntax of the XML files.
XML_SCHEMA =
# The XML_DTD tag can be used to specify an XML DTD,
# which can be used by a validating XML parser to check the
# syntax of the XML files.
XML_DTD =
# If the XML_PROGRAMLISTING tag is set to YES Doxygen will # If the XML_PROGRAMLISTING tag is set to YES Doxygen will
# dump the program listings (including syntax highlighting # dump the program listings (including syntax highlighting
# and cross-referencing information) to the XML output. Note that # and cross-referencing information) to the XML output. Note that

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ libgncmod_engine_la_SOURCES = \
gnc-session.c \ gnc-session.c \
gncmod-engine.c \ gncmod-engine.c \
swig-engine.c \ swig-engine.c \
kvp-scm.c \ kvp-scm.cpp \
engine-helpers.c \ engine-helpers.c \
glib-helpers.c \ glib-helpers.c \
policy.c \ policy.c \

View File

@ -565,32 +565,6 @@ xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid,
qof_query_add_guid_match (q, param_list, guid, op); qof_query_add_guid_match (q, param_list, guid, op);
} }
void
xaccQueryAddKVPMatch(QofQuery *q, GSList *path, const KvpValue *value,
QofQueryCompare how, QofIdType id_type,
QofQueryOp op)
{
GSList *param_list = NULL;
QofQueryPredData *pred_data;
if (!q || !path || !value || !id_type)
return;
pred_data = qof_query_kvp_predicate (how, path, value);
if (!pred_data)
return;
if (!g_strcmp0 (id_type, GNC_ID_SPLIT))
param_list = qof_query_build_param_list (SPLIT_KVP, NULL);
else if (!g_strcmp0 (id_type, GNC_ID_TRANS))
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_KVP, NULL);
else if (!g_strcmp0 (id_type, GNC_ID_ACCOUNT))
param_list = qof_query_build_param_list (SPLIT_ACCOUNT, ACCOUNT_KVP, NULL);
else
PERR ("Invalid match type: %s", id_type);
qof_query_add_term (q, param_list, pred_data, op);
}
/******************************************************************** /********************************************************************
* xaccQueryAddClosingTransMatch * xaccQueryAddClosingTransMatch

View File

@ -186,10 +186,6 @@ void xaccQueryAddClearedMatch(QofQuery * q, cleared_match_t how, QofQueryOp op);
void xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid, void xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid,
QofIdType id_type, QofQueryOp op); QofIdType id_type, QofQueryOp op);
/** given kvp value is on right side of comparison */
void xaccQueryAddKVPMatch(QofQuery *q, GSList *path, const KvpValue *value,
QofQueryCompare how, QofIdType id_type,
QofQueryOp op);
/******************************************************************* /*******************************************************************
* compatibility interface with old QofQuery API * compatibility interface with old QofQuery API

View File

@ -27,7 +27,6 @@
#include "SX-ttinfo.h" #include "SX-ttinfo.h"
/* KvpFrame policy? */
struct TTInfo_s struct TTInfo_s
{ {
/* FIXME add notes field */ /* FIXME add notes field */
@ -41,7 +40,6 @@ struct TTInfo_s
struct TTSplitInfo_s struct TTSplitInfo_s
{ {
char *action; /* owned by us */ char *action; /* owned by us */
/* FIXME: What about the split's KvpFrame */
char *memo; /* owned by us */ char *memo; /* owned by us */
char *credit_formula, *debit_formula; /* owned by us */ char *credit_formula, *debit_formula; /* owned by us */
Account *acc; Account *acc;

View File

@ -319,8 +319,6 @@ gboolean SXRegister (void);
#define xaccSchedXactionIsDirty(X) qof_instance_is_dirty (QOF_INSTANCE(X)) #define xaccSchedXactionIsDirty(X) qof_instance_is_dirty (QOF_INSTANCE(X))
/** \deprecated */ /** \deprecated */
#define xaccSchedXactionGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X)) #define xaccSchedXactionGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
/** \deprecated */
#define xaccSchedXactionGetSlots(X) qof_instance_get_slots(QOF_INSTANCE(X))
#endif /* XACC_SCHEDXACTION_H */ #endif /* XACC_SCHEDXACTION_H */

View File

@ -50,6 +50,7 @@
#include "Transaction.h" #include "Transaction.h"
#include "TransactionP.h" #include "TransactionP.h"
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include <qofinstance-p.h>
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.engine.scrub" #define G_LOG_DOMAIN "gnc.engine.scrub"
@ -1157,11 +1158,10 @@ xaccAccountDeleteOldData (Account *account)
{ {
if (!account) return; if (!account) return;
xaccAccountBeginEdit (account); xaccAccountBeginEdit (account);
qof_instance_set_kvp (QOF_INSTANCE (account), "old-currency", NULL);
kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency", NULL); qof_instance_set_kvp (QOF_INSTANCE (account), "old-security", NULL);
kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security", NULL); qof_instance_set_kvp (QOF_INSTANCE (account), "old-currency-scu", NULL);
kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency-scu", NULL); qof_instance_set_kvp (QOF_INSTANCE (account), "old-security-scu", NULL);
kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security-scu", NULL);
qof_instance_set_dirty (QOF_INSTANCE (account)); qof_instance_set_dirty (QOF_INSTANCE (account));
xaccAccountCommitEdit (account); xaccAccountCommitEdit (account);
} }
@ -1262,30 +1262,28 @@ xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table)
void void
xaccAccountScrubKvp (Account *account) xaccAccountScrubKvp (Account *account)
{ {
GValue v = G_VALUE_INIT;
const gchar *str; const gchar *str;
gchar *str2; gchar *str2;
KvpFrame *frame;
if (!account) return; if (!account) return;
str = kvp_frame_get_string(account->inst.kvp_data, "notes"); qof_instance_get_kvp (QOF_INSTANCE (account), "notes", &v);
if (str) if (G_VALUE_HOLDS_STRING (&v))
{ {
str2 = g_strstrip(g_strdup(str)); str2 = g_strstrip(g_value_dup_string(&v));
if (strlen(str2) == 0) if (strlen(str2) == 0)
kvp_frame_set_slot_nc (account->inst.kvp_data, "notes", NULL); qof_instance_slot_delete (QOF_INSTANCE (account), "notes");
g_free(str2); g_free(str2);
} }
str = kvp_frame_get_string(account->inst.kvp_data, "placeholder"); qof_instance_get_kvp (QOF_INSTANCE (account), "placeholder", &v);
if (str && strcmp(str, "false") == 0) if ((G_VALUE_HOLDS_STRING (&v) &&
kvp_frame_set_slot_nc (account->inst.kvp_data, "placeholder", NULL); strcmp(g_value_get_string (&v), "false") == 0) ||
(G_VALUE_HOLDS_BOOLEAN (&v) && ! g_value_get_boolean (&v)))
qof_instance_slot_delete (QOF_INSTANCE (account), "placeholder");
frame = kvp_frame_get_frame(account->inst.kvp_data, "hbci"); qof_instance_slot_delete_if_empty (QOF_INSTANCE (account), "hbci");
if (frame && kvp_frame_is_empty(frame))
{
kvp_frame_set_frame_nc(account->inst.kvp_data, "hbci", NULL);
}
} }
/* ================================================================ */ /* ================================================================ */

View File

@ -242,17 +242,13 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
static inline gboolean static inline gboolean
is_subsplit (Split *split) is_subsplit (Split *split)
{ {
KvpValue *kval;
/* generic stop-progress conditions */ /* generic stop-progress conditions */
if (!split) return FALSE; if (!split) return FALSE;
g_return_val_if_fail (split->parent, FALSE); g_return_val_if_fail (split->parent, FALSE);
/* If there are no sub-splits, then there's nothing to do. */ /* If there are no sub-splits, then there's nothing to do. */
kval = kvp_frame_get_slot (split->inst.kvp_data, "lot-split"); return xaccSplitHasPeers (split);
if (!kval) return FALSE;
return TRUE;
} }
/* ================================================================= */ /* ================================================================= */
@ -267,30 +263,9 @@ is_subsplit (Split *split)
static void static void
remove_guids (Split *sa, Split *sb) remove_guids (Split *sa, Split *sb)
{ {
KvpFrame *ksub; xaccSplitRemovePeerSplit (sa, sb);
xaccSplitRemovePeerSplit (sb, sa);
/* Find and remove the matching guid's */ xaccSplitMergePeerSplits (sa, sb);
ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->inst.kvp_data, "lot-split",
"peer_guid", qof_instance_get_guid(sb));
if (ksub)
{
gnc_kvp_bag_remove_frame (sa->inst.kvp_data, "lot-split", ksub);
kvp_frame_delete (ksub);
}
/* Now do it in the other direction */
ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->inst.kvp_data, "lot-split",
"peer_guid", qof_instance_get_guid(sa));
if (ksub)
{
gnc_kvp_bag_remove_frame (sb->inst.kvp_data, "lot-split", ksub);
kvp_frame_delete (ksub);
}
/* Finally, merge b's lot-splits, if any, into a's */
/* This is an important step, if it got busted into many pieces. */
gnc_kvp_bag_merge (sa->inst.kvp_data, "lot-split",
sb->inst.kvp_data, "lot-split");
} }
/* The merge_splits() routine causes the amount & value of sb /* The merge_splits() routine causes the amount & value of sb
@ -350,7 +325,6 @@ xaccScrubMergeSubSplits (Split *split, gboolean strict)
Transaction *txn; Transaction *txn;
SplitList *node; SplitList *node;
GNCLot *lot; GNCLot *lot;
const GncGUID *guid;
if (strict && (FALSE == is_subsplit (split))) return FALSE; if (strict && (FALSE == is_subsplit (split))) return FALSE;
@ -376,9 +350,7 @@ restart:
* example. Only worry about adjacent sub-splits. By * example. Only worry about adjacent sub-splits. By
* repeatedly merging adjacent subsplits, we'll get the non- * repeatedly merging adjacent subsplits, we'll get the non-
* adjacent ones too. */ * adjacent ones too. */
guid = qof_instance_get_guid(s); if (!xaccSplitIsPeerSplit (split, s))
if (gnc_kvp_bag_find_by_guid (split->inst.kvp_data, "lot-split",
"peer_guid", guid) == NULL)
continue; continue;
} }

File diff suppressed because it is too large Load Diff

View File

@ -338,7 +338,7 @@ gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
* *
* @param check_txn_splits If the pointers are not equal, but * @param check_txn_splits If the pointers are not equal, but
* everything else so far is equal (including memo, amount, value, * everything else so far is equal (including memo, amount, value,
* kvp_frame), then, when comparing the parenting transactions with * kvp), then, when comparing the parenting transactions with
* xaccTransEqual(), set its argument check_splits to be TRUE. * xaccTransEqual(), set its argument check_splits to be TRUE.
*/ */
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean xaccSplitEqual(const Split *sa, const Split *sb,
@ -356,6 +356,29 @@ Split * xaccSplitLookup (const GncGUID *guid, QofBook *book);
/* Get a GList of unique transactions containing the given list of Splits. */ /* Get a GList of unique transactions containing the given list of Splits. */
GList *xaccSplitListGetUniqueTransactions(const GList *splits); GList *xaccSplitListGetUniqueTransactions(const GList *splits);
/*################## Added for Reg2 #################*/ /*################## Added for Reg2 #################*/
/** Add a peer split to this split's lot-split list.
* @param other_split: The split whose guid to add
* @param timestamp: The time to be recorded for the split.
*/
void xaccSplitAddPeerSplit (Split *split, const Split *other_split,
const time64 timestamp);
/** Does this split have peers?
*/
gboolean xaccSplitHasPeers (const Split *split);
/** Report if a split is a peer of this one.
* @param other_split: The split to test for being a peer of this one.
* @return: True if other_split is registered as a peer of this one.
*/
gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split);
/** Remove a peer split from this split's lot-split list.
* @param other_split: The split whose guid to remove
*/
void xaccSplitRemovePeerSplit (Split *split, const Split *other_split);
/** Merge the other_split's peer splits into split's peers.
* @param other_split: The split donating the peer splits.
*/
void xaccSplitMergePeerSplits (Split *split, const Split *other_split);
/** /**
* The xaccSplitGetOtherSplit() is a convenience routine that returns * The xaccSplitGetOtherSplit() is a convenience routine that returns
@ -492,8 +515,6 @@ gnc_numeric xaccSplitVoidFormerValue(const Split *split);
* override so the gnome-search dialog displays the right type. * override so the gnome-search dialog displays the right type.
@{ @{
*/ */
#define SPLIT_KVP "kvp"
#define SPLIT_DATE_RECONCILED "date-reconciled" #define SPLIT_DATE_RECONCILED "date-reconciled"
#define SPLIT_BALANCE "balance" #define SPLIT_BALANCE "balance"
#define SPLIT_CLEARED_BALANCE "cleared-balance" #define SPLIT_CLEARED_BALANCE "cleared-balance"

View File

@ -312,7 +312,6 @@ gnc_transaction_get_property(GObject* object,
GParamSpec* pspec) GParamSpec* pspec)
{ {
Transaction* tx; Transaction* tx;
KvpFrame *frame;
gchar *key; gchar *key;
GValue *temp; GValue *temp;
@ -361,7 +360,6 @@ gnc_transaction_set_property(GObject* object,
GParamSpec* pspec) GParamSpec* pspec)
{ {
Transaction* tx; Transaction* tx;
KvpFrame *frame;
gchar *key; gchar *key;
g_return_if_fail(GNC_IS_TRANSACTION(object)); g_return_if_fail(GNC_IS_TRANSACTION(object));
@ -633,7 +631,7 @@ dupe_trans (const Transaction *from)
to->inst.e_type = NULL; to->inst.e_type = NULL;
qof_instance_set_guid(to, guid_null()); qof_instance_set_guid(to, guid_null());
qof_instance_copy_book(to, from); qof_instance_copy_book(to, from);
to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data); qof_instance_copy_kvp (QOF_INSTANCE(to), QOF_INSTANCE(from));
return to; return to;
} }
@ -688,7 +686,7 @@ xaccTransClone (const Transaction *from)
int length = g_list_length (from->splits); int length = g_list_length (from->splits);
xaccTransBeginEdit (to); xaccTransBeginEdit (to);
to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data); qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
g_assert (g_list_length (to->splits) == length); g_assert (g_list_length (to->splits) == length);
for (i = 0; i < length; ++i) for (i = 0; i < length; ++i)
xaccSplitCopyKvp (g_list_nth_data (from->splits, i), xaccSplitCopyKvp (g_list_nth_data (from->splits, i),
@ -934,13 +932,14 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb,
return FALSE; return FALSE;
} }
if (kvp_frame_compare(ta->inst.kvp_data, tb->inst.kvp_data) != 0) if (qof_instance_compare_kvp (QOF_INSTANCE (ta), QOF_INSTANCE (tb)) != 0)
{ {
char *frame_a; char *frame_a;
char *frame_b; char *frame_b;
frame_a = kvp_frame_to_string (ta->inst.kvp_data); frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (ta));
frame_b = kvp_frame_to_string (tb->inst.kvp_data); frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (tb));
PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b); PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
@ -1688,7 +1687,7 @@ xaccTransRollbackEdit (Transaction *trans)
trans->date_entered = orig->date_entered; trans->date_entered = orig->date_entered;
trans->date_posted = orig->date_posted; trans->date_posted = orig->date_posted;
SWAP(trans->common_currency, orig->common_currency); SWAP(trans->common_currency, orig->common_currency);
SWAP(trans->inst.kvp_data, orig->inst.kvp_data); qof_instance_swap_kvp (QOF_INSTANCE (trans), QOF_INSTANCE (orig));
/* The splits at the front of trans->splits are exactly the same /* The splits at the front of trans->splits are exactly the same
splits as in the original, but some of them may have changed, so splits as in the original, but some of them may have changed, so
@ -1713,7 +1712,7 @@ xaccTransRollbackEdit (Transaction *trans)
xaccSplitRollbackEdit(s); xaccSplitRollbackEdit(s);
SWAP(s->action, so->action); SWAP(s->action, so->action);
SWAP(s->memo, so->memo); SWAP(s->memo, so->memo);
SWAP(s->inst.kvp_data, so->inst.kvp_data); qof_instance_copy_kvp (QOF_INSTANCE (s), QOF_INSTANCE (so));
s->reconciled = so->reconciled; s->reconciled = so->reconciled;
s->amount = so->amount; s->amount = so->amount;
s->value = so->value; s->value = so->value;
@ -1924,20 +1923,15 @@ xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
void void
xaccTransSetDatePostedGDate (Transaction *trans, GDate date) xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
{ {
KvpValue* kvp_value; GValue v = G_VALUE_INIT;
KvpFrame* frame;
if (!trans) return; if (!trans) return;
/* We additionally save this date into a kvp frame to ensure in /* We additionally save this date into a kvp frame to ensure in
* the future a date which was set as *date* (without time) can * the future a date which was set as *date* (without time) can
* clearly be distinguished from the Timespec. */ * clearly be distinguished from the Timespec. */
kvp_value = kvp_value_new_gdate(date); g_value_init (&v, G_TYPE_DATE);
frame = kvp_frame_set_value_nc(trans->inst.kvp_data, TRANS_DATE_POSTED, kvp_value); g_value_set_boxed (&v, &date);
if (!frame) qof_instance_set_kvp (QOF_INSTANCE(trans), TRANS_DATE_POSTED, &v);
{
kvp_value_delete(kvp_value);
}
/* mark dirty and commit handled by SetDateInternal */ /* mark dirty and commit handled by SetDateInternal */
xaccTransSetDateInternal(trans, &trans->date_posted, xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_timespec(date)); gdate_to_timespec(date));
@ -2002,9 +1996,12 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year)
void void
xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts) xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts)
{ {
GValue v = G_VALUE_INIT;
if (!trans || !ts) return; if (!trans || !ts) return;
g_value_init (&v, GNC_TYPE_TIMESPEC);
g_value_set_boxed (&v, ts);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
kvp_frame_set_timespec (trans->inst.kvp_data, TRANS_DATE_DUE_KVP, *ts); qof_instance_set_kvp (QOF_INSTANCE (trans), TRANS_DATE_DUE_KVP, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2013,9 +2010,12 @@ void
xaccTransSetTxnType (Transaction *trans, char type) xaccTransSetTxnType (Transaction *trans, char type)
{ {
char s[2] = {type, '\0'}; char s[2] = {type, '\0'};
GValue v = G_VALUE_INIT;
g_return_if_fail(trans); g_return_if_fail(trans);
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, s);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
kvp_frame_set_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP, s); qof_instance_set_kvp (QOF_INSTANCE (trans), TRANS_TXN_TYPE_KVP, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2025,8 +2025,8 @@ void xaccTransClearReadOnly (Transaction *trans)
if (trans) if (trans)
{ {
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
kvp_frame_set_slot_path (trans->inst.kvp_data, NULL, qof_instance_set_kvp (QOF_INSTANCE (trans),
TRANS_READ_ONLY_REASON, NULL); TRANS_READ_ONLY_REASON, NULL);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2037,9 +2037,11 @@ xaccTransSetReadOnly (Transaction *trans, const char *reason)
{ {
if (trans && reason) if (trans && reason)
{ {
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, reason);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
kvp_frame_set_string (trans->inst.kvp_data, qof_instance_set_kvp (QOF_INSTANCE (trans), TRANS_READ_ONLY_REASON, &v);
TRANS_READ_ONLY_REASON, reason);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2092,10 +2094,12 @@ xaccTransSetDescription (Transaction *trans, const char *desc)
void void
xaccTransSetAssociation (Transaction *trans, const char *assoc) xaccTransSetAssociation (Transaction *trans, const char *assoc)
{ {
GValue v = G_VALUE_INIT;
if (!trans || !assoc) return; if (!trans || !assoc) return;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, assoc);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
qof_instance_set_kvp (QOF_INSTANCE (trans), assoc_uri_str, &v);
kvp_frame_set_string (trans->inst.kvp_data, assoc_uri_str, assoc);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2111,10 +2115,13 @@ qofTransSetNotes (Transaction *trans, const char *notes)
void void
xaccTransSetNotes (Transaction *trans, const char *notes) xaccTransSetNotes (Transaction *trans, const char *notes)
{ {
GValue v = G_VALUE_INIT;
if (!trans || !notes) return; if (!trans || !notes) return;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, notes);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
kvp_frame_set_string (trans->inst.kvp_data, trans_notes_str, notes); qof_instance_set_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2126,9 +2133,14 @@ xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
if (is_closing) if (is_closing)
kvp_frame_set_gint64 (trans->inst.kvp_data, trans_is_closing_str, 1); {
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_INT64);
g_value_set_int64 (&v, 1);
qof_instance_set_kvp (QOF_INSTANCE (trans), trans_is_closing_str, &v);
}
else else
kvp_frame_replace_value_nc (trans->inst.kvp_data, trans_is_closing_str, NULL); qof_instance_set_kvp (QOF_INSTANCE (trans), trans_is_closing_str, NULL);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
} }
@ -2186,23 +2198,34 @@ xaccTransGetDescription (const Transaction *trans)
const char * const char *
xaccTransGetAssociation (const Transaction *trans) xaccTransGetAssociation (const Transaction *trans)
{ {
return trans ? GValue v = G_VALUE_INIT;
kvp_frame_get_string (trans->inst.kvp_data, assoc_uri_str) : NULL; if (!trans) return NULL;
qof_instance_get_kvp (QOF_INSTANCE (trans), assoc_uri_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
const char * const char *
xaccTransGetNotes (const Transaction *trans) xaccTransGetNotes (const Transaction *trans)
{ {
return trans ? GValue v = G_VALUE_INIT;
kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL; if (!trans) return NULL;
qof_instance_get_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
gboolean gboolean
xaccTransGetIsClosingTxn (const Transaction *trans) xaccTransGetIsClosingTxn (const Transaction *trans)
{ {
return trans ? GValue v = G_VALUE_INIT;
kvp_frame_get_gint64 (trans->inst.kvp_data, trans_is_closing_str) if (!trans) return FALSE;
: FALSE; qof_instance_get_kvp (QOF_INSTANCE (trans), trans_is_closing_str, &v);
if (G_VALUE_HOLDS_INT64 (&v))
return g_value_get_int64 (&v);
return FALSE;
} }
/********************************************************************\ /********************************************************************\
@ -2252,11 +2275,11 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
/* Can we look up this value in the kvp slot? If yes, use it /* Can we look up this value in the kvp slot? If yes, use it
* from there because it doesn't suffer from time zone * from there because it doesn't suffer from time zone
* shifts. */ * shifts. */
const KvpValue* kvp_value = GValue v = G_VALUE_INIT;
kvp_frame_get_slot(trans->inst.kvp_data, TRANS_DATE_POSTED); qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_DATE_POSTED, &v);
if (kvp_value) if (G_VALUE_HOLDS_BOXED (&v))
result = kvp_value_get_gdate(kvp_value); result = *(GDate*)g_value_get_boxed (&v);
else if (! g_date_valid (&result))
result = timespec_to_gdate(xaccTransRetDatePostedTS(trans)); result = timespec_to_gdate(xaccTransRetDatePostedTS(trans));
} }
else else
@ -2276,14 +2299,13 @@ xaccTransRetDateEnteredTS (const Transaction *trans)
void void
xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts) xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts)
{ {
KvpValue *value; GValue v = G_VALUE_INIT;
if (!trans || !ts) return; if (!trans || !ts) return;
value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP); qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_DATE_DUE_KVP, &v);
if (value) if (G_VALUE_HOLDS_BOXED (&v))
*ts = kvp_value_get_timespec (value); *ts = *(Timespec*)g_value_get_boxed (&v);
else if (ts->tv_sec == 0)
xaccTransGetDatePostedTS (trans, ts); xaccTransGetDatePostedTS (trans, ts);
} }
@ -2298,10 +2320,15 @@ xaccTransRetDateDueTS (const Transaction *trans)
char char
xaccTransGetTxnType (const Transaction *trans) xaccTransGetTxnType (const Transaction *trans)
{ {
const char *s; const char *s = NULL;
GValue v = G_VALUE_INIT;
if (!trans) return TXN_TYPE_NONE; if (!trans) return TXN_TYPE_NONE;
s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP); qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_TXN_TYPE_KVP, &v);
if (s) return *s; if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s && strlen (s) == 0)
return *s;
return TXN_TYPE_NONE; return TXN_TYPE_NONE;
} }
@ -2312,8 +2339,16 @@ xaccTransGetReadOnly (const Transaction *trans)
/* XXX This flag should be cached in the transaction structure /* XXX This flag should be cached in the transaction structure
* for performance reasons, since its checked every trans commit. * for performance reasons, since its checked every trans commit.
*/ */
return trans ? kvp_frame_get_string ( GValue v = G_VALUE_INIT;
trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL; const char *s = NULL;
if (trans == NULL) return NULL;
qof_instance_get_kvp (QOF_INSTANCE(trans), TRANS_READ_ONLY_REASON, &v);
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s && strlen (s))
return s;
return NULL;
} }
static gboolean static gboolean
@ -2491,26 +2526,26 @@ gnc_book_count_transactions(QofBook *book)
void void
xaccTransVoid(Transaction *trans, const char *reason) xaccTransVoid(Transaction *trans, const char *reason)
{ {
KvpFrame *frame; GValue v = G_VALUE_INIT;
KvpValue *val;
Timespec now;
char iso8601_str[ISO_DATELENGTH + 1] = ""; char iso8601_str[ISO_DATELENGTH + 1] = "";
g_return_if_fail(trans && reason); g_return_if_fail(trans && reason);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
frame = trans->inst.kvp_data; qof_instance_get_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
qof_instance_set_kvp (QOF_INSTANCE (trans), void_former_notes_str, &v);
else
g_value_init (&v, G_TYPE_STRING);
val = kvp_frame_get_slot(frame, trans_notes_str); g_value_set_string (&v, _("Voided transaction"));
kvp_frame_set_slot(frame, void_former_notes_str, val); qof_instance_set_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
g_value_set_string (&v, reason);
qof_instance_set_kvp (QOF_INSTANCE (trans), void_reason_str, &v);
kvp_frame_set_string(frame, trans_notes_str, _("Voided transaction")); gnc_timespec_to_iso8601_buff (timespec_now (), iso8601_str);
kvp_frame_set_string(frame, void_reason_str, reason); g_value_set_string (&v, iso8601_str);
qof_instance_set_kvp (QOF_INSTANCE (trans), void_time_str, &v);
now.tv_sec = gnc_time (NULL);
now.tv_nsec = 0;
gnc_timespec_to_iso8601_buff(now, iso8601_str);
kvp_frame_set_string(frame, void_time_str, iso8601_str);
FOR_EACH_SPLIT(trans, xaccSplitVoid(s)); FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
@ -2522,48 +2557,63 @@ xaccTransVoid(Transaction *trans, const char *reason)
gboolean gboolean
xaccTransGetVoidStatus(const Transaction *trans) xaccTransGetVoidStatus(const Transaction *trans)
{ {
const char *s = NULL;
GValue v = G_VALUE_INIT;
g_return_val_if_fail(trans, FALSE); g_return_val_if_fail(trans, FALSE);
return (kvp_frame_get_slot(trans->inst.kvp_data, void_reason_str) != NULL);
qof_instance_get_kvp (QOF_INSTANCE (trans), void_reason_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
return s && strlen(s);
} }
const char * const char *
xaccTransGetVoidReason(const Transaction *trans) xaccTransGetVoidReason(const Transaction *trans)
{ {
g_return_val_if_fail(trans, NULL); GValue v = G_VALUE_INIT;
return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str); g_return_val_if_fail(trans, FALSE);
qof_instance_get_kvp (QOF_INSTANCE (trans), void_reason_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
Timespec Timespec
xaccTransGetVoidTime(const Transaction *tr) xaccTransGetVoidTime(const Transaction *tr)
{ {
const char *val; GValue v = G_VALUE_INIT;
Timespec void_time = {0, 0}; const char *s = NULL;
Timespec void_time = {0, 0}, *ts;
g_return_val_if_fail(tr, void_time); g_return_val_if_fail(tr, void_time);
qof_instance_get_kvp (QOF_INSTANCE (tr), void_time_str, &v);
val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str); if (G_VALUE_HOLDS_STRING (&v))
return val ? gnc_iso8601_to_timespec_gmt(val) : void_time; s = g_value_get_string (&v);
if (s)
return gnc_iso8601_to_timespec_gmt (s);
return void_time;
} }
void void
xaccTransUnvoid (Transaction *trans) xaccTransUnvoid (Transaction *trans)
{ {
KvpFrame *frame; GValue v = G_VALUE_INIT;
KvpValue *val; const char *s = NULL;
g_return_if_fail(trans); g_return_if_fail(trans);
frame = trans->inst.kvp_data; qof_instance_get_kvp (QOF_INSTANCE (trans), void_reason_str, &v);
val = kvp_frame_get_slot(frame, void_reason_str); if (G_VALUE_HOLDS_STRING (&v))
if (!val) return; /* Transaction isn't voided. Bail. */ s = g_value_get_string (&v);
if (s == NULL) return; /* Transaction isn't voided. Bail. */
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
val = kvp_frame_get_slot(frame, void_former_notes_str); qof_instance_get_kvp (QOF_INSTANCE (trans), void_former_notes_str, &v);
kvp_frame_set_slot(frame, trans_notes_str, val); if (G_VALUE_HOLDS_STRING (&v))
kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL); qof_instance_set_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
kvp_frame_set_slot_nc(frame, void_reason_str, NULL); qof_instance_set_kvp (QOF_INSTANCE (trans), void_former_notes_str, NULL);
kvp_frame_set_slot_nc(frame, void_time_str, NULL); qof_instance_set_kvp (QOF_INSTANCE (trans), void_reason_str, NULL);
qof_instance_set_kvp (QOF_INSTANCE (trans), void_time_str, NULL);
FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s)); FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
@ -2576,7 +2626,7 @@ Transaction *
xaccTransReverse (Transaction *orig) xaccTransReverse (Transaction *orig)
{ {
Transaction *trans; Transaction *trans;
KvpValue *kvp_val; GValue v = G_VALUE_INIT;
g_return_val_if_fail(orig, NULL); g_return_val_if_fail(orig, NULL);
trans = xaccTransClone(orig); trans = xaccTransClone(orig);
@ -2591,8 +2641,9 @@ xaccTransReverse (Transaction *orig)
}); });
/* Now update the original with a pointer to the new one */ /* Now update the original with a pointer to the new one */
kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans)); g_value_init (&v, GNC_TYPE_GUID);
kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val); g_value_set_boxed (&v, xaccTransGetGUID(trans));
qof_instance_set_kvp (QOF_INSTANCE (orig), TRANS_REVERSED_BY, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans)); qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
@ -2602,11 +2653,13 @@ xaccTransReverse (Transaction *orig)
Transaction * Transaction *
xaccTransGetReversedBy(const Transaction *trans) xaccTransGetReversedBy(const Transaction *trans)
{ {
GncGUID *guid; GValue v = G_VALUE_INIT;
g_return_val_if_fail(trans, NULL); g_return_val_if_fail(trans, NULL);
guid = kvp_frame_get_guid(trans->inst.kvp_data, TRANS_REVERSED_BY); qof_instance_get_kvp (QOF_INSTANCE(trans), TRANS_REVERSED_BY, &v);
return xaccTransLookup(guid, qof_instance_get_book(trans)); if (G_VALUE_HOLDS_BOXED (&v))
return xaccTransLookup((GncGUID*)g_value_get_boxed (&v),
qof_instance_get_book(trans));
return NULL;
} }
void void
@ -2653,9 +2706,9 @@ xaccTransScrubGainsDate (Transaction *trans)
xaccSplitDetermineGainStatus(s); xaccSplitDetermineGainStatus(s);
if ((GAINS_STATUS_GAINS & s->gains) && if ((GAINS_STATUS_GAINS & s->gains) &&
s->gains_split && s->gains_split &&
((s->gains_split->gains & GAINS_STATUS_DATE_DIRTY) || ((s->gains_split->gains & GAINS_STATUS_DATE_DIRTY) ||
(s->gains & GAINS_STATUS_DATE_DIRTY))) (s->gains & GAINS_STATUS_DATE_DIRTY)))
{ {
Transaction *source_trans = s->gains_split->parent; Transaction *source_trans = s->gains_split->parent;
ts = source_trans->date_posted; ts = source_trans->date_posted;
@ -2707,8 +2760,8 @@ restart:
if ((s->gains & GAINS_STATUS_VDIRTY) || if ((s->gains & GAINS_STATUS_VDIRTY) ||
(s->gains_split && (s->gains_split &&
(s->gains_split->gains & GAINS_STATUS_VDIRTY))) (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
xaccSplitComputeCapGains(s, gain_acc); xaccSplitComputeCapGains(s, gain_acc);
); );
LEAVE("(trans=%p)", trans); LEAVE("(trans=%p)", trans);
} }
@ -2780,89 +2833,85 @@ trans_is_balanced_p (const Transaction *trans)
gboolean xaccTransRegister (void) gboolean xaccTransRegister (void)
{ {
static QofParam params[] = static QofParam params[] =
{
{ {
TRANS_NUM, QOF_TYPE_STRING, {
(QofAccessFunc)xaccTransGetNum, TRANS_NUM, QOF_TYPE_STRING,
(QofSetterFunc)qofTransSetNum, (QofAccessFunc)xaccTransGetNum,
qof_string_number_compare_func (QofSetterFunc)qofTransSetNum,
}, qof_string_number_compare_func
{ },
TRANS_DESCRIPTION, QOF_TYPE_STRING, {
(QofAccessFunc)xaccTransGetDescription, TRANS_DESCRIPTION, QOF_TYPE_STRING,
(QofSetterFunc)qofTransSetDescription (QofAccessFunc)xaccTransGetDescription,
}, (QofSetterFunc)qofTransSetDescription
{ },
TRANS_DATE_ENTERED, QOF_TYPE_DATE, {
(QofAccessFunc)xaccTransRetDateEnteredTS, TRANS_DATE_ENTERED, QOF_TYPE_DATE,
(QofSetterFunc)qofTransSetDateEntered (QofAccessFunc)xaccTransRetDateEnteredTS,
}, (QofSetterFunc)qofTransSetDateEntered
{ },
TRANS_DATE_POSTED, QOF_TYPE_DATE, {
(QofAccessFunc)xaccTransRetDatePostedTS, TRANS_DATE_POSTED, QOF_TYPE_DATE,
(QofSetterFunc)qofTransSetDatePosted (QofAccessFunc)xaccTransRetDatePostedTS,
}, (QofSetterFunc)qofTransSetDatePosted
{ },
TRANS_DATE_DUE, QOF_TYPE_DATE, {
(QofAccessFunc)xaccTransRetDateDueTS, NULL TRANS_DATE_DUE, QOF_TYPE_DATE,
}, (QofAccessFunc)xaccTransRetDateDueTS, NULL
{ },
TRANS_IMBALANCE, QOF_TYPE_NUMERIC, {
(QofAccessFunc)xaccTransGetImbalanceValue, NULL TRANS_IMBALANCE, QOF_TYPE_NUMERIC,
}, (QofAccessFunc)xaccTransGetImbalanceValue, NULL
{ },
TRANS_NOTES, QOF_TYPE_STRING, {
(QofAccessFunc)xaccTransGetNotes, TRANS_NOTES, QOF_TYPE_STRING,
(QofSetterFunc)qofTransSetNotes (QofAccessFunc)xaccTransGetNotes,
}, (QofSetterFunc)qofTransSetNotes
{ },
TRANS_ASSOCIATION, QOF_TYPE_STRING, {
(QofAccessFunc)xaccTransGetAssociation, TRANS_ASSOCIATION, QOF_TYPE_STRING,
(QofSetterFunc)xaccTransSetAssociation (QofAccessFunc)xaccTransGetAssociation,
}, (QofSetterFunc)xaccTransSetAssociation
{ },
TRANS_IS_CLOSING, QOF_TYPE_BOOLEAN, {
(QofAccessFunc)xaccTransGetIsClosingTxn, NULL TRANS_IS_CLOSING, QOF_TYPE_BOOLEAN,
}, (QofAccessFunc)xaccTransGetIsClosingTxn, NULL
{ },
TRANS_IS_BALANCED, QOF_TYPE_BOOLEAN, {
(QofAccessFunc)trans_is_balanced_p, NULL TRANS_IS_BALANCED, QOF_TYPE_BOOLEAN,
}, (QofAccessFunc)trans_is_balanced_p, NULL
{ },
TRANS_TYPE, QOF_TYPE_CHAR, {
(QofAccessFunc)xaccTransGetTxnType, TRANS_TYPE, QOF_TYPE_CHAR,
(QofSetterFunc)xaccTransSetTxnType (QofAccessFunc)xaccTransGetTxnType,
}, (QofSetterFunc)xaccTransSetTxnType
{ },
TRANS_VOID_STATUS, QOF_TYPE_BOOLEAN, {
(QofAccessFunc)xaccTransGetVoidStatus, NULL TRANS_VOID_STATUS, QOF_TYPE_BOOLEAN,
}, (QofAccessFunc)xaccTransGetVoidStatus, NULL
{ },
TRANS_VOID_REASON, QOF_TYPE_STRING, {
(QofAccessFunc)xaccTransGetVoidReason, NULL TRANS_VOID_REASON, QOF_TYPE_STRING,
}, (QofAccessFunc)xaccTransGetVoidReason, NULL
{ },
TRANS_VOID_TIME, QOF_TYPE_DATE, {
(QofAccessFunc)xaccTransGetVoidTime, NULL TRANS_VOID_TIME, QOF_TYPE_DATE,
}, (QofAccessFunc)xaccTransGetVoidTime, NULL
{ },
TRANS_SPLITLIST, GNC_ID_SPLIT, {
(QofAccessFunc)xaccTransGetSplitList, NULL TRANS_SPLITLIST, GNC_ID_SPLIT,
}, (QofAccessFunc)xaccTransGetSplitList, NULL
{ },
TRANS_KVP, QOF_TYPE_KVP, {
(QofAccessFunc)qof_instance_get_slots, NULL QOF_PARAM_BOOK, QOF_ID_BOOK,
}, (QofAccessFunc)qof_instance_get_book, NULL
{ },
QOF_PARAM_BOOK, QOF_ID_BOOK, {
(QofAccessFunc)qof_instance_get_book, NULL QOF_PARAM_GUID, QOF_TYPE_GUID,
}, (QofAccessFunc)qof_entity_get_guid, NULL
{ },
QOF_PARAM_GUID, QOF_TYPE_GUID, { NULL },
(QofAccessFunc)qof_entity_get_guid, NULL };
},
{ NULL },
};
qof_class_register (GNC_ID_TRANS, (QofSortFunc)xaccTransOrder, params); qof_class_register (GNC_ID_TRANS, (QofSortFunc)xaccTransOrder, params);

View File

@ -164,13 +164,6 @@ QofBackend * xaccTransactionGetBackend (Transaction *trans);
void xaccEnableDataScrubbing(void); void xaccEnableDataScrubbing(void);
void xaccDisableDataScrubbing(void); void xaccDisableDataScrubbing(void);
/** Set the KvpFrame slots of this transaction to the given frm by
* * directly using the frm pointer (i.e. non-copying).
* * XXX this is wrong, nedds to be replaced with a transactional thingy
* in kvp + qofinstance. for now, this is a quasi-unctional placeholder.
* */
#define xaccTransSetSlots_nc(T,F) qof_instance_set_slots(QOF_INSTANCE(T),F)
void xaccTransRemoveSplit (Transaction *trans, const Split *split); void xaccTransRemoveSplit (Transaction *trans, const Split *split);
void check_open (const Transaction *trans); void check_open (const Transaction *trans);

View File

@ -404,16 +404,8 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
/* Set the lot-split and peer_guid properties on the two /* Set the lot-split and peer_guid properties on the two
* splits to indicate that they're linked. * splits to indicate that they're linked.
*/ */
qof_instance_set (QOF_INSTANCE (split), xaccSplitAddPeerSplit(split, new_split, now);
"lot-split", now, xaccSplitAddPeerSplit(new_split, split, now);
"peer_guid", xaccSplitGetGUID (new_split),
NULL);
qof_instance_set (QOF_INSTANCE (new_split),
"lot-split", now,
"peer_guid", xaccSplitGetGUID (split),
NULL);
xaccAccountInsertSplit (acc, new_split); xaccAccountInsertSplit (acc, new_split);
xaccTransAppendSplit (trans, new_split); xaccTransAppendSplit (trans, new_split);
/* Set the amount and value after the split is in the transaction /* Set the amount and value after the split is in the transaction

View File

@ -37,8 +37,9 @@
#include "gnc-session.h" #include "gnc-session.h"
#include "guile-mappings.h" #include "guile-mappings.h"
#include "gnc-guile-utils.h" #include "gnc-guile-utils.h"
#include "qof.h" #include <qof.h>
#include "qofbookslots.h" #include <qofbookslots.h>
/** \todo Code dependent on the private query headers /** \todo Code dependent on the private query headers
qofquery-p.h and qofquerycore-p.h may need to be modified. qofquery-p.h and qofquerycore-p.h may need to be modified.
These files are temporarily exported for QOF 0.6.0 but These files are temporarily exported for QOF 0.6.0 but
@ -477,32 +478,6 @@ gnc_scm2amt_match_how (SCM how_scm)
return res; return res;
} }
static QofQueryCompare
gnc_scm2kvp_match_how (SCM how_scm)
{
QofQueryCompare res;
gchar *how = gnc_scm_symbol_to_locale_string (how_scm);
if (!g_strcmp0 (how, "kvp-match-lt"))
res = QOF_COMPARE_LT;
else if (!g_strcmp0 (how, "kvp-match-lte"))
res = QOF_COMPARE_LTE;
else if (!g_strcmp0 (how, "kvp-match-eq"))
res = QOF_COMPARE_EQUAL;
else if (!g_strcmp0 (how, "kvp-match-gte"))
res = QOF_COMPARE_GTE;
else if (!g_strcmp0 (how, "kvp-match-gt"))
res = QOF_COMPARE_GT;
else
{
PINFO ("invalid kvp match: %s", how);
res = QOF_COMPARE_EQUAL;
}
g_free (how);
return res;
}
static int static int
gnc_scm2bitfield (SCM field_scm) gnc_scm2bitfield (SCM field_scm)
{ {
@ -558,33 +533,6 @@ gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
return TRUE; return TRUE;
} }
static QofIdType
gnc_scm2kvp_match_where (SCM where_scm)
{
QofIdType res;
gchar *where;
if (!scm_is_list (where_scm))
return NULL;
where = gnc_scm_symbol_to_locale_string (SCM_CAR(where_scm));
if (!g_strcmp0 (where, "kvp-match-split"))
res = GNC_ID_SPLIT;
else if (!g_strcmp0 (where, "kvp-match-trans"))
res = GNC_ID_TRANS;
else if (!g_strcmp0 (where, "kvp-match-account"))
res = GNC_ID_ACCOUNT;
else
{
PINFO ("Unknown kvp-match-where: %s", where);
res = NULL;
}
g_free (where);
return res;
}
static SCM static SCM
gnc_guid_glist2scm (const GList *account_guids) gnc_guid_glist2scm (const GList *account_guids)
{ {
@ -719,287 +667,6 @@ gnc_query_path_free (GSList *path)
g_slist_free (path); g_slist_free (path);
} }
static KvpValueType
gnc_scm2KvpValueType (SCM value_type_scm)
{
return scm_to_int(value_type_scm);
}
static SCM gnc_kvp_frame2scm (KvpFrame *frame);
static SCM
gnc_kvp_value2scm (const KvpValue *value)
{
SCM value_scm = SCM_EOL;
KvpValueType value_t;
SCM scm;
const gchar *string;
if (!value) return SCM_BOOL_F;
value_t = kvp_value_get_type (value);
value_scm = scm_cons (scm_from_long (value_t), value_scm);
switch (value_t)
{
case KVP_TYPE_GINT64:
scm = scm_from_int64 (kvp_value_get_gint64 (value));
break;
case KVP_TYPE_DOUBLE:
scm = scm_from_double (kvp_value_get_double (value));
break;
case KVP_TYPE_STRING:
string = kvp_value_get_string (value);
scm = string ? scm_from_utf8_string (string) : SCM_BOOL_F;
break;
case KVP_TYPE_GUID:
scm = gnc_guid2scm (*kvp_value_get_guid (value));
break;
case KVP_TYPE_TIMESPEC:
scm = gnc_timespec2timepair (kvp_value_get_timespec (value));
break;
case KVP_TYPE_NUMERIC:
{
gnc_numeric n = kvp_value_get_numeric (value);
scm = gnc_query_numeric2scm (n);
break;
}
case KVP_TYPE_GLIST:
{
GList *node;
scm = SCM_EOL;
for (node = kvp_value_get_glist (value); node; node = node->next)
scm = scm_cons (gnc_kvp_value2scm (node->data), scm);
scm = scm_reverse (scm);
break;
}
case KVP_TYPE_FRAME:
scm = gnc_kvp_frame2scm (kvp_value_get_frame (value));
break;
default:
scm = SCM_BOOL_F;
break;
}
value_scm = scm_cons (scm, value_scm);
return scm_reverse (value_scm);
}
typedef struct
{
SCM scm;
} KVPSCMData;
static void
kvp_frame_slot2scm (const char *key, KvpValue *value, gpointer data)
{
KVPSCMData *ksd = data;
SCM value_scm;
SCM key_scm;
SCM pair;
key_scm = key ? scm_from_utf8_string (key) : SCM_BOOL_F;
value_scm = gnc_kvp_value2scm (value);
pair = scm_cons (key_scm, value_scm);
ksd->scm = scm_cons (pair, ksd->scm);
}
static SCM
gnc_kvp_frame2scm (KvpFrame *frame)
{
KVPSCMData ksd;
if (!frame) return SCM_BOOL_F;
ksd.scm = SCM_EOL;
kvp_frame_for_each_slot (frame, kvp_frame_slot2scm, &ksd);
return ksd.scm;
}
static KvpFrame * gnc_scm2KvpFrame (SCM frame_scm);
static KvpValue *
gnc_scm2KvpValue (SCM value_scm)
{
KvpValueType value_t;
KvpValue *value = NULL;
SCM type_scm;
SCM val_scm;
if (!scm_is_list (value_scm) || scm_is_null (value_scm))
return NULL;
type_scm = SCM_CAR (value_scm);
value_t = gnc_scm2KvpValueType (type_scm);
value_scm = SCM_CDR (value_scm);
if (!scm_is_list (value_scm) || scm_is_null (value_scm))
return NULL;
val_scm = SCM_CAR (value_scm);
switch (value_t)
{
case KVP_TYPE_GINT64:
value = kvp_value_new_gint64 (scm_to_int64 (val_scm));
break;
case KVP_TYPE_DOUBLE:
value = kvp_value_new_double (scm_to_double (val_scm));
break;
case KVP_TYPE_STRING:
{
gchar * str;
str = gnc_scm_to_utf8_string (val_scm);
value = kvp_value_new_string (str);
g_free (str);
break;
}
case KVP_TYPE_GUID:
{
if (val_scm != SCM_BOOL_F)
{
GncGUID guid = gnc_scm2guid (val_scm);
value = kvp_value_new_guid (&guid);
}
else
value = NULL;
break;
}
case KVP_TYPE_TIMESPEC:
{
Timespec ts = gnc_timepair2timespec (val_scm);
value = kvp_value_new_timespec(ts);
break;
}
case KVP_TYPE_GDATE:
{
Timespec ts = gnc_timepair2timespec (val_scm);
value = kvp_value_new_gdate(timespec_to_gdate(ts));
break;
}
case KVP_TYPE_NUMERIC:
{
gnc_numeric n;
if (!gnc_query_numeric_p (val_scm))
return NULL;
n = gnc_query_scm2numeric (val_scm);
value = kvp_value_new_gnc_numeric (n);
break;
}
case KVP_TYPE_GLIST:
{
GList *list = NULL;
GList *node;
for (; scm_is_list (val_scm) && !scm_is_null (val_scm);
val_scm = SCM_CDR (val_scm))
{
SCM scm = SCM_CAR (val_scm);
list = g_list_prepend (list, gnc_scm2KvpValue (scm));
}
list = g_list_reverse (list);
value = kvp_value_new_glist (list);
for (node = list; node; node = node->next)
kvp_value_delete (node->data);
g_list_free (list);
break;
}
case KVP_TYPE_FRAME:
{
KvpFrame *frame;
frame = gnc_scm2KvpFrame (val_scm);
value = kvp_value_new_frame (frame);
kvp_frame_delete (frame);
break;
}
default:
break;
}
return value;
}
static KvpFrame *
gnc_scm2KvpFrame (SCM frame_scm)
{
KvpFrame * frame;
if (!scm_is_list (frame_scm)) return NULL;
frame = kvp_frame_new ();
for (; scm_is_list (frame_scm) && !scm_is_null (frame_scm);
frame_scm = SCM_CDR (frame_scm))
{
SCM pair = SCM_CAR (frame_scm);
KvpValue *value;
SCM key_scm;
SCM val_scm;
gchar *key;
if (!scm_is_pair (pair))
continue;
key_scm = SCM_CAR (pair);
val_scm = SCM_CDR (pair);
if (!scm_is_string (key_scm))
continue;
key = scm_to_utf8_string (key_scm); /* key should be freed with free !
This is automatically taken care
of by scm_dynwind_free below. */
scm_dynwind_begin (0);
scm_dynwind_free (key); /* free key whenever the dynwind context ends */
if (!key)
{
scm_dynwind_end ();
continue;
}
value = gnc_scm2KvpValue (val_scm); /* can exit non-locally so justifies
the use of scm_dynwind context
protection */
if (!value)
{
scm_dynwind_end ();
continue;
}
kvp_frame_set_slot_nc (frame, key, value);
scm_dynwind_end ();
}
return frame;
}
static SCM static SCM
gnc_queryterm2scm (const QofQueryTerm *qt) gnc_queryterm2scm (const QofQueryTerm *qt)
@ -1076,14 +743,6 @@ gnc_queryterm2scm (const QofQueryTerm *qt)
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm); qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (pdata->char_list ? scm_from_utf8_string (pdata->char_list) : SCM_BOOL_F, qt_scm); qt_scm = scm_cons (pdata->char_list ? scm_from_utf8_string (pdata->char_list) : SCM_BOOL_F, qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_KVP))
{
query_kvp_t pdata = (query_kvp_t) pd;
qt_scm = scm_cons (gnc_query_path2scm (pdata->path), qt_scm);
qt_scm = scm_cons (gnc_kvp_value2scm (pdata->value), qt_scm);
} }
else else
{ {
@ -1287,31 +946,6 @@ gnc_scm2query_term_query_v2 (SCM qt_scm)
pd = qof_query_char_predicate (options, char_list); pd = qof_query_char_predicate (options, char_list);
g_free (char_list); g_free (char_list);
} }
else if (!g_strcmp0 (type, QOF_TYPE_KVP))
{
GSList *kvp_path;
KvpValue *value;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (!scm_is_list (scm))
break;
kvp_path = gnc_query_scm2path (scm);
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
{
gnc_query_path_free (kvp_path);
break;
}
value = gnc_scm2KvpValue (scm);
pd = qof_query_kvp_predicate (compare_how, kvp_path, value);
gnc_query_path_free (kvp_path);
kvp_value_delete (value);
}
else else
{ {
PWARN ("query core type %s not supported", type); PWARN ("query core type %s not supported", type);
@ -1645,48 +1279,6 @@ gnc_scm2query_term_query_v1 (SCM query_term_scm)
g_free ((void *) id_type); g_free ((void *) id_type);
ok = TRUE; ok = TRUE;
}
else if (!g_strcmp0 (pd_type, "pd-kvp"))
{
GSList *path;
KvpValue *value;
QofQueryCompare how;
QofIdType where;
/* how */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
how = gnc_scm2kvp_match_how (scm);
/* where */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
where = gnc_scm2kvp_match_where (scm);
/* path */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
path = gnc_query_scm2path (scm);
/* value */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
value = gnc_scm2KvpValue (scm);
xaccQueryAddKVPMatch (q, path, value, how, where, QOF_QUERY_OR);
gnc_query_path_free (path);
kvp_value_delete (value);
ok = TRUE;
} }
else else
{ {

View File

@ -142,18 +142,6 @@ functions. */
QofSession * qof_session_new (void); QofSession * qof_session_new (void);
QofBook * qof_session_get_book (QofSession *session); QofBook * qof_session_get_book (QofSession *session);
/* This horror is to permit the scheme options in
* src/app-utils/options.scm to read and write the book's KVP (another
* horror) directly. It should be refactored into book functions that
* handle the KVP access.
*/
%inline {
KvpFrame *qof_book_get_slots (QofBook *book);
extern KvpFrame *qof_instance_get_slots (QofInstance*);
KvpFrame *qof_book_get_slots (QofBook *book) {
return qof_instance_get_slots (QOF_INSTANCE (book));
}
}
// TODO: Unroll/remove // TODO: Unroll/remove
const char *qof_session_get_url (QofSession *session); const char *qof_session_get_url (QofSession *session);
@ -238,10 +226,9 @@ Account * gnc_book_get_template_root(QofBook *book);
%typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); " %typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); "
%typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);" %typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
void gnc_kvp_frame_delete_at_path(KvpFrame *frame, GSList *key_path); void qof_book_options_delete (QofBook *book);
void kvp_frame_set_slot_path_gslist( void qof_book_set_option (QofBook *book, KvpValue *new_value, GSList *key_path);
KvpFrame *frame, KvpValue *new_value, GSList *key_path); KvpValue* qof_book_get_option (QofBook *book, GSList *key_path);
KvpValue * kvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path);
%clear GSList *key_path; %clear GSList *key_path;

View File

@ -42,11 +42,11 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
enum enum
{ {
PROP_0, PROP_0,
PROP_NAME, /* Table */ PROP_NAME, /* Table */
PROP_DESCRIPTION, /* Table */ PROP_DESCRIPTION, /* Table */
PROP_NUM_PERIODS, /* Table */ PROP_NUM_PERIODS, /* Table */
PROP_RUNTIME_0, PROP_RUNTIME_0,
PROP_RECURRENCE, /* Cached pointer; Recurrence table holds budget guid */ PROP_RECURRENCE, /* Cached pointer; Recurrence table holds budget guid */
}; };
struct budget_s struct budget_s
@ -159,7 +159,7 @@ gnc_budget_set_property( GObject* object,
budget = GNC_BUDGET(object); budget = GNC_BUDGET(object);
if (prop_id < PROP_RUNTIME_0) if (prop_id < PROP_RUNTIME_0)
g_assert (qof_instance_get_editlevel(budget)); g_assert (qof_instance_get_editlevel(budget));
switch ( prop_id ) switch ( prop_id )
{ {
@ -476,24 +476,29 @@ gnc_budget_get_num_periods(const GncBudget* budget)
#define BUF_SIZE (10 + GUID_ENCODING_LENGTH + \ #define BUF_SIZE (10 + GUID_ENCODING_LENGTH + \
GNC_BUDGET_MAX_NUM_PERIODS_DIGITS) GNC_BUDGET_MAX_NUM_PERIODS_DIGITS)
static inline void
make_period_path (const Account *account, guint period_num, char *path)
{
const GncGUID *guid;
gchar *bufend;
guid = xaccAccountGetGUID(account);
bufend = guid_to_string_buff(guid, path);
g_sprintf(bufend, "/%d", period_num);
}
/* period_num is zero-based */ /* period_num is zero-based */
/* What happens when account is deleted, after we have an entry for it? */ /* What happens when account is deleted, after we have an entry for it? */
void void
gnc_budget_unset_account_period_value(GncBudget *budget, const Account *account, gnc_budget_unset_account_period_value(GncBudget *budget, const Account *account,
guint period_num) guint period_num)
{ {
const GncGUID *guid;
KvpFrame *frame;
gchar path[BUF_SIZE]; gchar path[BUF_SIZE];
gchar *bufend;
g_return_if_fail (budget != NULL);
g_return_if_fail (account != NULL);
make_period_path (account, period_num, path);
gnc_budget_begin_edit(budget); gnc_budget_begin_edit(budget);
frame = qof_instance_get_slots(QOF_INSTANCE(budget)); qof_instance_set_kvp (QOF_INSTANCE (budget), path, NULL);
guid = xaccAccountGetGUID(account);
bufend = guid_to_string_buff(guid, path);
g_sprintf(bufend, "/%d", period_num);
kvp_frame_set_value(frame, path, NULL);
qof_instance_set_dirty(&budget->inst); qof_instance_set_dirty(&budget->inst);
gnc_budget_commit_edit(budget); gnc_budget_commit_edit(budget);
@ -507,10 +512,7 @@ void
gnc_budget_set_account_period_value(GncBudget *budget, const Account *account, gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
guint period_num, gnc_numeric val) guint period_num, gnc_numeric val)
{ {
const GncGUID *guid;
KvpFrame *frame;
gchar path[BUF_SIZE]; gchar path[BUF_SIZE];
gchar *bufend;
/* Watch out for an off-by-one error here: /* Watch out for an off-by-one error here:
* period_num starts from 0 while num_periods starts from 1 */ * period_num starts from 0 while num_periods starts from 1 */
@ -520,16 +522,21 @@ gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
return; return;
} }
gnc_budget_begin_edit(budget); g_return_if_fail (budget != NULL);
frame = qof_instance_get_slots(QOF_INSTANCE(budget)); g_return_if_fail (account != NULL);
guid = xaccAccountGetGUID(account);
bufend = guid_to_string_buff(guid, path);
g_sprintf(bufend, "/%d", period_num);
make_period_path (account, period_num, path);
gnc_budget_begin_edit(budget);
if (gnc_numeric_check(val)) if (gnc_numeric_check(val))
kvp_frame_set_value(frame, path, NULL); qof_instance_set_kvp (QOF_INSTANCE (budget), path, NULL);
else else
kvp_frame_set_numeric(frame, path, val); {
GValue v = G_VALUE_INIT;
g_value_init (&v, GNC_TYPE_NUMERIC);
g_value_set_boxed (&v, &val);
qof_instance_set_kvp (QOF_INSTANCE (budget), path, &v);
}
qof_instance_set_dirty(&budget->inst); qof_instance_set_dirty(&budget->inst);
gnc_budget_commit_edit(budget); gnc_budget_commit_edit(budget);
@ -541,42 +548,44 @@ gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
Maybe this should move to Account.h */ Maybe this should move to Account.h */
gboolean gboolean
gnc_budget_is_account_period_value_set(const GncBudget *budget, const Account *account, gnc_budget_is_account_period_value_set(const GncBudget *budget,
const Account *account,
guint period_num) guint period_num)
{ {
GValue v = G_VALUE_INIT;
gchar path[BUF_SIZE]; gchar path[BUF_SIZE];
gchar *bufend; gconstpointer ptr = NULL;
KvpFrame *frame;
g_return_val_if_fail(GNC_IS_BUDGET(budget), FALSE); g_return_val_if_fail(GNC_IS_BUDGET(budget), FALSE);
g_return_val_if_fail(account, FALSE); g_return_val_if_fail(account, FALSE);
frame = qof_instance_get_slots(QOF_INSTANCE(budget)); make_period_path (account, period_num, path);
bufend = guid_to_string_buff(xaccAccountGetGUID(account), path); qof_instance_get_kvp (QOF_INSTANCE (budget), path, &v);
g_sprintf(bufend, "/%d", period_num); if (G_VALUE_HOLDS_BOXED (&v))
return (kvp_frame_get_value(frame, path) != NULL); ptr = g_value_get_boxed (&v);
return (ptr != NULL);
} }
gnc_numeric gnc_numeric
gnc_budget_get_account_period_value(const GncBudget *budget, const Account *account, gnc_budget_get_account_period_value(const GncBudget *budget,
const Account *account,
guint period_num) guint period_num)
{ {
gnc_numeric numeric; gnc_numeric *numeric = NULL;
gchar path[BUF_SIZE]; gchar path[BUF_SIZE];
gchar *bufend; GValue v = G_VALUE_INIT;
KvpFrame *frame;
numeric = gnc_numeric_zero(); g_return_val_if_fail(GNC_IS_BUDGET(budget), gnc_numeric_zero());
g_return_val_if_fail(GNC_IS_BUDGET(budget), numeric); g_return_val_if_fail(account, gnc_numeric_zero());
g_return_val_if_fail(account, numeric);
frame = qof_instance_get_slots(QOF_INSTANCE(budget)); make_period_path (account, period_num, path);
bufend = guid_to_string_buff(xaccAccountGetGUID(account), path); qof_instance_get_kvp (QOF_INSTANCE (budget), path, &v);
g_sprintf(bufend, "/%d", period_num); if (G_VALUE_HOLDS_BOXED (&v))
numeric = (gnc_numeric*)g_value_get_boxed (&v);
numeric = kvp_frame_get_numeric(frame, path); if (numeric)
/* This still returns zero if unset, but callers can check for that. */ return *numeric;
return numeric; return gnc_numeric_zero();
} }
@ -637,16 +646,14 @@ gnc_budget_get_default (QofBook *book)
g_return_val_if_fail(book, NULL); g_return_val_if_fail(book, NULL);
/* See if there is a budget selected in the KVP perferences */
qof_instance_get (QOF_INSTANCE (book), qof_instance_get (QOF_INSTANCE (book),
"default-budget", &default_budget_guid, "default-budget", &default_budget_guid,
NULL); NULL);
if (default_budget_guid != NULL) if (default_budget_guid != NULL)
{ {
col = qof_book_get_collection(book, GNC_ID_BUDGET); col = qof_book_get_collection(book, GNC_ID_BUDGET);
bgt = (GncBudget *) qof_collection_lookup_entity(col, bgt = (GncBudget *) qof_collection_lookup_entity(col,
default_budget_guid); default_budget_guid);
} }
/* Revert to 2.2.x behavior if the book has no default budget. */ /* Revert to 2.2.x behavior if the book has no default budget. */

View File

@ -940,8 +940,7 @@ gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src)
gnc_commodity_set_quote_flag (dest, src_priv->quote_flag); gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src)); gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
gnc_commodity_set_quote_tz (dest, src_priv->quote_tz); gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
kvp_frame_delete (dest->inst.kvp_data); qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
} }
gnc_commodity * gnc_commodity *
@ -967,8 +966,7 @@ gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src)); gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
kvp_frame_delete (dest->inst.kvp_data); qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
reset_printname(dest_priv); reset_printname(dest_priv);
reset_unique_name(dest_priv); reset_unique_name(dest_priv);
@ -1087,11 +1085,14 @@ static gboolean
gnc_commodity_get_auto_quote_control_flag(const gnc_commodity *cm) gnc_commodity_get_auto_quote_control_flag(const gnc_commodity *cm)
{ {
const char *str; const char *str;
GValue v = G_VALUE_INIT;
if (!cm) return FALSE; if (!cm) return FALSE;
qof_instance_get_kvp (QOF_INSTANCE (cm), "auto_quote_control", &v);
str = kvp_frame_get_string(cm->inst.kvp_data, "auto_quote_control"); if (G_VALUE_HOLDS_STRING (&v) &&
return !str || (strcmp(str, "false") != 0); strcmp(g_value_get_string (&v), "false") == 0)
return FALSE;
return TRUE;
} }
/******************************************************************** /********************************************************************
@ -1148,8 +1149,12 @@ const char*
gnc_commodity_get_user_symbol(const gnc_commodity *cm) gnc_commodity_get_user_symbol(const gnc_commodity *cm)
{ {
const char *str; const char *str;
GValue v = G_VALUE_INIT;
if (!cm) return NULL; if (!cm) return NULL;
return kvp_frame_get_string(cm->inst.kvp_data, "user_symbol"); qof_instance_get_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
/******************************************************************** /********************************************************************
@ -1308,6 +1313,7 @@ static void
gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm, gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
const gboolean flag) const gboolean flag)
{ {
GValue v = G_VALUE_INIT;
ENTER ("(cm=%p, flag=%d)", cm, flag); ENTER ("(cm=%p, flag=%d)", cm, flag);
if (!cm) if (!cm)
@ -1315,10 +1321,15 @@ gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
LEAVE(""); LEAVE("");
return; return;
} }
gnc_commodity_begin_edit(cm); gnc_commodity_begin_edit(cm);
kvp_frame_set_string(cm->inst.kvp_data, if (flag)
"auto_quote_control", flag ? NULL : "false"); qof_instance_set_kvp (QOF_INSTANCE (cm), "auto_quote_control", NULL);
else
{
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, "false");
qof_instance_set_kvp (QOF_INSTANCE (cm), "auto_quote_control", &v);
}
mark_commodity_dirty(cm); mark_commodity_dirty(cm);
gnc_commodity_commit_edit(cm); gnc_commodity_commit_edit(cm);
LEAVE(""); LEAVE("");
@ -1431,7 +1442,7 @@ void
gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol) gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
{ {
struct lconv *lc; struct lconv *lc;
GValue v = G_VALUE_INIT;
if (!cm) return; if (!cm) return;
ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)"); ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
@ -1448,8 +1459,15 @@ gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
user_symbol = NULL; user_symbol = NULL;
else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm))) else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
user_symbol = NULL; user_symbol = NULL;
if (user_symbol)
{
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, user_symbol);
qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
}
else
qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", NULL);
kvp_frame_set_string(cm->inst.kvp_data, "user_symbol", user_symbol);
mark_commodity_dirty(cm); mark_commodity_dirty(cm);
gnc_commodity_commit_edit(cm); gnc_commodity_commit_edit(cm);

View File

@ -64,15 +64,15 @@ struct gnc_lot_s
enum enum
{ {
PROP_0, PROP_0,
// PROP_ACCOUNT, /* Table */ // PROP_ACCOUNT, /* Table */
PROP_IS_CLOSED, /* Table */ PROP_IS_CLOSED, /* Table */
PROP_INVOICE, /* KVP */ PROP_INVOICE, /* KVP */
PROP_OWNER_TYPE, /* KVP */ PROP_OWNER_TYPE, /* KVP */
PROP_OWNER_GUID, /* KVP */ PROP_OWNER_GUID, /* KVP */
PROP_RUNTIME_0, PROP_RUNTIME_0,
PROP_MARKER, /* Runtime */ PROP_MARKER, /* Runtime */
}; };
typedef struct LotPrivate typedef struct LotPrivate
@ -138,7 +138,6 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
{ {
GNCLot* lot; GNCLot* lot;
LotPrivate* priv; LotPrivate* priv;
KvpFrame *frame;
gchar *key; gchar *key;
GValue *temp; GValue *temp;
@ -155,17 +154,17 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
g_value_set_int(value, priv->marker); g_value_set_int(value, priv->marker);
break; break;
case PROP_INVOICE: case PROP_INVOICE:
key = GNC_INVOICE_ID "/" GNC_INVOICE_GUID; key = GNC_INVOICE_ID "/" GNC_INVOICE_GUID;
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value); qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
break; break;
case PROP_OWNER_TYPE: case PROP_OWNER_TYPE:
key = GNC_OWNER_ID"/" GNC_OWNER_TYPE; key = GNC_OWNER_ID"/" GNC_OWNER_TYPE;
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value); qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
break; break;
case PROP_OWNER_GUID: case PROP_OWNER_GUID:
key = GNC_OWNER_ID "/" GNC_OWNER_GUID; key = GNC_OWNER_ID "/" GNC_OWNER_GUID;
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value); qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -174,20 +173,19 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
static void static void
gnc_lot_set_property (GObject* object, gnc_lot_set_property (GObject* object,
guint prop_id, guint prop_id,
const GValue* value, const GValue* value,
GParamSpec* pspec) GParamSpec* pspec)
{ {
GNCLot* lot; GNCLot* lot;
LotPrivate* priv; LotPrivate* priv;
KvpFrame *frame;
gchar *key = NULL; gchar *key = NULL;
g_return_if_fail(GNC_IS_LOT(object)); g_return_if_fail(GNC_IS_LOT(object));
lot = GNC_LOT(object); lot = GNC_LOT(object);
if (prop_id < PROP_RUNTIME_0) if (prop_id < PROP_RUNTIME_0)
g_assert (qof_instance_get_editlevel(lot)); g_assert (qof_instance_get_editlevel(lot));
priv = GET_PRIVATE(lot); priv = GET_PRIVATE(lot);
switch (prop_id) switch (prop_id)
@ -199,17 +197,17 @@ gnc_lot_set_property (GObject* object,
priv->marker = g_value_get_int(value); priv->marker = g_value_get_int(value);
break; break;
case PROP_INVOICE: case PROP_INVOICE:
key = GNC_INVOICE_ID"/" GNC_INVOICE_GUID; key = GNC_INVOICE_ID"/" GNC_INVOICE_GUID;
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value); qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
break; break;
case PROP_OWNER_TYPE: case PROP_OWNER_TYPE:
key = GNC_OWNER_ID "/" GNC_OWNER_TYPE; key = GNC_OWNER_ID "/" GNC_OWNER_TYPE;
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value); qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
break; break;
case PROP_OWNER_GUID: case PROP_OWNER_GUID:
key = GNC_OWNER_ID "/" GNC_OWNER_GUID; key = GNC_OWNER_ID "/" GNC_OWNER_GUID;
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value); qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -251,28 +249,28 @@ gnc_lot_class_init(GNCLotClass* klass)
gobject_class, gobject_class,
PROP_INVOICE, PROP_INVOICE,
g_param_spec_boxed("invoice", g_param_spec_boxed("invoice",
"Invoice attached to lot", "Invoice attached to lot",
"Used by GncInvoice", "Used by GncInvoice",
GNC_TYPE_GUID, GNC_TYPE_GUID,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_OWNER_TYPE, PROP_OWNER_TYPE,
g_param_spec_int64("owner-type", g_param_spec_int64("owner-type",
"Owning Entity Type of lot", "Owning Entity Type of lot",
"Used by GncOwner", "Used by GncOwner",
0, G_MAXINT64, 0, 0, G_MAXINT64, 0,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_OWNER_GUID, PROP_OWNER_GUID,
g_param_spec_boxed("owner-guid", g_param_spec_boxed("owner-guid",
"Owner attached to lot", "Owner attached to lot",
"Used by GncOwner", "Used by GncOwner",
GNC_TYPE_GUID, GNC_TYPE_GUID,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
GNCLot * GNCLot *
@ -436,38 +434,48 @@ gint gnc_lot_count_splits (const GNCLot *lot)
const char * const char *
gnc_lot_get_title (const GNCLot *lot) gnc_lot_get_title (const GNCLot *lot)
{ {
GValue v = G_VALUE_INIT;
if (!lot) return NULL; if (!lot) return NULL;
return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)), qof_instance_get_kvp (QOF_INSTANCE (lot), "/title", &v);
"/title"); if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
const char * const char *
gnc_lot_get_notes (const GNCLot *lot) gnc_lot_get_notes (const GNCLot *lot)
{ {
GValue v = G_VALUE_INIT;
if (!lot) return NULL; if (!lot) return NULL;
return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)), qof_instance_get_kvp (QOF_INSTANCE (lot), "/notes", &v);
"/notes"); if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
} }
void void
gnc_lot_set_title (GNCLot *lot, const char *str) gnc_lot_set_title (GNCLot *lot, const char *str)
{ {
GValue v = G_VALUE_INIT;
if (!lot) return; if (!lot) return;
qof_begin_edit(QOF_INSTANCE(lot)); qof_begin_edit(QOF_INSTANCE(lot));
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, str);
qof_instance_set_kvp (QOF_INSTANCE (lot), "/title", &v);
qof_instance_set_dirty(QOF_INSTANCE(lot)); qof_instance_set_dirty(QOF_INSTANCE(lot));
kvp_frame_set_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
"/title", str);
gnc_lot_commit_edit(lot); gnc_lot_commit_edit(lot);
} }
void void
gnc_lot_set_notes (GNCLot *lot, const char *str) gnc_lot_set_notes (GNCLot *lot, const char *str)
{ {
GValue v = G_VALUE_INIT;
if (!lot) return; if (!lot) return;
gnc_lot_begin_edit(lot); qof_begin_edit(QOF_INSTANCE(lot));
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, str);
qof_instance_set_kvp (QOF_INSTANCE (lot), "/notes", &v);
qof_instance_set_dirty(QOF_INSTANCE(lot)); qof_instance_set_dirty(QOF_INSTANCE(lot));
kvp_frame_set_string (qof_instance_get_slots (QOF_INSTANCE (lot)),
"/notes", str);
gnc_lot_commit_edit(lot); gnc_lot_commit_edit(lot);
} }

View File

@ -49,6 +49,38 @@ enum
PROP_VALUE, /* Table, 2 fields (numeric) */ PROP_VALUE, /* Table, 2 fields (numeric) */
}; };
typedef struct
{
gpointer key;
gpointer value;
} HashEntry;
static void
hash_entry_insert(gpointer key, gpointer val, gpointer user_data)
{
GSList **result = (GSList **) user_data;
HashEntry *entry = g_new(HashEntry, 1);
entry->key = key;
entry->value = val;
*result = g_slist_prepend(*result, entry);
}
static GSList *
hash_table_to_list(GHashTable *table)
{
GSList *result_list = NULL;
g_hash_table_foreach(table, hash_entry_insert, &result_list);
return result_list;
}
static void
hash_entry_free_gfunc(gpointer data, G_GNUC_UNUSED gpointer user_data)
{
HashEntry *entry = (HashEntry *) data;
g_free(entry);
}
/* GObject Initialization */ /* GObject Initialization */
G_DEFINE_TYPE(GNCPrice, gnc_price, QOF_TYPE_INSTANCE); G_DEFINE_TYPE(GNCPrice, gnc_price, QOF_TYPE_INSTANCE);
@ -2261,10 +2293,10 @@ unstable_price_traversal(GNCPriceDB *db,
} }
static gint static gint
compare_kvpairs_by_commodity_key(gconstpointer a, gconstpointer b) compare_hash_entries_by_commodity_key(gconstpointer a, gconstpointer b)
{ {
GHashTableKVPair *kvpa = (GHashTableKVPair *) a; HashEntry *he_a = (HashEntry *) a;
GHashTableKVPair *kvpb = (GHashTableKVPair *) b; HashEntry *he_b = (HashEntry *) b;
gnc_commodity *ca; gnc_commodity *ca;
gnc_commodity *cb; gnc_commodity *cb;
int cmp_result; int cmp_result;
@ -2274,8 +2306,8 @@ compare_kvpairs_by_commodity_key(gconstpointer a, gconstpointer b)
if (!a) return -1; if (!a) return -1;
if (!b) return 1; if (!b) return 1;
ca = (gnc_commodity *) kvpa->key; ca = (gnc_commodity *) he_a->key;
cb = (gnc_commodity *) kvpb->key; cb = (gnc_commodity *) he_b->key;
cmp_result = g_strcmp0(gnc_commodity_get_namespace(ca), cmp_result = g_strcmp0(gnc_commodity_get_namespace(ca),
gnc_commodity_get_namespace(cb)); gnc_commodity_get_namespace(cb));
@ -2297,22 +2329,22 @@ stable_price_traversal(GNCPriceDB *db,
if (!db || !f) return FALSE; if (!db || !f) return FALSE;
currency_hashes = g_hash_table_key_value_pairs(db->commodity_hash); currency_hashes = hash_table_to_list(db->commodity_hash);
currency_hashes = g_slist_sort(currency_hashes, currency_hashes = g_slist_sort(currency_hashes,
compare_kvpairs_by_commodity_key); compare_hash_entries_by_commodity_key);
for (i = currency_hashes; i; i = i->next) for (i = currency_hashes; i; i = i->next)
{ {
GHashTableKVPair *kv_pair = (GHashTableKVPair *) i->data; HashEntry *entry = (HashEntry *) i->data;
GHashTable *currency_hash = (GHashTable *) kv_pair->value; GHashTable *currency_hash = (GHashTable *) entry->value;
GSList *price_lists = g_hash_table_key_value_pairs(currency_hash); GSList *price_lists = hash_table_to_list(currency_hash);
GSList *j; GSList *j;
price_lists = g_slist_sort(price_lists, compare_kvpairs_by_commodity_key); price_lists = g_slist_sort(price_lists, compare_hash_entries_by_commodity_key);
for (j = price_lists; j; j = j->next) for (j = price_lists; j; j = j->next)
{ {
GHashTableKVPair *pricelist_kvp = (GHashTableKVPair *) j->data; HashEntry *pricelist_entry = (HashEntry *) j->data;
GList *price_list = (GList *) pricelist_kvp->value; GList *price_list = (GList *) pricelist_entry->value;
GList *node; GList *node;
for (node = (GList *) price_list; node; node = node->next) for (node = (GList *) price_list; node; node = node->next)
@ -2326,7 +2358,7 @@ stable_price_traversal(GNCPriceDB *db,
} }
if (price_lists) if (price_lists)
{ {
g_slist_foreach(price_lists, g_hash_table_kv_pair_free_gfunc, NULL); g_slist_foreach(price_lists, hash_entry_free_gfunc, NULL);
g_slist_free(price_lists); g_slist_free(price_lists);
price_lists = NULL; price_lists = NULL;
} }
@ -2334,7 +2366,7 @@ stable_price_traversal(GNCPriceDB *db,
if (currency_hashes) if (currency_hashes)
{ {
g_slist_foreach(currency_hashes, g_hash_table_kv_pair_free_gfunc, NULL); g_slist_foreach(currency_hashes, hash_entry_free_gfunc, NULL);
g_slist_free(currency_hashes); g_slist_free(currency_hashes);
} }
return ok; return ok;

View File

@ -495,7 +495,7 @@ static void address_free (QofInstance *inst)
void gncAddressCommitEdit (GncAddress *addr) void gncAddressCommitEdit (GncAddress *addr)
{ {
/* GnuCash 2.6.3 and earlier didn't handle address kvp's... */ /* GnuCash 2.6.3 and earlier didn't handle address kvp's... */
if (!kvp_frame_is_empty (addr->inst.kvp_data)) if (qof_instance_has_kvp(QOF_INSTANCE(addr)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (addr)), GNC_FEATURE_KVP_EXTRA_DATA); gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (addr)), GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(addr))) return; if (!qof_commit_edit (QOF_INSTANCE(addr))) return;

View File

@ -1532,8 +1532,9 @@ static void entry_free (QofInstance *inst)
void gncEntryCommitEdit (GncEntry *entry) void gncEntryCommitEdit (GncEntry *entry)
{ {
/* GnuCash 2.6.3 and earlier didn't handle entry kvp's... */ /* GnuCash 2.6.3 and earlier didn't handle entry kvp's... */
if (!kvp_frame_is_empty (entry->inst.kvp_data)) if (qof_instance_has_kvp(QOF_INSTANCE(entry)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (entry)), GNC_FEATURE_KVP_EXTRA_DATA); gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (entry)),
GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(entry))) return; if (!qof_commit_edit (QOF_INSTANCE(entry))) return;
qof_commit_edit_part2 (&entry->inst, gncEntryOnError, qof_commit_edit_part2 (&entry->inst, gncEntryOnError,

View File

@ -338,7 +338,7 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
GncInvoice *invoice; GncInvoice *invoice;
QofBook* book; QofBook* book;
GList *node; GList *node;
gint64 is_cn; GValue v = G_VALUE_INIT;
g_assert(from); g_assert(from);
book = qof_instance_get_book(from); book = qof_instance_get_book(from);
@ -354,8 +354,9 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
invoice->billing_id = CACHE_INSERT (from->billing_id); invoice->billing_id = CACHE_INSERT (from->billing_id);
invoice->active = from->active; invoice->active = from->active;
is_cn = kvp_frame_get_gint64(from->inst.kvp_data, GNC_INVOICE_IS_CN); qof_instance_get_kvp (QOF_INSTANCE (from), GNC_INVOICE_IS_CN, &v);
kvp_frame_set_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN, is_cn); if (G_VALUE_HOLDS_INT64 (&v))
qof_instance_set_kvp (QOF_INSTANCE (invoice), GNC_INVOICE_IS_CN, &v);
invoice->terms = from->terms; invoice->terms = from->terms;
gncBillTermIncRef (invoice->terms); gncBillTermIncRef (invoice->terms);
@ -545,10 +546,12 @@ void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note) void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
{ {
GValue v = G_VALUE_INIT;
if (!invoice) return; if (!invoice) return;
gncInvoiceBeginEdit (invoice); gncInvoiceBeginEdit (invoice);
kvp_frame_set_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN, g_value_init (&v, G_TYPE_INT64);
credit_note ? 1 : 0); g_value_set_int64(&v, credit_note ? 1 : 0);
qof_instance_set_kvp (QOF_INSTANCE (invoice), GNC_INVOICE_IS_CN, &v);
mark_invoice (invoice); mark_invoice (invoice);
gncInvoiceCommitEdit (invoice); gncInvoiceCommitEdit (invoice);
@ -1035,8 +1038,10 @@ gboolean gncInvoiceGetActive (const GncInvoice *invoice)
gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice) gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice)
{ {
GValue v = G_VALUE_INIT;
if (!invoice) return FALSE; if (!invoice) return FALSE;
if (kvp_frame_get_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN)) qof_instance_get_kvp (QOF_INSTANCE(invoice), GNC_INVOICE_IS_CN, &v);
if (G_VALUE_HOLDS_INT64(&v) && g_value_get_int64(&v))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;

View File

@ -73,13 +73,13 @@ void mark_job (GncJob *job)
enum enum
{ {
PROP_0, PROP_0,
// PROP_ID, /* Table */ // PROP_ID, /* Table */
PROP_NAME, /* Table */ PROP_NAME, /* Table */
// PROP_REFERENCE, /* Table */ // PROP_REFERENCE, /* Table */
// PROP_ACTIVE, /* Table */ // PROP_ACTIVE, /* Table */
// PROP_OWNER_TYPE, /* Table */ // PROP_OWNER_TYPE, /* Table */
// PROP_OWNER, /* Table */ // PROP_OWNER, /* Table */
PROP_PDF_DIRNAME, /* KVP */ PROP_PDF_DIRNAME, /* KVP */
}; };
/* GObject Initialization */ /* GObject Initialization */
@ -120,9 +120,9 @@ gnc_job_get_property (GObject *object,
g_value_set_string(value, job->name); g_value_set_string(value, job->name);
break; break;
case PROP_PDF_DIRNAME: case PROP_PDF_DIRNAME:
key = OWNER_EXPORT_PDF_DIRNAME; key = OWNER_EXPORT_PDF_DIRNAME;
qof_instance_get_kvp (QOF_INSTANCE (job), key, value); qof_instance_get_kvp (QOF_INSTANCE (job), key, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -149,9 +149,9 @@ gnc_job_set_property (GObject *object,
gncJobSetName(job, g_value_get_string(value)); gncJobSetName(job, g_value_get_string(value));
break; break;
case PROP_PDF_DIRNAME: case PROP_PDF_DIRNAME:
key = OWNER_EXPORT_PDF_DIRNAME; key = OWNER_EXPORT_PDF_DIRNAME;
qof_instance_set_kvp (QOF_INSTANCE (job), key, value); qof_instance_set_kvp (QOF_INSTANCE (job), key, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -204,10 +204,10 @@ gnc_job_class_init (GncJobClass *klass)
g_param_spec_string ("export-pdf-dir", g_param_spec_string ("export-pdf-dir",
"Export PDF Directory Name", "Export PDF Directory Name",
"A subdirectory for exporting PDF reports which is " "A subdirectory for exporting PDF reports which is "
"appended to the target directory when writing them " "appended to the target directory when writing them "
"out. It is retrieved from preferences and stored on " "out. It is retrieved from preferences and stored on "
"each 'Owner' object which prints items after " "each 'Owner' object which prints items after "
"printing.", "printing.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
@ -314,16 +314,15 @@ void gncJobSetRate (GncJob *job, gnc_numeric rate)
gncJobBeginEdit (job); gncJobBeginEdit (job);
if (!gnc_numeric_zero_p(rate)) if (!gnc_numeric_zero_p(rate))
kvp_frame_set_numeric(job->inst.kvp_data, GNC_JOB_RATE, rate); {
GValue v = G_VALUE_INIT;
g_value_init (&v, GNC_TYPE_NUMERIC);
g_value_set_boxed (&v, &rate);
qof_instance_set_kvp (QOF_INSTANCE (job), GNC_JOB_RATE, &v);
}
else else
{ {
KvpFrame *frame; qof_instance_set_kvp (QOF_INSTANCE (job), GNC_JOB_RATE, NULL);
KvpValue *value;
value = NULL;
frame = kvp_frame_set_value_nc (job->inst.kvp_data,
GNC_JOB_RATE, value);
if (!frame) kvp_value_delete (value);
} }
mark_job (job); mark_job (job);
gncJobCommitEdit (job); gncJobCommitEdit (job);
@ -423,7 +422,7 @@ static void gncJobOnDone (QofInstance *qof) { }
void gncJobCommitEdit (GncJob *job) void gncJobCommitEdit (GncJob *job)
{ {
/* GnuCash 2.6.3 and earlier didn't handle job kvp's... */ /* GnuCash 2.6.3 and earlier didn't handle job kvp's... */
if (!kvp_frame_is_empty (job->inst.kvp_data)) if (qof_instance_has_kvp (QOF_INSTANCE (job)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (job)), GNC_FEATURE_KVP_EXTRA_DATA); gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (job)), GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(job))) return; if (!qof_commit_edit (QOF_INSTANCE(job))) return;
@ -454,8 +453,15 @@ const char * gncJobGetReference (const GncJob *job)
gnc_numeric gncJobGetRate (const GncJob *job) gnc_numeric gncJobGetRate (const GncJob *job)
{ {
GValue v = G_VALUE_INIT;
gnc_numeric *rate = NULL;
if (!job) return gnc_numeric_zero (); if (!job) return gnc_numeric_zero ();
return kvp_frame_get_numeric(job->inst.kvp_data, GNC_JOB_RATE); qof_instance_get_kvp (QOF_INSTANCE (job), GNC_JOB_RATE, &v);
if (G_VALUE_HOLDS_BOXED (&v))
rate = (gnc_numeric*)g_value_get_boxed (&v);
if (rate)
return *rate;
return gnc_numeric_zero();
} }
GncOwner * gncJobGetOwner (GncJob *job) GncOwner * gncJobGetOwner (GncJob *job)

View File

@ -655,8 +655,9 @@ static void table_free (QofInstance *inst)
void gncTaxTableCommitEdit (GncTaxTable *table) void gncTaxTableCommitEdit (GncTaxTable *table)
{ {
/* GnuCash 2.6.3 and earlier didn't handle taxtable kvp's... */ /* GnuCash 2.6.3 and earlier didn't handle taxtable kvp's... */
if (!kvp_frame_is_empty (table->inst.kvp_data)) if (qof_instance_has_kvp (QOF_INSTANCE (table)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (table)), GNC_FEATURE_KVP_EXTRA_DATA); gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (table)),
GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(table))) return; if (!qof_commit_edit (QOF_INSTANCE(table))) return;
qof_commit_edit_part2 (&table->inst, gncTaxTableOnError, qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,

View File

@ -1,13 +1,19 @@
#include <libguile.h>
extern "C"
{
#include "config.h" #include "config.h"
#include "qof.h" #include <qof.h>
#include <libguile.h>
#include "engine-helpers-guile.h" #include "engine-helpers-guile.h"
#include "kvp-scm.h"
#include "guile-mappings.h" #include "guile-mappings.h"
#include "gnc-guile-utils.h" #include "gnc-guile-utils.h"
#include "swig-runtime.h" #include "swig-runtime.h"
#include "kvp-scm.h"
}
#include <kvp_frame.hpp>
/* NOTE: There are some problems with this approach. Currently, /* NOTE: There are some problems with this approach. Currently,
* guids are stored simply as strings in scheme, so some * guids are stored simply as strings in scheme, so some
@ -24,43 +30,40 @@ gnc_scm_to_kvp_value_ptr(SCM val)
/* in guile 1.8 (exact? ) only works on numbers */ /* in guile 1.8 (exact? ) only works on numbers */
if (scm_is_exact (val) && gnc_gh_gint64_p(val)) if (scm_is_exact (val) && gnc_gh_gint64_p(val))
{ {
return kvp_value_new_gint64(scm_to_int64(val)); return new KvpValue{scm_to_int64(val)};
} }
else else
{ {
return kvp_value_new_double(scm_to_double(val)); return new KvpValue{scm_to_double(val)};
} }
} }
else if (gnc_numeric_p(val)) else if (gnc_numeric_p(val))
{ {
return kvp_value_new_gnc_numeric(gnc_scm_to_numeric(val)); return new KvpValue{gnc_scm_to_numeric(val)};
} }
else if (gnc_guid_p(val)) else if (gnc_guid_p(val))
{ {
GncGUID tmpguid = gnc_scm2guid(val); auto guid = gnc_scm2guid(val);
return kvp_value_new_guid(&tmpguid); auto tmpguid = guid_copy(&guid);
return new KvpValue{tmpguid};
} }
else if (gnc_timepair_p(val)) else if (gnc_timepair_p(val))
{ {
Timespec ts = gnc_timepair2timespec(val); Timespec ts = gnc_timepair2timespec(val);
return kvp_value_new_timespec(ts); return new KvpValue{ts};
} }
else if (scm_is_string(val)) else if (scm_is_string(val))
{ {
gchar *newstr; return new KvpValue{gnc_scm_to_utf8_string(val)};
KvpValue *ret;
newstr = gnc_scm_to_utf8_string (val);
ret = kvp_value_new_string(newstr);
g_free (newstr);
return ret;
} }
else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame"))) else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame")))
{ {
#define FUNC_NAME G_STRFUNC #define FUNC_NAME G_STRFUNC
KvpFrame *frame = SWIG_MustGetPtr(val, SWIG_TypeQuery("_p_KvpFrame"), auto vp_frame = SWIG_MustGetPtr(val,
1, 0); SWIG_TypeQuery("_p_KvpFrame"), 1, 0);
KvpFrame *frame = static_cast<KvpFrame*>(vp_frame);
#undef FUNC_NAME #undef FUNC_NAME
return kvp_value_new_frame (frame); return new KvpValue{frame};
} }
/* FIXME: add list handler here */ /* FIXME: add list handler here */
return NULL; return NULL;
@ -69,52 +72,49 @@ gnc_scm_to_kvp_value_ptr(SCM val)
SCM SCM
gnc_kvp_value_ptr_to_scm(KvpValue* val) gnc_kvp_value_ptr_to_scm(KvpValue* val)
{ {
const gchar *string; if (val == nullptr) return SCM_BOOL_F;
switch (kvp_value_get_type(val))
switch (val->get_type())
{ {
case KVP_TYPE_GINT64: case KvpValue::Type::INT64:
return scm_from_int64(kvp_value_get_gint64(val)); return scm_from_int64(val->get<int64_t>());
break; break;
case KVP_TYPE_DOUBLE: case KvpValue::Type::DOUBLE:
return scm_from_double (kvp_value_get_double(val)); return scm_from_double (val->get<double>());
break; break;
case KVP_TYPE_NUMERIC: case KvpValue::Type::NUMERIC:
return gnc_numeric_to_scm(kvp_value_get_numeric(val)); return gnc_numeric_to_scm(val->get<gnc_numeric>());
break; break;
case KVP_TYPE_STRING: case KvpValue::Type::STRING:
string = kvp_value_get_string(val); {
auto string = val->get<const char*>();
return string ? scm_from_utf8_string(string) : SCM_BOOL_F; return string ? scm_from_utf8_string(string) : SCM_BOOL_F;
break; break;
case KVP_TYPE_GUID: }
case KvpValue::Type::GUID:
{ {
GncGUID *tempguid = kvp_value_get_guid(val); auto tempguid = val->get<GncGUID*>();
return gnc_guid2scm(*tempguid); return gnc_guid2scm(*tempguid);
} }
break; break;
case KVP_TYPE_TIMESPEC: case KvpValue::Type::TIMESPEC:
return gnc_timespec2timepair(kvp_value_get_timespec(val)); return gnc_timespec2timepair(val->get<Timespec>());
break; break;
case KVP_TYPE_FRAME: case KvpValue::Type::FRAME:
{ {
KvpFrame *frame = kvp_value_get_frame(val); auto frame = val->get<KvpFrame*>();
if (frame) if (frame != nullptr)
return SWIG_NewPointerObj(frame, SWIG_TypeQuery("_p_KvpFrame"), 0); return SWIG_NewPointerObj(frame, SWIG_TypeQuery("_p_KvpFrame"), 0);
} }
break; break;
case KVP_TYPE_GDATE: case KvpValue::Type::GDATE:
return gnc_timespec2timepair(gdate_to_timespec(kvp_value_get_gdate(val))); return gnc_timespec2timepair(gdate_to_timespec(val->get<GDate>()));
/* FIXME: handle types below */ /* FIXME: handle types below */
case KVP_TYPE_GLIST: case KvpValue::Type::GLIST:
default: default:
break; break;
} }
return SCM_BOOL_F; return SCM_BOOL_F;
} }
void
gnc_kvp_frame_delete_at_path (KvpFrame *frame, GSList *key_path)
{
kvp_frame_set_slot_path_gslist (frame, NULL, key_path);
}

View File

@ -1,12 +1,18 @@
#ifndef KVP_SCM_H #ifndef KVP_SCM_H
#define KVP_SCM_H #define KVP_SCM_H
#include "qof.h" #ifdef __cplusplus
extern "C"
{
#endif
#include <qof.h>
#include <libguile.h> #include <libguile.h>
KvpValue* gnc_scm_to_kvp_value_ptr(SCM kvpval); KvpValue* gnc_scm_to_kvp_value_ptr(SCM kvpval);
SCM gnc_kvp_value_ptr_to_scm(KvpValue* val); SCM gnc_kvp_value_ptr_to_scm(KvpValue* val);
void gnc_kvp_frame_delete_at_path(KvpFrame *frame, GSList *key_path);
#ifdef __cplusplus
}
#endif
#endif /* KVP_SCM_H */ #endif /* KVP_SCM_H */

View File

@ -6,7 +6,7 @@ API: \ref KVP
This file documents the use of keys in the key-value pair system This file documents the use of keys in the key-value pair system
used by the GnuCash Application (both the engine, and non-engine, GUI used by the GnuCash Application (both the engine, and non-engine, GUI
pieces). Before assigning keys for use, please read the Key-Value pieces). Before assigning keys for use, please read the Key-Value
Policy in the GnuCash Design Document located under src/doc/design. Policy in the GnuCash Design Document located under src/doc/design.
The format of the data below is: The format of the data below is:
@ -16,7 +16,7 @@ Name: The name of the key, including key names of parent frames
filename. Use the '/' character to separate keys. filename. Use the '/' character to separate keys.
Type: The type of value stored in the key. The types are listed in Type: The type of value stored in the key. The types are listed in
'kvp_frame.h'. 'kvp-value.hpp'.
Entities: Which engine entities (Accounts, Transactions, Splits) Entities: Which engine entities (Accounts, Transactions, Splits)
can use this key. Use 'All' if every entity could have can use this key. Use 'All' if every entity could have
@ -24,7 +24,7 @@ Entities: Which engine entities (Accounts, Transactions, Splits)
Use: The use to which the key will be put. Include any requirements Use: The use to which the key will be put. Include any requirements
for using the key here. Also include any API calls which use for using the key here. Also include any API calls which use
the key. If more than one entity can use the key, the key. If more than one entity can use the key,
Example: Example:
@ -44,7 +44,7 @@ Please put the keys in alphabetical order.
[ \ref kvpA ] [ \ref kvpB ] [ \ref kvpC ] [ \ref kvpD ] [ \ref kvpE ] [ \ref kvpA ] [ \ref kvpB ] [ \ref kvpC ] [ \ref kvpD ] [ \ref kvpE ]
[ \ref kvpF ] [ \ref kvpG ] [ \ref kvpH ] [ \ref kvpJ ] [ \ref kvpK ] [ \ref kvpL ]\n [ \ref kvpF ] [ \ref kvpG ] [ \ref kvpH ] [ \ref kvpJ ] [ \ref kvpK ] [ \ref kvpL ]\n
[ \ref kvpM ] [ \ref kvpN ] [ \ref kvpO ] [ \ref kvpP ] [ \ref kvpQ ] [ \ref kvpM ] [ \ref kvpN ] [ \ref kvpO ] [ \ref kvpP ] [ \ref kvpQ ]
[ \ref kvpR ] [ \ref kvpS ] [ \ref kvpT ] [ \ref kvpU ] [ \ref kvpV ] [ \ref kvpW ] [ \ref kvpR ] [ \ref kvpS ] [ \ref kvpT ] [ \ref kvpU ] [ \ref kvpV ] [ \ref kvpW ]
\subsection kvpA A \subsection kvpA A
@ -62,7 +62,7 @@ Use: kvp subdirectory holding info relating to accounting periods, including
\verbatim \verbatim
Name: /book/accounting-period Name: /book/accounting-period
Type: string, enum {none, week, month, quarter, trimester, year} Type: string, enum {none, week, month, quarter, trimester, year}
XXX not used, should be UIFreqSpec stuff .. XXX not used, should be UIFreqSpec stuff ..
Entities: Book Entities: Book
Use: An enumerated identifier indicating how often books are supposed Use: An enumerated identifier indicating how often books are supposed
@ -74,7 +74,7 @@ Use: An enumerated identifier indicating how often books are supposed
Name: /book/close-date Name: /book/close-date
Type: Timespec Type: Timespec
Entities: Book Entities: Book
Use: The posted closing date of this book. This book only contains Use: The posted closing date of this book. This book only contains
transactions whose posted date is earlier than this closing date. transactions whose posted date is earlier than this closing date.
\endverbatim \endverbatim
@ -82,7 +82,7 @@ Use: The posted closing date of this book. This book only contains
Name: /book/closed-acct Name: /book/closed-acct
Type: GUID Type: GUID
Entities: Transaction Entities: Transaction
Use: The GUID of the account for which this transaction represents the Use: The GUID of the account for which this transaction represents the
opening balance. This value will occur *only* in transactions that opening balance. This value will occur *only* in transactions that
are opening balances. are opening balances.
\endverbatim \endverbatim
@ -91,7 +91,7 @@ Use: The GUID of the account for which this transaction represents the
Name: /book/closed-book Name: /book/closed-book
Type: GUID Type: GUID
Entities: Transaction Entities: Transaction
Use: The GUID of the book for which this transaction represents the Use: The GUID of the book for which this transaction represents the
opening balance. This value will occur *only* in transactions that opening balance. This value will occur *only* in transactions that
are opening balances. are opening balances.
\endverbatim \endverbatim
@ -173,7 +173,7 @@ Entities: Book
Use: Holders for a bunch of counters for various types. Used specifically Use: Holders for a bunch of counters for various types. Used specifically
in the business objects for ID counters. The counter name is the path in the business objects for ID counters. The counter name is the path
that follows /counters/, e.g. "/counters/GncCustomer" that follows /counters/, e.g. "/counters/GncCustomer"
\endverbatim \endverbatim
\verbatim \verbatim
Name: /counter_formats/... Name: /counter_formats/...
@ -224,7 +224,7 @@ Use: GUID of the split that records the capital gains for this split.
Name: /gemini/ Name: /gemini/
Type: kvp_glist Type: kvp_glist
Entities: Account, Book Entities: Account, Book
Use: kvp bag holding frames that identify accounts or books Use: kvp bag holding frames that identify accounts or books
that are copies of this account. that are copies of this account.
\endverbatim \endverbatim
@ -247,7 +247,7 @@ Use: guid of another account that is a copy of this one.
Name: /gemini/<type>/book_guid Name: /gemini/<type>/book_guid
Type: guid Type: guid
Entities: Account, Book Entities: Account, Book
Use: When this appears in an account, then it contains the guid of Use: When this appears in an account, then it contains the guid of
the book that the other account belongs to. When this appears the book that the other account belongs to. When this appears
in a book, then this is the guid of the other book. in a book, then this is the guid of the other book.
\endverbatim \endverbatim
@ -304,7 +304,7 @@ Name: /hbci/config-filename
Type: string Type: string
Entitied: Book Entitied: Book
Use: OpenHBCI configuration file name, where the real HBCI Use: OpenHBCI configuration file name, where the real HBCI
configuration for the OpenHBCI library can be found configuration for the OpenHBCI library can be found
\endverbatim \endverbatim
\subsection kvpJ J \subsection kvpJ J
@ -328,15 +328,15 @@ Type: kvp_frame
Entities: Account Entities: Account
Use: Frame holding info regarding how lots should be managed in this Use: Frame holding info regarding how lots should be managed in this
account, including what accounting policy to use, where realized account, including what accounting policy to use, where realized
gains should be reported, and etc. gains should be reported, and etc.
\endverbatim \endverbatim
\verbatim \verbatim
Name: /lot-mgmt/gains-acct/ Name: /lot-mgmt/gains-acct/
Type: frame Type: frame
Entities: Account Entities: Account
Use: When a lot in this account is double-balanced, this frame Use: When a lot in this account is double-balanced, this frame
holds per-currency accounts to which realized gains are to holds per-currency accounts to which realized gains are to
be posted. be posted.
\endverbatim \endverbatim
@ -361,7 +361,7 @@ Name: /lot-split/
Type: kvp_glist Type: kvp_glist
Entities: Split Entities: Split
Use: A bag of kvp frames holding identification of splits Use: A bag of kvp frames holding identification of splits
that were split off of this split. Same style as the that were split off of this split. Same style as the
/gemini/, look there for additional doco's. /gemini/, look there for additional doco's.
\endverbatim \endverbatim
@ -380,7 +380,7 @@ Use: The GUID of the peer split which was split from this split.
Name: /notes Name: /notes
Type: string Type: string
Entities: Account, Lot, Transaction Entities: Account, Lot, Transaction
Use: A user-suplied 'Notes' text field. The user can set this to Use: A user-suplied 'Notes' text field. The user can set this to
any value and change it at any time for any reason. any value and change it at any time for any reason.
Accessors: xaccAccountGetNotes(), xaccAccountSetNotes(), Accessors: xaccAccountGetNotes(), xaccAccountSetNotes(),
xaccTransGetNotes(), xaccTransSetNotes() xaccTransGetNotes(), xaccTransSetNotes()
@ -533,7 +533,7 @@ Use: Store the formula for the credit side of the split
Name: /sched-xaction/debit-formula Name: /sched-xaction/debit-formula
Type: string Type: string
Entities: Split associated with a SchedXaction Entities: Split associated with a SchedXaction
Use: Formula for the debit. Either the credit or the Use: Formula for the debit. Either the credit or the
debit formula must be empty. debit formula must be empty.
\endverbatim \endverbatim
@ -571,7 +571,7 @@ Use: A boolean flag indicated whether the Account is tax-related.
Name: /title Name: /title
Type: string Type: string
Entities: Lot Entities: Lot
Use: A user-supplied title for the lot. The user can set this to Use: A user-supplied title for the lot. The user can set this to
any value and change it at any time for any reason. any value and change it at any time for any reason.
\endverbatim \endverbatim
@ -606,7 +606,7 @@ Use: This frame is used to store keys which are editable directly by
Name: void-reason Name: void-reason
Type: string Type: string
Entities: Transaction Entities: Transaction
Use: This string is used to store the reason why a transaction has been Use: This string is used to store the reason why a transaction has been
voided. Note that it should only exist if the transaction has been voided. voided. Note that it should only exist if the transaction has been voided.
\endverbatim \endverbatim

View File

@ -6,7 +6,7 @@ LDADD = \
${top_builddir}/src/libqof/qof/libgnc-qof.la \ ${top_builddir}/src/libqof/qof/libgnc-qof.la \
${GLIB_LIBS} ${GLIB_LIBS}
libgncmod_test_engine_la_SOURCES = gncmod-test-engine.c test-engine-stuff.c libgncmod_test_engine_la_SOURCES = gncmod-test-engine.c test-engine-stuff.cpp
libgncmod_test_engine_la_LDFLAGS = -module libgncmod_test_engine_la_LDFLAGS = -module
libgncmod_test_engine_la_LIBADD = \ libgncmod_test_engine_la_LIBADD = \
${top_builddir}/src/gnc-module/libgnc-module.la \ ${top_builddir}/src/gnc-module/libgnc-module.la \

View File

@ -15,6 +15,10 @@
* Created by Linux Developers Group, 2001 * Created by Linux Developers Group, 2001
* Updates Linas Vepstas July 2004 * Updates Linas Vepstas July 2004
*/ */
#include <kvp_frame.hpp>
extern "C"
{
#include "config.h" #include "config.h"
#include <sys/types.h> #include <sys/types.h>
@ -28,6 +32,7 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <qof.h>
#include <qofinstance-p.h> #include <qofinstance-p.h>
#include "Account.h" #include "Account.h"
@ -43,6 +48,7 @@
#include "test-engine-stuff.h" #include "test-engine-stuff.h"
#include "test-stuff.h" #include "test-stuff.h"
#include "test-engine-strings.h" #include "test-engine-strings.h"
}
static gboolean glist_strings_only = FALSE; static gboolean glist_strings_only = FALSE;
@ -99,8 +105,8 @@ set_max_kvp_frame_elements (gint max_kvp_frame_elements)
kvp_frame_max_elements = MAX (max_kvp_frame_elements, 1); kvp_frame_max_elements = MAX (max_kvp_frame_elements, 1);
} }
void static void
kvp_exclude_type (KvpValueType kvp_type) kvp_exclude_type (KvpValue::Type kvp_type)
{ {
gint *key; gint *key;
@ -114,7 +120,7 @@ kvp_exclude_type (KvpValueType kvp_type)
} }
static gboolean static gboolean
kvp_type_excluded (KvpValueType kvp_type) kvp_type_excluded (KvpValue::Type kvp_type)
{ {
gint key = kvp_type; gint key = kvp_type;
@ -127,12 +133,6 @@ kvp_type_excluded (KvpValueType kvp_type)
return FALSE; return FALSE;
} }
void
random_glist_strings_only (gboolean strings_only)
{
glist_strings_only = strings_only;
}
static gboolean zero_nsec = FALSE; static gboolean zero_nsec = FALSE;
void void
@ -188,14 +188,11 @@ get_random_glist_depth (gint depth)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
KvpValueType kvpt; KvpValue *value = nullptr;
KvpValue *value;
kvpt = glist_strings_only ? KVP_TYPE_STRING : -2;
do do
{ {
value = get_random_kvp_value_depth (kvpt, depth + 1); value = get_random_kvp_value_depth (-2, depth + 1);
} }
while (!value); while (!value);
@ -205,12 +202,6 @@ get_random_glist_depth (gint depth)
return ret; return ret;
} }
GList*
get_random_glist(void)
{
return get_random_glist_depth (0);
}
/* ========================================================== */ /* ========================================================== */
/* Time/Date, GncGUID data stuff */ /* Time/Date, GncGUID data stuff */
@ -247,23 +238,25 @@ static KvpFrame* get_random_kvp_frame_depth (gint depth);
static KvpValue* static KvpValue*
get_random_kvp_value_depth (int type, gint depth) get_random_kvp_value_depth (int type, gint depth)
{ {
int datype = type; KvpValue::Type datype;
KvpValue *ret; KvpValue *ret;
if (datype == -1) if (type == -1)
{ {
datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME); datype = static_cast<KvpValue::Type>(get_random_int_in_range(KvpValue::Type::INT64, KvpValue::Type::FRAME));
} }
if (datype == -2) else if (type == -2)
{ {
datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1); datype = static_cast<KvpValue::Type>(get_random_int_in_range(KvpValue::Type::INT64, KvpValue::Type::FRAME - 1));
} }
else
datype = static_cast<KvpValue::Type>(type);
if (datype == KVP_TYPE_FRAME && depth >= kvp_max_depth) if (datype == KvpValue::Type::FRAME && depth >= kvp_max_depth)
return NULL; return NULL;
if (datype == KVP_TYPE_GLIST && depth >= kvp_max_depth) if (datype == KvpValue::Type::GLIST && depth >= kvp_max_depth)
return NULL; return NULL;
if (kvp_type_excluded (datype)) if (kvp_type_excluded (datype))
@ -271,57 +264,50 @@ get_random_kvp_value_depth (int type, gint depth)
switch (datype) switch (datype)
{ {
case KVP_TYPE_GINT64: case KvpValue::Type::INT64:
ret = kvp_value_new_gint64(get_random_gint64()); ret = new KvpValue(get_random_gint64());
break; break;
case KVP_TYPE_DOUBLE: case KvpValue::Type::DOUBLE:
ret = NULL; ret = NULL;
break; break;
case KVP_TYPE_NUMERIC: case KvpValue::Type::NUMERIC:
ret = kvp_value_new_gnc_numeric(get_random_gnc_numeric(GNC_DENOM_AUTO)); ret = new KvpValue(get_random_gnc_numeric(GNC_DENOM_AUTO));
break; break;
case KVP_TYPE_STRING: case KvpValue::Type::STRING:
{ {
gchar *tmp_str; gchar *tmp_str;
tmp_str = get_random_string(); tmp_str = get_random_string();
if (!tmp_str) if (!tmp_str)
return NULL; return NULL;
ret = kvp_value_new_string(tmp_str); ret = new KvpValue(tmp_str);
g_free(tmp_str);
} }
break; break;
case KVP_TYPE_GUID: case KvpValue::Type::GUID:
{ {
GncGUID *tmp_guid; return new KvpValue(get_random_guid());
tmp_guid = get_random_guid();
ret = kvp_value_new_guid(tmp_guid);
g_free(tmp_guid);
} }
break; break;
case KVP_TYPE_TIMESPEC: case KvpValue::Type::TIMESPEC:
{ {
Timespec *ts = get_random_timespec(); Timespec *ts = get_random_timespec();
ret = kvp_value_new_timespec (*ts); ret = new KvpValue(*ts);
g_free(ts); g_free(ts);
} }
break; break;
case KVP_TYPE_GLIST: case KvpValue::Type::GLIST:
ret = kvp_value_new_glist_nc(get_random_glist_depth (depth + 1)); ret = new KvpValue(get_random_glist_depth (depth + 1));
break; break;
case KVP_TYPE_FRAME: case KvpValue::Type::FRAME:
{ {
KvpFrame *tmp_frame; return new KvpValue(get_random_kvp_frame_depth(depth + 1));
tmp_frame = get_random_kvp_frame_depth(depth + 1);
ret = kvp_value_new_frame(tmp_frame);
kvp_frame_delete(tmp_frame);
} }
break; break;
@ -335,14 +321,13 @@ get_random_kvp_value_depth (int type, gint depth)
static KvpFrame* static KvpFrame*
get_random_kvp_frame_depth (gint depth) get_random_kvp_frame_depth (gint depth)
{ {
KvpFrame *ret;
int vals_to_add; int vals_to_add;
gboolean val_added; gboolean val_added;
if (depth >= kvp_max_depth) if (depth >= kvp_max_depth)
return NULL; return NULL;
ret = kvp_frame_new(); auto ret = new KvpFrame;
vals_to_add = get_random_int_in_range(1, kvp_frame_max_elements); vals_to_add = get_random_int_in_range(1, kvp_frame_max_elements);
val_added = FALSE; val_added = FALSE;
@ -374,7 +359,7 @@ get_random_kvp_frame_depth (gint depth)
val_added = TRUE; val_added = TRUE;
kvp_frame_set_slot_nc(ret, key, val); ret->set_path(key, val);
g_free(key); g_free(key);
} }
@ -495,13 +480,13 @@ get_random_commodity_from_table (gnc_commodity_table *table)
GList *commodities; GList *commodities;
char *name_space; char *name_space;
name_space = get_random_list_element (namespaces); name_space = static_cast<char*>(get_random_list_element (namespaces));
commodities = gnc_commodity_table_get_commodities (table, name_space); commodities = gnc_commodity_table_get_commodities (table, name_space);
if (!commodities) if (!commodities)
continue; continue;
com = get_random_list_element (commodities); com = static_cast<gnc_commodity*>(get_random_list_element (commodities));
g_list_free (commodities); g_list_free (commodities);
@ -603,7 +588,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table)
for (node = namespaces; node; node = node->next) for (node = namespaces; node; node = node->next)
{ {
const char *ns = node->data; auto ns = static_cast<const char *>(node->data);
GList *commodities; GList *commodities;
GList *com_node; GList *com_node;
@ -614,7 +599,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table)
for (com_node = commodities; com_node; com_node = com_node->next) for (com_node = commodities; com_node; com_node = com_node->next)
{ {
gnc_commodity *com = com_node->data; auto com = static_cast<gnc_commodity *>(com_node->data);
gnc_commodity_table_remove (table, com); gnc_commodity_table_remove (table, com);
make_random_changes_to_commodity (com); make_random_changes_to_commodity (com);
@ -747,7 +732,7 @@ get_random_pricedb(QofBook *book)
static gboolean static gboolean
price_accumulator (GNCPrice *p, gpointer data) price_accumulator (GNCPrice *p, gpointer data)
{ {
GList **list = data; auto list = static_cast<GList**>(data);
*list = g_list_prepend (*list, p); *list = g_list_prepend (*list, p);
@ -766,7 +751,7 @@ make_random_changes_to_pricedb (QofBook *book, GNCPriceDB *pdb)
for (node = list; node; node = node->next) for (node = list; node; node = node->next)
{ {
GNCPrice *p = node->data; auto p = static_cast<GNCPrice *>(node->data);
switch (get_random_int_in_range (0, 5)) switch (get_random_int_in_range (0, 5))
{ {
@ -897,7 +882,6 @@ get_random_account_tree (QofBook *book)
static void static void
add_random_splits(QofBook *book, Transaction *trn, GList *account_list) add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
{ {
Account *acc, *bcc;
Split *s1, *s2; Split *s1, *s2;
gnc_numeric val; gnc_numeric val;
int s2_scu; int s2_scu;
@ -905,11 +889,11 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
/* Gotta have at least two different accounts */ /* Gotta have at least two different accounts */
if (1 >= g_list_length (account_list)) return; if (1 >= g_list_length (account_list)) return;
acc = get_random_list_element (account_list); auto acc = static_cast<Account*>(get_random_list_element (account_list));
xaccTransBeginEdit(trn); xaccTransBeginEdit(trn);
s1 = get_random_split(book, acc, trn); s1 = get_random_split(book, acc, trn);
bcc = get_random_list_element (account_list); auto bcc = static_cast<Account*>(get_random_list_element (account_list));
if ((bcc == acc) && (!do_bork())) if ((bcc == acc) && (!do_bork()))
{ {
/* Make sure that each side of the transaction is in /* Make sure that each side of the transaction is in
@ -918,7 +902,7 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
* this case? */ * this case? */
while (bcc == acc) while (bcc == acc)
{ {
bcc = get_random_list_element (account_list); bcc = static_cast<Account*>(get_random_list_element (account_list));
} }
} }
@ -993,10 +977,8 @@ make_random_changes_to_transaction_and_splits (QofBook *book,
splits = xaccTransGetSplitList (trans); splits = xaccTransGetSplitList (trans);
for (node = splits; node; node = node->next) for (node = splits; node; node = node->next)
{ {
Split *split = node->data; auto split = static_cast<Split *>(node->data);
Account *account; auto account = static_cast<Account*>(get_random_list_element (accounts));
account = get_random_list_element (accounts);
xaccAccountInsertSplit (account, split); xaccAccountInsertSplit (account, split);
} }
@ -1021,7 +1003,7 @@ make_random_changes_to_transaction_and_splits (QofBook *book,
splits = xaccTransGetSplitList (trans); splits = xaccTransGetSplitList (trans);
for (node = splits; node; node = node->next) for (node = splits; node; node = node->next)
{ {
Split *split = node->data; auto split = static_cast<Split *>(node->data);
if (get_random_boolean ()) if (get_random_boolean ())
make_random_changes_to_split (split); make_random_changes_to_split (split);
@ -1037,7 +1019,7 @@ static int
add_trans_helper (Transaction *trans, gpointer data) add_trans_helper (Transaction *trans, gpointer data)
{ {
TransInfo *ti; TransInfo *ti;
GList **list = data; auto list = static_cast<GList **>(data);
ti = g_new (TransInfo, 1); ti = g_new (TransInfo, 1);
@ -1068,7 +1050,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
gnc_account_append_child (parent, new_account); gnc_account_append_child (parent, new_account);
else else
{ {
account = get_random_list_element (accounts); account = static_cast<Account*>(get_random_list_element (accounts));
gnc_account_append_child (account, new_account); gnc_account_append_child (account, new_account);
} }
@ -1082,7 +1064,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
/* Mess with the accounts */ /* Mess with the accounts */
for (node = accounts; node; node = node->next) for (node = accounts; node; node = node->next)
{ {
Account *account = node->data; auto account = static_cast<Account *>(node->data);
if (get_random_boolean ()) if (get_random_boolean ())
make_random_changes_to_account (book, account); make_random_changes_to_account (book, account);
@ -1094,7 +1076,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
for (node = transes; node; node = node->next) for (node = transes; node; node = node->next)
{ {
TransInfo *ti = node->data; auto ti = static_cast<TransInfo *>(node->data);
Transaction *trans = xaccTransLookup (&ti->guid, book); Transaction *trans = xaccTransLookup (&ti->guid, book);
if (!trans) if (!trans)
@ -1105,7 +1087,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
for (node = transes; node; node = node->next) for (node = transes; node; node = node->next)
{ {
TransInfo *ti = node->data; auto ti = static_cast<TransInfo *>(node->data);
g_free (ti); g_free (ti);
} }
@ -1113,18 +1095,18 @@ make_random_changes_to_level (QofBook *book, Account *parent)
transes = NULL; transes = NULL;
/* delete an account */ /* delete an account */
account = get_random_list_element (accounts); account = static_cast<Account*>(get_random_list_element (accounts));
splits = xaccAccountGetSplitList (account); splits = xaccAccountGetSplitList (account);
splits = g_list_copy (splits); splits = g_list_copy (splits);
for (node = splits; node; node = node->next) for (node = splits; node; node = node->next)
{ {
Split *split = node->data; auto split = static_cast<Split *>(node->data);
do do
{ {
new_account = get_random_list_element (accounts); new_account = static_cast<Account*>(get_random_list_element (accounts));
} }
while (new_account == account); while (new_account == account);
@ -1146,12 +1128,12 @@ make_random_changes_to_level (QofBook *book, Account *parent)
while (i--) while (i--)
{ {
Account *a1, *a2; Account *a2;
a1 = get_random_list_element (accounts); auto a1 = static_cast<Account*>(get_random_list_element (accounts));
if (get_random_boolean ()) if (get_random_boolean ())
a2 = get_random_list_element (accounts); a2 = static_cast<Account*>(get_random_list_element (accounts));
else else
a2 = NULL; a2 = NULL;
@ -1190,7 +1172,7 @@ get_random_account(QofBook *book)
sane_account_names); sane_account_names);
tmp_int = get_random_int_in_range(ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1); tmp_int = get_random_int_in_range(ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1);
xaccAccountSetType(ret, tmp_int); xaccAccountSetType(ret, static_cast<GNCAccountType>(tmp_int));
set_account_random_string(ret, xaccAccountSetCode); set_account_random_string(ret, xaccAccountSetCode);
set_account_random_string(ret, xaccAccountSetDescription); set_account_random_string(ret, xaccAccountSetDescription);
@ -1223,7 +1205,7 @@ make_random_changes_to_account (QofBook *book, Account *account)
set_account_random_string (account, xaccAccountSetName); set_account_random_string (account, xaccAccountSetName);
tmp_int = get_random_int_in_range (ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1); tmp_int = get_random_int_in_range (ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1);
xaccAccountSetType (account, tmp_int); xaccAccountSetType (account, static_cast<GNCAccountType>(tmp_int));
set_account_random_string (account, xaccAccountSetCode); set_account_random_string (account, xaccAccountSetCode);
set_account_random_string (account, xaccAccountSetDescription); set_account_random_string (account, xaccAccountSetDescription);
@ -1386,7 +1368,7 @@ set_tran_random_string(Transaction* trn,
void(*func)(Transaction *act, const gchar*str)) void(*func)(Transaction *act, const gchar*str))
{ {
gchar *tmp_str = get_random_string(); gchar *tmp_str = get_random_string();
if (!trn || !(&trn->inst)) if (!trn)
{ {
return; return;
} }
@ -1464,7 +1446,7 @@ get_random_transaction_with_currency(QofBook *book,
trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS); trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS);
f = get_random_kvp_frame(); f = get_random_kvp_frame();
xaccTransSetSlots_nc(trans, f); qof_instance_set_slots (QOF_INSTANCE (trans), f);
add_random_splits(book, trans, account_list); add_random_splits(book, trans, account_list);
@ -1525,7 +1507,7 @@ make_random_changes_to_transaction (QofBook *book, Transaction *trans)
set_tran_random_string (trans, xaccTransSetDescription); set_tran_random_string (trans, xaccTransSetDescription);
xaccTransSetSlots_nc (trans, get_random_kvp_frame()); qof_instance_set_slots (QOF_INSTANCE (trans), get_random_kvp_frame());
/* Do split manipulations in higher-level functions */ /* Do split manipulations in higher-level functions */
@ -1659,7 +1641,7 @@ set_query_sort (QofQuery *q, sort_type_t sort_code)
{ {
GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard; GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard;
standard = g_slist_prepend (NULL, QUERY_DEFAULT_SORT); standard = g_slist_prepend (NULL, const_cast<char*>(QUERY_DEFAULT_SORT));
switch (sort_code) switch (sort_code)
{ {
@ -1667,36 +1649,36 @@ set_query_sort (QofQuery *q, sort_type_t sort_code)
p1 = standard; p1 = standard;
break; break;
case BY_DATE: case BY_DATE:
p1 = g_slist_prepend (p1, TRANS_DATE_POSTED); p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DATE_POSTED));
p1 = g_slist_prepend (p1, SPLIT_TRANS); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard; p2 = standard;
break; break;
case BY_DATE_ENTERED: case BY_DATE_ENTERED:
p1 = g_slist_prepend (p1, TRANS_DATE_ENTERED); p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DATE_ENTERED));
p1 = g_slist_prepend (p1, SPLIT_TRANS); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard; p2 = standard;
break; break;
case BY_DATE_RECONCILED: case BY_DATE_RECONCILED:
p1 = g_slist_prepend (p1, SPLIT_RECONCILE); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_RECONCILE));
p2 = g_slist_prepend (p2, SPLIT_DATE_RECONCILED); p2 = g_slist_prepend (p2, const_cast<char*>(SPLIT_DATE_RECONCILED));
p3 = standard; p3 = standard;
break; break;
case BY_NUM: case BY_NUM:
p1 = g_slist_prepend (p1, TRANS_NUM); p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_NUM));
p1 = g_slist_prepend (p1, SPLIT_TRANS); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard; p2 = standard;
break; break;
case BY_AMOUNT: case BY_AMOUNT:
p1 = g_slist_prepend (p1, SPLIT_VALUE); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_VALUE));
p2 = standard; p2 = standard;
break; break;
case BY_MEMO: case BY_MEMO:
p1 = g_slist_prepend (p1, SPLIT_MEMO); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_MEMO));
p2 = standard; p2 = standard;
break; break;
case BY_DESC: case BY_DESC:
p1 = g_slist_prepend (p1, TRANS_DESCRIPTION); p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DESCRIPTION));
p1 = g_slist_prepend (p1, SPLIT_TRANS); p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard; p2 = standard;
break; break;
case BY_NONE: case BY_NONE:
@ -1711,6 +1693,13 @@ set_query_sort (QofQuery *q, sort_type_t sort_code)
qof_query_set_sort_order (q, p1, p2, p3); qof_query_set_sort_order (q, p1, p2, p3);
} }
template <typename T> inline T
compare_param(int max)
{
auto ret = get_random_int_in_range (max == 1 ? 0 : 1, max);
return static_cast<T>(ret);
}
QofQuery * QofQuery *
get_random_query(void) get_random_query(void)
{ {
@ -1743,7 +1732,7 @@ get_random_query(void)
xaccQueryAddAccountGUIDMatch xaccQueryAddAccountGUIDMatch
(q, (q,
guids, guids,
get_random_int_in_range (1, QOF_GUID_MATCH_NONE), compare_param<QofGuidMatch>(QOF_GUID_MATCH_NONE),
get_random_queryop ()); get_random_queryop ());
free_random_guids (guids); free_random_guids (guids);
break; break;
@ -1754,7 +1743,7 @@ get_random_query(void)
string, string,
get_random_boolean (), get_random_boolean (),
get_random_boolean (), get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS), compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ()); get_random_queryop ());
g_free (string); g_free (string);
break; break;
@ -1762,19 +1751,19 @@ get_random_query(void)
case 3: /* PR_BALANCE */ case 3: /* PR_BALANCE */
xaccQueryAddBalanceMatch xaccQueryAddBalanceMatch
(q, (q,
get_random_boolean (), compare_param<QofQueryCompare> (1),
get_random_queryop ()); get_random_queryop ());
break; break;
case 4: /* PR_CLEARED */ case 4: /* PR_CLEARED */
xaccQueryAddClearedMatch xaccQueryAddClearedMatch
(q, (q,
get_random_int_in_range (1, static_cast<cleared_match_t>(get_random_int_in_range (1,
CLEARED_NO | CLEARED_NO |
CLEARED_CLEARED | CLEARED_CLEARED |
CLEARED_RECONCILED | CLEARED_RECONCILED |
CLEARED_FROZEN | CLEARED_FROZEN |
CLEARED_VOIDED), CLEARED_VOIDED)),
get_random_queryop ()); get_random_queryop ());
break; break;
@ -1797,7 +1786,7 @@ get_random_query(void)
string, string,
get_random_boolean (), get_random_boolean (),
get_random_boolean (), get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS), compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ()); get_random_queryop ());
g_free (string); g_free (string);
break; break;
@ -1812,20 +1801,6 @@ get_random_query(void)
break; break;
case 8: /* PR_KVP */ case 8: /* PR_KVP */
path = get_random_kvp_path ();
do
{
value = get_random_kvp_value_depth (-2, kvp_max_depth);
}
while (!value);
xaccQueryAddKVPMatch (q,
path,
value,
get_random_int_in_range (1, QOF_COMPARE_NEQ),
get_random_id_type (),
get_random_queryop ());
kvp_value_delete (value);
free_random_kvp_path (path);
break; break;
case 9: /* PR_MEMO */ case 9: /* PR_MEMO */
@ -1834,7 +1809,7 @@ get_random_query(void)
string, string,
get_random_boolean (), get_random_boolean (),
get_random_boolean (), get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS), compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ()); get_random_queryop ());
g_free (string); g_free (string);
break; break;
@ -1845,7 +1820,7 @@ get_random_query(void)
string, string,
get_random_boolean (), get_random_boolean (),
get_random_boolean (), get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS), compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ()); get_random_queryop ());
g_free (string); g_free (string);
break; break;
@ -1854,7 +1829,7 @@ get_random_query(void)
xaccQueryAddSharePriceMatch xaccQueryAddSharePriceMatch
(q, (q,
get_random_gnc_numeric (GNC_DENOM_AUTO), get_random_gnc_numeric (GNC_DENOM_AUTO),
get_random_int_in_range (1, QOF_COMPARE_NEQ), compare_param<QofQueryCompare> (QOF_COMPARE_NEQ),
get_random_queryop ()); get_random_queryop ());
break; break;
@ -1862,7 +1837,7 @@ get_random_query(void)
xaccQueryAddSharesMatch xaccQueryAddSharesMatch
(q, (q,
get_random_gnc_numeric (GNC_DENOM_AUTO), get_random_gnc_numeric (GNC_DENOM_AUTO),
get_random_int_in_range (1, QOF_COMPARE_NEQ), compare_param<QofQueryCompare> (QOF_COMPARE_NEQ),
get_random_queryop ()); get_random_queryop ());
break; break;
@ -1870,8 +1845,8 @@ get_random_query(void)
xaccQueryAddValueMatch xaccQueryAddValueMatch
(q, (q,
get_random_gnc_numeric (GNC_DENOM_AUTO), get_random_gnc_numeric (GNC_DENOM_AUTO),
get_random_int_in_range (1, QOF_NUMERIC_MATCH_ANY), compare_param<QofNumericMatch> (QOF_NUMERIC_MATCH_ANY),
get_random_int_in_range (1, QOF_COMPARE_NEQ), compare_param<QofQueryCompare> (QOF_COMPARE_NEQ),
get_random_queryop ()); get_random_queryop ());
break; break;
@ -1883,7 +1858,7 @@ get_random_query(void)
} }
if (gnc_engine_debug_random) printf ("\n"); if (gnc_engine_debug_random) printf ("\n");
set_query_sort (q, get_random_int_in_range (1, BY_NONE)); set_query_sort (q, compare_param<sort_type_t>(BY_NONE));
qof_query_set_sort_increasing (q, qof_query_set_sort_increasing (q,
get_random_boolean (), get_random_boolean (),
@ -1977,39 +1952,6 @@ typedef struct
QofQuery *q; QofQuery *q;
} KVPQueryData; } KVPQueryData;
static void
add_kvp_value_query (const char *key, KvpValue *value, gpointer data)
{
KVPQueryData *kqd = data;
GSList *node;
kqd->path = g_slist_append (kqd->path, (gpointer) key);
if (kvp_value_get_type (value) == KVP_TYPE_FRAME)
kvp_frame_for_each_slot (kvp_value_get_frame (value),
add_kvp_value_query, data);
else
xaccQueryAddKVPMatch (kqd->q, kqd->path, value,
QOF_COMPARE_EQUAL, kqd->where,
QOF_QUERY_AND);
node = g_slist_last (kqd->path);
kqd->path = g_slist_remove_link (kqd->path, node);
g_slist_free_1 (node);
}
static void
add_kvp_query (QofQuery *q, KvpFrame *frame, QofIdType where)
{
KVPQueryData kqd;
kqd.where = where;
kqd.path = NULL;
kqd.q = q;
kvp_frame_for_each_slot (frame, add_kvp_value_query, &kqd);
}
static gboolean include_price = TRUE; static gboolean include_price = TRUE;
void void
@ -2021,17 +1963,11 @@ trans_query_include_price (gboolean include_price_in)
TestQueryTypes TestQueryTypes
get_random_query_type (void) get_random_query_type (void)
{ {
switch (get_random_int_in_range (0, 4)) switch (get_random_int_in_range (0, 1))
{ {
case 0: case 0:
return SIMPLE_QT; return SIMPLE_QT;
case 1: case 1:
return SPLIT_KVP_QT;
case 2:
return TRANS_KVP_QT;
case 3:
return ACCOUNT_KVP_QT;
case 4:
return GUID_QT; return GUID_QT;
default: default:
return SIMPLE_QT; return SIMPLE_QT;
@ -2140,7 +2076,7 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
list = NULL; list = NULL;
for (node = xaccTransGetSplitList (trans); node; node = node->next) for (node = xaccTransGetSplitList (trans); node; node = node->next)
{ {
Split * split = node->data; auto split = static_cast<Split * >(node->data);
list = g_list_prepend (list, xaccSplitGetAccount (split)); list = g_list_prepend (list, xaccSplitGetAccount (split));
} }
xaccQueryAddAccountMatch (q, list, QOF_GUID_MATCH_ALL, QOF_QUERY_AND); xaccQueryAddAccountMatch (q, list, QOF_GUID_MATCH_ALL, QOF_QUERY_AND);
@ -2178,15 +2114,6 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
GNC_ID_ACCOUNT, QOF_QUERY_AND); GNC_ID_ACCOUNT, QOF_QUERY_AND);
} }
if (query_types & SPLIT_KVP_QT)
add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (s)), GNC_ID_SPLIT);
if (query_types & TRANS_KVP_QT)
add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (trans)), GNC_ID_TRANS);
if (query_types & ACCOUNT_KVP_QT)
add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (a)), GNC_ID_ACCOUNT);
return q; return q;
} }

View File

@ -4,7 +4,10 @@
#ifndef TEST_ENGINE_STUFF_H #ifndef TEST_ENGINE_STUFF_H
#define TEST_ENGINE_STUFF_H #define TEST_ENGINE_STUFF_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h> #include <glib.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -14,6 +17,8 @@
#include "gnc-pricedb.h" #include "gnc-pricedb.h"
#include "SchedXaction.h" #include "SchedXaction.h"
typedef struct KvpValueImpl KvpValue;
typedef struct KvpFrameImpl KvpFrame;
Timespec* get_random_timespec(void); Timespec* get_random_timespec(void);
void random_timespec_zero_nsec (gboolean zero_nsec); void random_timespec_zero_nsec (gboolean zero_nsec);
void random_timespec_usec_resolution (gboolean usec_resolution); void random_timespec_usec_resolution (gboolean usec_resolution);
@ -31,10 +36,8 @@ bin_data* get_random_binary_data(void);
KvpFrame* get_random_kvp_frame(void); KvpFrame* get_random_kvp_frame(void);
gnc_numeric get_random_gnc_numeric(int64_t); gnc_numeric get_random_gnc_numeric(int64_t);
GncGUID* get_random_guid(void); GncGUID* get_random_guid(void);
GList* get_random_glist(void);
void random_glist_strings_only (gboolean strings_only); //void kvp_exclude_type (KvpValueType kvp_type);
void kvp_exclude_type (KvpValueType kvp_type);
void set_max_kvp_depth (gint max_kvp_depth); void set_max_kvp_depth (gint max_kvp_depth);
void set_max_kvp_frame_elements (gint max_kvp_frame_elements); void set_max_kvp_frame_elements (gint max_kvp_frame_elements);
void set_max_account_tree_depth (gint max_tree_depth); void set_max_account_tree_depth (gint max_tree_depth);
@ -94,4 +97,7 @@ SchedXaction* add_daily_sx(gchar *name, const GDate *start, const GDate *end, co
SchedXaction* add_once_sx(gchar *name, const GDate *when); SchedXaction* add_once_sx(gchar *name, const GDate *when);
void remove_sx(SchedXaction *sx); void remove_sx(SchedXaction *sx);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -23,6 +23,8 @@ LDADD = \
${top_builddir}/src/core-utils/libgnc-core-utils.la \ ${top_builddir}/src/core-utils/libgnc-core-utils.la \
${GLIB_LIBS} ${GLIB_LIBS}
test_guid_SOURCES = test-guid.cpp
# these tests are ordered kind more or less in the order # these tests are ordered kind more or less in the order
# that they should be executed, with more basic tests coming first. # that they should be executed, with more basic tests coming first.
# #
@ -73,6 +75,7 @@ TESTS_ENVIRONMENT = \
$(shell ${abs_top_srcdir}/src/gnc-test-env.pl --noexports ${GNC_TEST_DEPS}) $(shell ${abs_top_srcdir}/src/gnc-test-env.pl --noexports ${GNC_TEST_DEPS})
check_PROGRAMS = ${TEST_GROUP_1} ${TEST_GROUP_2} check_PROGRAMS = ${TEST_GROUP_1} ${TEST_GROUP_2}
AM_DEFAULT_SOURCE_EXT = .cpp
TESTS = ${TEST_GROUP_1} test-create-account ${TEST_GROUP_2} TESTS = ${TEST_GROUP_1} test-create-account ${TEST_GROUP_2}
@ -94,7 +97,7 @@ EXTRA_DIST += \
test_engine_SOURCES = \ test_engine_SOURCES = \
test-engine.c \ test-engine.c \
utest-Account.c \ utest-Account.cpp \
utest-Budget.c \ utest-Budget.c \
utest-Entry.c \ utest-Entry.c \
utest-Invoice.c \ utest-Invoice.c \
@ -124,10 +127,36 @@ libutest_Split_la_CXXFLAGS = -Wno-write-strings $(AM_CXXFLAGS)
libutest_Split_la_LIBADD = $(LDADD) libutest_Split_la_LIBADD = $(LDADD)
libutest_Trans_la_SOURCES = \ libutest_Trans_la_SOURCES = \
utest-Transaction.c utest-Transaction.cpp
libutest_Trans_la_LIBADD = $(LDADD) libutest_Trans_la_LIBADD = $(LDADD)
if WITH_GOOGLE_TEST
test_import_map_SOURCES = \
gtest-import-map.cpp
test_import_map_LDADD = \
${top_builddir}/src/libqof/qof/libgnc-qof.la \
${top_builddir}/src/engine/libgncmod-engine.la \
${GLIB_LIBS} \
${GTEST_LIBS}
if !GOOGLE_TEST_LIBS
nodist_test_import_map_SOURCES = \
${GTEST_SRC}/src/gtest_main.cc
test_import_map_LDADD += ${top_builddir}/src/test-core/libgtest.a
endif
test_import_map_CPPFLAGS = \
-I${GTEST_HEADERS} \
-I${top_srcdir}/${MODULEPATH} \
-I${top_srcdir}/src/libqof/qof \
-I${top_srcdir}/src/core-utils \
${GLIB_CFLAGS}
TEST_GROUP_1 += test-import-map
endif
clean-local: clean-local:
rm -f translog.* rm -f translog.*

Some files were not shown because too many files have changed in this diff Show More