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-recurrence-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-transaction-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/io-example-account.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-utils.c
src/backend/xml/sixtp.c
src/backend/xml/sixtp-dom-generators.c
src/backend/xml/sixtp-dom-parsers.c
src/backend/xml/sixtp-dom-generators.cpp
src/backend/xml/sixtp-dom-parsers.cpp
src/backend/xml/sixtp-stack.c
src/backend/xml/sixtp-to-dom-parser.c
src/backend/xml/sixtp-utils.c
@ -184,7 +184,7 @@ src/engine/gnc-pricedb.c
src/engine/gnc-session.c
src/engine/gncTaxTable.c
src/engine/gncVendor.c
src/engine/kvp-scm.c
src/engine/kvp-scm.cpp
src/engine/policy.c
src/engine/Query.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-kvp.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-file-aqb-import.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-to-gnc.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-int128.cpp
src/libqof/qof/gnc-numeric.cpp
src/libqof/qof/gnc-rational.cpp
src/libqof/qof/guid.cpp
src/libqof/qof/kvp_frame.cpp
src/libqof/qof/kvp-util.cpp
src/libqof/qof/kvp-value.cpp
src/libqof/qof/qofbackend.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_end(void);
SCM gnc_make_kvp_options(QofIdType id_type);
void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
%typemap(in) GList * {

View File

@ -146,6 +146,11 @@
(export gnc:send-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
(export gnc:make-config-var)
(export gnc:config-var-description-get)
@ -318,9 +323,7 @@
(define (gnc:company-info key)
;; Access company info from key-value pairs for current book
(kvp-frame-get-slot-path-gslist
(qof-book-get-slots (gnc-get-current-book))
(append gnc:*kvp-option-path* (list gnc:*business-label* key))))
(gnc:option-get-value gnc:*business-label* key))
(export gnc:*business-label* gnc:*company-name* gnc:*company-addy*
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;
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)
{

View File

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

View File

@ -101,7 +101,6 @@ static GDate *
get_fy_end(void)
{
QofBook *book;
KvpFrame *book_frame;
GDate *date = NULL;
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_year(&creation_data->instance->date));
/* the accounts and amounts are in the kvp_frames of the splits. */
template_splits = xaccTransGetSplitList(template_txn);
txn_splits = xaccTransGetSplitList(new_txn);
if ((template_splits == NULL) || (txn_splits == NULL))
@ -1555,9 +1554,6 @@ create_cashflow_helper(Transaction *template_txn, void *user_data)
xaccTransGetDescription(template_txn),
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);
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 */
/* 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 *
gnc_option_db_new_for_type(QofIdType id_type)
{
@ -280,13 +313,12 @@ gnc_option_db_new_for_type(QofIdType id_type)
}
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_option_path = SCM_UNDEFINED;
SCM scm_slots;
SCM scm_book;
if (!odb || !slots) return;
if (!odb || !book) return;
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)
{
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_book = SWIG_NewPointerObj(book, SWIG_TypeQuery("_p_QofBook"), 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
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 kvp_option_path = SCM_UNDEFINED;
SCM scm_slots;
SCM scm_clear_kvp;
SCM scm_book;
SCM scm_clear_all;
if (!odb || !slots) return;
if (!odb || !book) return;
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)
{
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_book = SWIG_NewPointerObj(book, SWIG_TypeQuery("_p_QofBook"), 0);
scm_clear_all = scm_from_bool (clear_all);
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 *
@ -2928,17 +2941,6 @@ SCM gnc_dateformat_option_set_value(QofDateFormat format, GNCDateMonthFormat mon
return value;
}
/* For now, this is global, just like when it was in guile.
But, it should be make per-book. */
static GHashTable *kvp_registry = NULL;
static void
init_table(void)
{
if (!kvp_registry)
kvp_registry = g_hash_table_new(g_str_hash, g_str_equal);
}
/*
* the generator should be a procedure that takes one argument,
* an options object. The procedure should fill in the options with
@ -2954,25 +2956,3 @@ gnc_register_kvp_option_generator(QofIdType id_type, SCM generator)
g_hash_table_insert(kvp_registry, (gpointer) id_type, list);
scm_gc_protect_object(generator);
}
/* create a new options object for the requested type */
SCM
gnc_make_kvp_options(QofIdType id_type)
{
GList *list, *p;
SCM gnc_new_options = SCM_UNDEFINED;
SCM options = SCM_UNDEFINED;
init_table();
list = g_hash_table_lookup(kvp_registry, id_type);
gnc_new_options = scm_c_eval_string("gnc:new-options");
options = scm_call_0(gnc_new_options);
for (p = list; p; p = p->next)
{
SCM generator = p->data;
scm_call_1(generator, options);
}
return options;
}

View File

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

View File

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

View File

@ -8,6 +8,8 @@ check_PROGRAMS = \
test-sx \
test-app-utils
AM_DEFAULT_SOURCE_EXT = .cpp
TESTS = \
test-load-module \
${check_PROGRAMS}
@ -16,7 +18,7 @@ test_exp_parser_SOURCES = \
test-exp-parser.c
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-module-dir ${top_builddir}/src/app-utils \
@ -67,11 +69,10 @@ AM_CPPFLAGS = \
test_app_utils_SOURCES = \
test-app-utils.c \
test-option-util.c \
test-option-util.cpp \
test-gnc-ui-util.c
test_app_utils_CFLAGS = \
test_app_utils_CXXFLAGS = \
${DEFAULT_INCLUDES} \
-I${top_srcdir}/${MODULEPATH}/ \
-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> *
* *
* 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 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
********************************************************************/
#include <kvp_frame.hpp>
#include <gmp.h>
extern "C"
{
#include <config.h>
#include <glib.h>
#include <unittest-support.h>
#include <qofbookslots.h>
#include "../option-util.h"
}
static const gchar *suitename = "/app-utils/option-util";
void test_suite_option_util (void);
extern "C" void test_suite_option_util (void);
typedef struct
{
@ -41,7 +44,7 @@ typedef struct
/* Expose a mostly-private QofInstance function to load options into
* the Book.
*/
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
extern "C" KvpFrame *qof_instance_get_slots (const QofInstance*);
static void
setup (Fixture *fixture, gconstpointer pData)
@ -65,8 +68,8 @@ setup_kvp (Fixture *fixture, gconstpointer pData)
"autoreadonly-days", (double)21,
NULL);
kvp_frame_set_string (slots, "options/Business/Company Name",
"Bogus Company");
slots->set_path("options/Business/Company Name",
new KvpValue("Bogus Company"));
qof_commit_edit (QOF_INSTANCE (book));
}
@ -93,14 +96,14 @@ teardown (Fixture *fixture, gconstpointer pData)
}
static void
test_option_load_from_kvp (Fixture *fixture, gconstpointer pData)
test_option_load (Fixture *fixture, gconstpointer pData)
{
gchar *str = NULL;
SCM symbol_value;
QofBook *book = fixture->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 (
gnc_option_db_lookup_option (odb,
OPTION_SECTION_ACCOUNTS,
@ -127,7 +130,7 @@ test_option_load_from_kvp (Fixture *fixture, gconstpointer pData)
}
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;
SCM symbol_value;
@ -137,7 +140,7 @@ test_option_load_from_kvp_book_currency (Fixture *fixture, gconstpointer pData)
QofBook *book = fixture->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 (
gnc_option_db_lookup_option (odb,
OPTION_SECTION_ACCOUNTS,
@ -186,7 +189,7 @@ test_option_load_from_kvp_book_currency (Fixture *fixture, gconstpointer pData)
}
static void
test_option_save_to_kvp (Fixture *fixture, gconstpointer pData)
test_option_save (Fixture *fixture, gconstpointer pData)
{
QofBook *book = fixture->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,
OPTION_NAME_AUTO_READONLY_DAYS,
17));
qof_book_save_options (book, gnc_option_db_save_to_kvp, odb, TRUE);
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Trading Accounts"), == , "t");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Split Action Field for Number"), == , "t");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Business/Company Name"), ==, "Bogus Company");
g_assert_cmpfloat (kvp_frame_get_double (slots, "options/Accounts/Day Threshold for Read-Only Transactions (red line)"), ==, 17);
qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (slots->get_slot("options/Accounts/Use Trading Accounts")->get<const char*>(), == , "t");
g_assert_cmpstr (slots->get_slot("options/Accounts/Use Split Action Field for Number")->get<const char*>(), == , "t");
g_assert_cmpstr (slots->get_slot("options/Business/Company Name")->get<const char*>(), ==, "Bogus Company");
g_assert_cmpfloat (slots->get_slot("options/Accounts/Day Threshold for Read-Only Transactions (red line)")->get<double>(), ==, 17);
gnc_option_db_destroy (odb);
}
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;
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_utf8_string("GTQ"),
scm_cons (scm_from_locale_symbol("fifo"), SCM_EOL)))));
qof_book_save_options (book, gnc_option_db_save_to_kvp, odb, TRUE);
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Book Currency"), == , "GTQ");
g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Default Gains Policy"), == , "fifo");
qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (slots->get_slot("options/Accounts/Book Currency")->get<const char*>(), == , "GTQ");
g_assert_cmpstr (slots->get_slot("options/Accounts/Default Gains Policy")->get<const char*>(), == , "fifo");
gnc_option_db_destroy (odb);
}
void
extern "C" 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 from KVP - Book Currency", Fixture, NULL, setup_kvp_book_currency, test_option_load_from_kvp_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 to KVP - Book Currency", Fixture, NULL, setup, test_option_save_to_kvp_book_currency, teardown);
GNC_TEST_ADD (suitename, "Option DB Load", Fixture, NULL, setup_kvp, test_option_load, 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", Fixture, NULL, setup, test_option_save, 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 <glib.h>
#include <stdlib.h>
@ -8,6 +10,7 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"
#include <unittest-support.h>
}
static void
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;
gboolean ok, print_ok;
gchar *msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW.";
gchar *log_domain = "gnc.gui";
guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
TestErrorStruct check = { loglevel, log_domain, msg };
auto msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW.";
auto log_domain = "gnc.gui";
auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING);
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. */
hdlr = g_log_set_handler (log_domain, loglevel,
auto hdlr = g_log_set_handler (log_domain, loglevel,
(GLogFunc)test_checked_handler, &check);
s = xaccPrintAmount (n, print_info);
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)",
gnc_numeric_to_string (n), s,
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 ();
/* double->string->double is not idempotent */
kvp_exclude_type (KVP_TYPE_DOUBLE);
/* Initialize to a known RNG position */
srand(1);

View File

@ -1763,8 +1763,6 @@ init_sql_backend( GncDbiBackend* dbi_be )
* configured for multiuser access. */
be->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->run_query = gnc_sql_run_query;

View File

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

View File

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

View File

@ -22,21 +22,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "config.h"
#include "qof.h"
#include "qofsession-p.h"
#include "cashobjects.h"
#include "test-dbi-stuff.h"
extern "C"
{
#include <config.h>
#include <qof.h>
#include <qofsession-p.h>
#include <cashobjects.h>
#include <test-dbi-stuff.h>
#include <unittest-support.h>
#include "Account.h"
#include "Split.h"
#include "Transaction.h"
#include "gnc-commodity.h"
#include <Account.h>
#include <Split.h>
#include <Transaction.h>
#include <gnc-commodity.h>
#include <SX-book.h>
#include <gnc-lot.h>
#include "../gnc-backend-dbi-priv.h"
}
#include <kvp_frame.hpp>
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;
sx_guid = qof_instance_get_guid (QOF_INSTANCE(sxitem->data));
if (guid_equal (sx_guid, guid))
return sxitem->data;
return static_cast<SchedXaction*>(sxitem->data);
}
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;
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);
g_assert_cmpint (r1->ptype, ==, r2->ptype);
@ -184,7 +189,7 @@ compare_single_lot( QofInstance* inst, gpointer user_data )
gnc_lot_get_account (lot_2), FALSE ));
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);
splits1 = gnc_lot_get_split_list (lot_1);
splits2 = gnc_lot_get_split_list (lot_2);
@ -196,7 +201,8 @@ compare_single_lot( QofInstance* inst, gpointer user_data )
split2 = xaccSplitLookup (qof_instance_get_guid (split1->data),
info->book_2);
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) )
{
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));
}

View File

@ -25,7 +25,10 @@
#ifndef _TEST_DBI_STUFF_H_
#define _TEST_DBI_STUFF_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include "qof.h"
typedef struct
@ -37,5 +40,7 @@ typedef struct
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 );
#ifdef __cplusplus
}
#endif
#endif

View File

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

View File

@ -38,7 +38,7 @@ libgnc_backend_sql_la_SOURCES = \
gnc-price-sql.c \
gnc-recurrence-sql.c \
gnc-schedxaction-sql.c \
gnc-slots-sql.c \
gnc-slots-sql.cpp \
gnc-tax-table-sql.c \
gnc-transaction-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 );
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
{

View File

@ -34,17 +34,17 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include "qof.h"
#include "qofquery-p.h"
#include "qofquerycore-p.h"
#include "Account.h"
#include "TransLog.h"
#include "gnc-engine.h"
#include "SX-book.h"
#include "Recurrence.h"
#include "gncBillTerm.h"
#include "gncTaxTable.h"
#include "gncInvoice.h"
#include <qof.h>
#include <qofquery-p.h>
#include <qofquerycore-p.h>
#include <Account.h>
#include <TransLog.h>
#include <gnc-engine.h>
#include <SX-book.h>
#include <Recurrence.h>
#include <gncBillTerm.h>
#include <gncTaxTable.h>
#include <gncInvoice.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 );
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
{

View File

@ -430,7 +430,7 @@ save_budget( GncSqlBackend* be, QofInstance* inst )
}
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

View File

@ -213,7 +213,7 @@ do_commit_commodity( GncSqlBackend* be, QofInstance* inst, gboolean force_insert
guid = qof_instance_get_guid( 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
{

View File

@ -198,7 +198,7 @@ save_employee( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( 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
{

View File

@ -221,7 +221,7 @@ save_invoice( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( 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
{

View File

@ -206,7 +206,7 @@ gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
// Now, commit any slots
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
{

View File

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

View File

@ -28,10 +28,13 @@
#ifndef GNC_SLOTS_SQL_H
#define GNC_SLOTS_SQL_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h>
#include "guid.h"
#include "kvp_frame.h"
#include "qof.h"
#include "gnc-backend-sql.h"
@ -41,11 +44,11 @@
* @param be SQL backend
* @param guid Object guid
* @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
*/
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.
@ -88,4 +91,7 @@ void gnc_sql_slots_load_for_sql_subquery( GncSqlBackend* be, const gchar* subque
void gnc_sql_init_slots_handler( void );
#ifdef __cplusplus
}
#endif
#endif /* GNC_SLOTS_SQL_H */

View File

@ -454,7 +454,7 @@ save_taxtable( GncSqlBackend* be, QofInstance* inst )
guid = qof_instance_get_guid( 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 )
{
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))
{
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);
}
return is_ok;
@ -724,7 +721,7 @@ save_transaction( GncSqlBackend* be, Transaction* pTx, gboolean do_save_splits )
guid = qof_instance_get_guid( 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 )
{
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 );
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
{

View File

@ -583,7 +583,7 @@ test_gnc_sql_convert_timespec_to_string ()
GncSqlBackend be = {{
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,
"%4d-%02d-%02d %02d:%02d:%02d"

View File

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

View File

@ -42,11 +42,11 @@ libgnc_backend_xml_utils_la_SOURCES = \
gnc-xml-helper.c \
io-example-account.c \
io-gncxml-gen.c \
io-gncxml-v1.c \
io-gncxml-v1.cpp \
io-gncxml-v2.c \
io-utils.c \
sixtp-dom-generators.c \
sixtp-dom-parsers.c \
sixtp-dom-generators.cpp \
sixtp-dom-parsers.cpp \
sixtp-stack.c \
sixtp-to-dom-parser.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_placeholder_string "act:placeholder"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
xmlNodePtr
gnc_account_dom_tree_create(Account *act,
gboolean exporting,
gboolean allow_incompat)
{
const char *str;
KvpFrame *kf;
xmlNodePtr ret;
GList *lots, *n;
Account *parent;
@ -137,16 +133,9 @@ gnc_account_dom_tree_create(Account *act,
xmlAddChild(ret, text_to_dom_tree(act_description_string, str));
}
kf = qof_instance_get_slots (QOF_INSTANCE (act));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(act_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(act_slots_string,
QOF_INSTANCE(act)));
parent = gnc_account_get_parent(act);
if (parent)
{
@ -371,9 +360,7 @@ static gboolean
account_slots_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->account)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->account));
}
static gboolean

View File

@ -58,9 +58,6 @@ const gchar *address_version_string = "2.0.0";
#define addr_email_string "addr:email"
#define addr_slots_string "addr:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void
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)
{
xmlNodePtr ret;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST tag);
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_email_string, gncAddressGetEmail (addr));
kf = qof_instance_get_slots (QOF_INSTANCE(addr));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(addr_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(addr_slots_string,
QOF_INSTANCE(addr)));
return ret;
}
@ -190,9 +179,7 @@ static gboolean
address_slots_handler (xmlNodePtr node, gpointer addr_pdata)
{
struct address_pdata *pdata = addr_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->address)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->address));
}
static struct dom_tree_handler address_handlers_v2[] =

View File

@ -1251,8 +1251,6 @@ gnc_backend_new(void)
be->process_events = NULL;
be->sync = xml_sync_all;
be->load_config = NULL;
be->get_config = NULL;
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
billterm_dom_tree_create (GncBillTerm *term)
{
xmlNodePtr ret, data, kvpnode;
xmlNodePtr ret, data;
ret = xmlNewNode(NULL, BAD_CAST gnc_billterm_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,
gncBillTermGetInvisible (term)));
kvpnode = kvp_frame_to_dom_tree (billterm_slots_string,
qof_instance_get_slots (QOF_INSTANCE(term)));
if (kvpnode) xmlAddChild (ret, kvpnode);
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(billterm_slots_string,
QOF_INSTANCE(term)));
/* We should not be our own child */
if (gncBillTermGetChild(term) != term)
@ -401,8 +400,7 @@ static gboolean
billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata)
{
struct billterm_pdata *pdata = billterm_pdata;
return dom_tree_to_kvp_frame_given (node,
qof_instance_get_slots (QOF_INSTANCE(pdata->term)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE(pdata->term));
}
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,
qof_book_get_guid(book)));
if (qof_instance_get_slots (QOF_INSTANCE (book)))
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
qof_instance_get_slots (QOF_INSTANCE (book)));
if (kvpnode)
xmlAddChild(ret, kvpnode);
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(book_slots_string,
QOF_INSTANCE(book)));
#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
/* theoretically, we should be adding all the below to the book
@ -153,7 +149,7 @@ gnc_book_dom_tree_create(QofBook *book)
gboolean
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));
xmlElemDump(out, NULL, domnode);
@ -162,19 +158,17 @@ write_book_parts(FILE *out, QofBook *book)
if (ferror(out) || fprintf(out, "\n") < 0)
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,
qof_instance_get_slots (QOF_INSTANCE (book)));
if (kvpnode)
{
xmlElemDump(out, NULL, kvpnode);
xmlFreeNode(kvpnode);
xmlElemDump(out, NULL, slotsnode);
xmlFreeNode(slotsnode);
if (ferror(out) || fprintf(out, "\n") < 0)
return FALSE;
}
}
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
* 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);

View File

@ -57,7 +57,6 @@ xmlNodePtr
gnc_budget_dom_tree_create(GncBudget *bgt)
{
xmlNodePtr ret;
KvpFrame *kf;
ENTER ("(budget=%p)", bgt);
@ -79,14 +78,9 @@ gnc_budget_dom_tree_create(GncBudget *bgt)
/* field: Recurrence* */
xmlAddChild(ret, recurrence_to_dom_tree(bgt_recurrence_string,
gnc_budget_get_recurrence(bgt)));
/* slots */
kf = qof_instance_get_slots(QOF_INSTANCE(bgt));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(bgt_slots_string, kf);
if (kvpnode)
xmlAddChild(ret, kvpnode);
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(bgt_slots_string,
QOF_INSTANCE(bgt)));
LEAVE (" ");
return ret;
@ -159,8 +153,7 @@ budget_recurrence_handler (xmlNodePtr node, gpointer bgt)
static gboolean
budget_slots_handler (xmlNodePtr node, gpointer bgt)
{
return dom_tree_to_kvp_frame_given(
node, qof_instance_get_slots(QOF_INSTANCE(bgt)));
return dom_tree_create_instance_slots(node, QOF_INSTANCE(bgt));
}
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;
xmlNodePtr ret;
gboolean currency = gnc_commodity_is_iso(com);
xmlNodePtr kvpnode =
kvp_frame_to_dom_tree(cmdty_slots,
qof_instance_get_slots(QOF_INSTANCE(com)));
xmlNodePtr slotsnode =
qof_instance_slots_to_dom_tree(cmdty_slots, QOF_INSTANCE(com));
if (currency && !gnc_commodity_get_quote_flag(com) && !kvpnode)
if (currency && !gnc_commodity_get_quote_flag(com) && !slotsnode)
return NULL;
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));
}
if (kvpnode)
xmlAddChild(ret, kvpnode);
if (slotsnode)
xmlAddChild(ret, slotsnode);
return ret;
}
@ -172,8 +171,7 @@ set_commodity_value(xmlNodePtr node, gnc_commodity* com)
else if (g_strcmp0((char*)node->name, cmdty_slots) == 0)
{
/* We ignore the results here */
dom_tree_to_kvp_frame_given(node,
qof_instance_get_slots(QOF_INSTANCE(com)));
dom_tree_create_instance_slots(node, QOF_INSTANCE(com));
}
else
{

View File

@ -77,7 +77,7 @@ const gchar *customer_version_string = "2.0.0";
static xmlNodePtr
customer_dom_tree_create (GncCustomer *cust)
{
xmlNodePtr ret, kvpnode;
xmlNodePtr ret;
gnc_numeric num;
GncBillTerm *term;
GncTaxTable *taxtable;
@ -132,9 +132,9 @@ customer_dom_tree_create (GncCustomer *cust)
xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
qof_instance_get_guid(QOF_INSTANCE(taxtable))));
kvpnode = kvp_frame_to_dom_tree (cust_slots_string,
qof_instance_get_slots (QOF_INSTANCE(cust)));
if (kvpnode) xmlAddChild (ret, kvpnode);
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(cust_slots_string,
QOF_INSTANCE(cust)));
return ret;
}
@ -367,8 +367,7 @@ static gboolean
customer_slots_handler (xmlNodePtr node, gpointer cust_pdata)
{
struct customer_pdata *pdata = cust_pdata;
return dom_tree_to_kvp_frame_given (node,
qof_instance_get_slots (QOF_INSTANCE(pdata->customer)));
return dom_tree_create_instance_slots(node, QOF_INSTANCE(pdata->customer));
}
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
employee_dom_tree_create (GncEmployee *employee)
{
xmlNodePtr ret, kvpnode;
xmlNodePtr ret;
gnc_numeric num;
Account* ccard_acc;
@ -118,10 +118,9 @@ employee_dom_tree_create (GncEmployee *employee)
xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string,
qof_instance_get_guid(QOF_INSTANCE(ccard_acc))));
kvpnode = kvp_frame_to_dom_tree (employee_slots_string,
qof_instance_get_slots (QOF_INSTANCE(employee)));
if (kvpnode) xmlAddChild (ret, kvpnode);
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(employee_slots_string,
QOF_INSTANCE(employee)));
return ret;
}
@ -294,8 +293,7 @@ static gboolean
employee_slots_handler (xmlNodePtr node, gpointer employee_pdata)
{
struct employee_pdata *pdata = employee_pdata;
return dom_tree_to_kvp_frame_given (
node, qof_instance_get_slots (QOF_INSTANCE(pdata->employee)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE(pdata->employee));
}
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_slots_string "entry:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
@ -118,7 +115,6 @@ entry_dom_tree_create (GncEntry *entry)
GncTaxTable *taxtable;
GncOrder *order;
GncInvoice *invoice;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_entry_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,
qof_instance_get_guid(QOF_INSTANCE (order))));
kf = qof_instance_get_slots (QOF_INSTANCE(entry));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(entry_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(entry_slots_string,
QOF_INSTANCE(entry)));
return ret;
}
@ -677,8 +666,7 @@ entry_slots_handler (xmlNodePtr node, gpointer entry_pdata)
{
struct entry_pdata *pdata = entry_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->entry)));
return dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->entry));
}
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_slots_string "invoice:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
@ -93,7 +90,6 @@ static xmlNodePtr
invoice_dom_tree_create (GncInvoice *invoice)
{
xmlNodePtr ret;
KvpFrame *kf;
Timespec ts;
Transaction *txn;
GNCLot *lot;
@ -160,16 +156,9 @@ invoice_dom_tree_create (GncInvoice *invoice)
if (! gnc_numeric_zero_p (amt))
xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt));
kf = qof_instance_get_slots (QOF_INSTANCE(invoice));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(invoice_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(invoice_slots_string,
QOF_INSTANCE(invoice)));
return ret;
}
@ -411,9 +400,7 @@ static gboolean
invoice_slots_handler (xmlNodePtr node, gpointer invoice_pdata)
{
struct invoice_pdata *pdata = invoice_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->invoice)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->invoice));
}
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_slots_string "job:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static xmlNodePtr
job_dom_tree_create (GncJob *job)
{
xmlNodePtr ret;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_job_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,
gncJobGetActive (job)));
kf = qof_instance_get_slots (QOF_INSTANCE(job));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(job_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(job_slots_string,
QOF_INSTANCE(job)));
return ret;
}
@ -209,8 +199,7 @@ job_slots_handler (xmlNodePtr node, gpointer job_pdata)
{
struct job_pdata *pdata = job_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->job)));
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->job));
}
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 lot_id_string "lot:id"
#define lot_slots_string "lot:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
xmlNodePtr
gnc_lot_dom_tree_create(GNCLot *lot)
{
xmlNodePtr ret;
KvpFrame *kf;
ENTER("(lot=%p)", lot);
ret = xmlNewNode(NULL, BAD_CAST gnc_lot_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)));
kf = qof_instance_get_slots (QOF_INSTANCE (lot));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(lot_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(lot_slots_string,
QOF_INSTANCE(lot)));
LEAVE("");
return ret;
@ -113,8 +103,7 @@ lot_slots_handler (xmlNodePtr node, gpointer p)
gboolean success;
ENTER("(lot=%p)", pdata->lot);
success = dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->lot)));
success = dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->lot));
LEAVE("");
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_slots_string "order:slots"
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance*);
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
@ -79,7 +76,6 @@ order_dom_tree_create (GncOrder *order)
{
xmlNodePtr ret;
Timespec ts;
KvpFrame *kf;
ret = xmlNewNode(NULL, BAD_CAST gnc_order_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,
gncOrderGetActive (order)));
kf = qof_instance_get_slots (QOF_INSTANCE(order));
if (kf)
{
xmlNodePtr kvpnode = kvp_frame_to_dom_tree(order_slots_string, kf);
if (kvpnode)
{
xmlAddChild(ret, kvpnode);
}
}
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
xmlAddChild(ret, qof_instance_slots_to_dom_tree(order_slots_string,
QOF_INSTANCE(order)));
return ret;
}
@ -250,8 +240,7 @@ order_slots_handler (xmlNodePtr node, gpointer order_pdata)
{
struct order_pdata *pdata = order_pdata;
return dom_tree_to_kvp_frame_given
(node, qof_instance_get_slots (QOF_INSTANCE (pdata->order)));
return dom_tree_create_instance_slots(node, QOF_INSTANCE (pdata->order));
}
static struct dom_tree_handler order_handlers_v2[] =

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,6 +32,10 @@
#ifndef IO_GNCXML_H
#define IO_GNCXML_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.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);
#ifdef __cplusplus
}
#endif
#endif /* IO_GNCXML_H */

View File

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

View File

@ -24,6 +24,10 @@
#ifndef SIXTP_DOM_GENERATORS_H
#define SIXTP_DOM_GENERATORS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.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);
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 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 recurrence_to_dom_tree(const gchar *tag, const Recurrence *r);
gchar* double_to_string(double value);
#ifdef __cplusplus
}
#endif
#endif /* _SIXTP_DOM_GENERATORS_H_ */

View File

@ -20,16 +20,20 @@
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
********************************************************************/
extern "C"
{
#include "config.h"
#include <glib.h>
#include <string.h>
#include "gnc-xml-helper.h"
#include "gnc-engine.h"
#include <gnc-engine.h>
#include "sixtp-utils.h"
#include "sixtp-dom-parsers.h"
}
#include <kvp_frame.hpp>
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 */
if ((g_strcmp0("guid", type) == 0) || (g_strcmp0("new", type) == 0))
{
GncGUID *gid = g_new(GncGUID, 1);
auto gid = guid_new();
char *guid_str;
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)
{
gchar *text;
@ -89,7 +93,7 @@ dom_tree_to_integer_kvp_value(xmlNodePtr node)
if (string_to_gint64(text, &daint))
{
ret = kvp_value_new_gint64(daint);
ret = new KvpValue{daint};
}
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)
{
gchar *text;
@ -172,7 +176,7 @@ dom_tree_to_double_kvp_value(xmlNodePtr node)
if (string_to_double(text, &dadoub))
{
ret = kvp_value_new_double(dadoub);
ret = new KvpValue{dadoub};
}
g_free(text);
@ -180,7 +184,7 @@ dom_tree_to_double_kvp_value(xmlNodePtr node)
return ret;
}
KvpValue*
static KvpValue*
dom_tree_to_numeric_kvp_value(xmlNodePtr node)
{
gnc_numeric *danum;
@ -190,7 +194,7 @@ dom_tree_to_numeric_kvp_value(xmlNodePtr node)
if (danum)
{
ret = kvp_value_new_gnc_numeric(*danum);
ret = new KvpValue{*danum};
}
g_free(danum);
@ -198,7 +202,7 @@ dom_tree_to_numeric_kvp_value(xmlNodePtr node)
return ret;
}
KvpValue*
static KvpValue*
dom_tree_to_string_kvp_value(xmlNodePtr node)
{
gchar *datext;
@ -207,15 +211,13 @@ dom_tree_to_string_kvp_value(xmlNodePtr node)
datext = dom_tree_to_text(node);
if (datext)
{
ret = kvp_value_new_string(datext);
ret = new KvpValue{datext};
}
g_free(datext);
return ret;
}
KvpValue*
static KvpValue*
dom_tree_to_guid_kvp_value(xmlNodePtr node)
{
GncGUID *daguid;
@ -224,29 +226,24 @@ dom_tree_to_guid_kvp_value(xmlNodePtr node)
daguid = dom_tree_to_guid(node);
if (daguid)
{
ret = kvp_value_new_guid(daguid);
ret = new KvpValue{daguid};
}
g_free(daguid);
return ret;
}
KvpValue*
static KvpValue*
dom_tree_to_timespec_kvp_value (xmlNodePtr node)
{
Timespec ts;
KvpValue * ret = NULL;
KvpValue * ret = nullptr;
ts = dom_tree_to_timespec (node);
if (ts.tv_sec || ts.tv_nsec)
{
ret = kvp_value_new_timespec (ts);
}
ret = new KvpValue{ts};
return ret;
}
KvpValue*
static KvpValue*
dom_tree_to_gdate_kvp_value (xmlNodePtr node)
{
GDate *date;
@ -256,7 +253,7 @@ dom_tree_to_gdate_kvp_value (xmlNodePtr node)
if (date)
{
ret = kvp_value_new_gdate(*date);
ret = new KvpValue{*date};
}
g_free(date);
@ -303,7 +300,14 @@ string_to_binary(const gchar *str, void **v, guint64 *data_len)
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)
{
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;
}
KvpValue*
static KvpValue*
dom_tree_to_frame_kvp_value(xmlNodePtr node)
{
KvpFrame *frame;
@ -339,18 +343,16 @@ dom_tree_to_frame_kvp_value(xmlNodePtr node)
if (frame)
{
ret = kvp_value_new_frame(frame);
ret = new KvpValue{frame};
}
kvp_frame_delete(frame);
return ret;
}
struct kvp_val_converter
{
gchar *tag;
const gchar *tag;
KvpValue* (*converter)(xmlNodePtr node);
};
@ -368,7 +370,7 @@ struct kvp_val_converter val_converters[] =
{ 0, 0 },
};
KvpValue*
static KvpValue*
dom_tree_to_kvp_value(xmlNodePtr node)
{
xmlChar *xml_type;
@ -403,7 +405,7 @@ dom_tree_to_kvp_value(xmlNodePtr node)
return ret;
}
gboolean
static gboolean
dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
{
xmlNodePtr mark;
@ -440,7 +442,8 @@ dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
{
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
{
@ -458,20 +461,23 @@ dom_tree_to_kvp_frame_given(xmlNodePtr node, KvpFrame *frame)
KvpFrame*
dom_tree_to_kvp_frame(xmlNodePtr node)
{
KvpFrame *ret;
g_return_val_if_fail(node, NULL);
ret = kvp_frame_new();
auto ret = new KvpFrame;
if (dom_tree_to_kvp_frame_given(node, ret))
return ret;
kvp_frame_delete(ret);
delete ret;
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 *
dom_tree_to_text(xmlNodePtr tree)
@ -683,7 +689,8 @@ dom_tree_to_gdate(xmlNodePtr node)
}
g_free(content);
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 ) )
{
PWARN("invalid date");

View File

@ -23,6 +23,10 @@
#ifndef SIXTP_DOM_PARSERS_H
#define SIXTP_DOM_PARSERS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h>
@ -46,21 +50,7 @@ GDate* dom_tree_to_gdate(xmlNodePtr node);
gnc_numeric* dom_tree_to_gnc_numeric(xmlNodePtr node);
gchar * dom_tree_to_text(xmlNodePtr tree);
gboolean string_to_binary(const gchar *str, void **v, guint64 *data_len);
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_create_instance_slots(xmlNodePtr node, QofInstance *inst);
gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint);
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,
gpointer data);
#ifdef __cplusplus
}
#endif
#endif /* _SIXTP_DOM_PARSERS_H_ */

View File

@ -2,8 +2,8 @@
SUBDIRS = test-files
test_date_converting_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -12,8 +12,8 @@ test_date_converting_SOURCES = \
test-date-converting.c
test_dom_converters1_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -22,22 +22,22 @@ test_dom_converters1_SOURCES = \
test-dom-converters1.c
test_kvp_frames_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
${top_srcdir}/src/backend/xml/sixtp-to-dom-parser.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
# not load it as a module and cannot link to it
# and remain portable.
test_load_example_account_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -60,8 +60,8 @@ test_load_example_account_SOURCES = \
test-load-example-account.c
test_string_converters_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -70,8 +70,8 @@ test_string_converters_SOURCES = \
test-string-converters.c
test_xml_account_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -93,8 +93,8 @@ test_xml_account_SOURCES = \
test-xml-account.c
test_xml_commodity_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -116,8 +116,8 @@ test_xml_commodity_SOURCES = \
test-xml-commodity.c
test_xml_pricedb_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -139,8 +139,8 @@ test_xml_pricedb_SOURCES = \
test-xml-pricedb.c
test_xml_transaction_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -162,8 +162,8 @@ test_xml_transaction_SOURCES = \
test-xml-transaction.c
test_xml2_is_file_SOURCES = \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.c \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.c \
${top_srcdir}/src/backend/xml/sixtp-dom-parsers.cpp \
${top_srcdir}/src/backend/xml/sixtp-dom-generators.cpp \
${top_srcdir}/src/backend/xml/sixtp-utils.c \
${top_srcdir}/src/backend/xml/sixtp.c \
${top_srcdir}/src/backend/xml/sixtp-stack.c \
@ -221,7 +221,7 @@ TESTS_ENVIRONMENT = \
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 = \
${top_builddir}/src/engine/libgncmod-engine.la

View File

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

View File

@ -4,16 +4,19 @@
#ifndef TEST_FILE_STUFF_H
#define TEST_FILE_STUFF_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h>
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-xml-helper.h"
#include "io-gncxml-gen.h"
#include "sixtp.h"
#include <gnc-commodity.h>
#include <gnc-engine.h>
#include <gnc-xml-helper.h>
#include <io-gncxml-gen.h>
#include <sixtp.h>
typedef struct KvpFrameImpl KvpFrame;
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,
sixtp *parser, const char *parser_tag,
QofBook *book);
#ifdef __cplusplus
}
#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);
return msg;
}
g_hash_table_unref (features_used);
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
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]
Implements accounting Lots.

View File

@ -153,7 +153,7 @@ SHORT_NAMES = NO
# comments will behave just like regular Qt-style comments
# (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
# 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.
# 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
# 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
# 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
# enable parsing support.
@ -675,7 +675,9 @@ FILE_PATTERNS = *.c \
*.h \
*.txt \
*.py \
*.pl
*.pl \
*.cpp \
*.hpp
# 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.
@ -703,7 +705,7 @@ EXCLUDE_SYMLINKS = YES
# against the file with absolute path, so to exclude all test directories
# 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
# (namespaces, classes, functions, etc.) that should be excluded from the
@ -1460,18 +1462,6 @@ GENERATE_XML = NO
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
# dump the program listings (including syntax highlighting
# 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 \
gncmod-engine.c \
swig-engine.c \
kvp-scm.c \
kvp-scm.cpp \
engine-helpers.c \
glib-helpers.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);
}
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

View File

@ -186,10 +186,6 @@ void xaccQueryAddClearedMatch(QofQuery * q, cleared_match_t how, QofQueryOp op);
void xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid,
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

View File

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

View File

@ -319,8 +319,6 @@ gboolean SXRegister (void);
#define xaccSchedXactionIsDirty(X) qof_instance_is_dirty (QOF_INSTANCE(X))
/** \deprecated */
#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 */

View File

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

View File

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

View File

@ -92,8 +92,6 @@ enum
PROP_SX_SHARES, /* KVP */
PROP_LOT, /* KVP */
PROP_ONLINE_ACCOUNT, /* KVP */
PROP_LOT_SPLIT, /* KVP */
PROP_PEER_GUID, /* KVP */
PROP_GAINS_SPLIT, /* KVP */
PROP_GAINS_SOURCE, /* KVP */
PROP_RUNTIME_0,
@ -213,14 +211,6 @@ gnc_split_get_property(GObject *object,
key = "online_id";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_LOT_SPLIT:
key = "lot-split";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_PEER_GUID:
key = "peer_guid";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SPLIT:
key = "gains-split";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
@ -307,14 +297,6 @@ gnc_split_set_property(GObject *object,
key = "online_id";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_LOT_SPLIT:
key = "lot-split";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_PEER_GUID:
key = "peer_guid";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SPLIT:
key = "gains-split";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
@ -496,26 +478,6 @@ gnc_split_class_init(SplitClass* klass)
NULL,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_LOT_SPLIT,
g_param_spec_int64 ("lot-split",
"Lot Split",
"Indicates that the split was divided into two "
"splits in order to balance a lot capital gains "
"transaction. Contains a timestamp of the action.",
G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_PEER_GUID,
g_param_spec_boxed ("peer-guid",
"Peer GUID",
"The other split in the division.",
GNC_TYPE_GUID,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_GAINS_SPLIT,
@ -571,9 +533,6 @@ xaccSplitReinit(Split * split)
split->cleared_balance = gnc_numeric_zero();
split->reconciled_balance = gnc_numeric_zero();
if (split->inst.kvp_data)
kvp_frame_delete(split->inst.kvp_data);
split->inst.kvp_data = kvp_frame_new();
qof_instance_set_idata(split, 0);
split->gains = GAINS_STATUS_UNKNOWN;
@ -625,7 +584,7 @@ xaccDupeSplit (const Split *s)
split->memo = CACHE_INSERT(s->memo);
split->action = CACHE_INSERT(s->action);
split->inst.kvp_data = kvp_frame_copy (s->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (split), QOF_INSTANCE (s));
split->reconciled = s->reconciled;
split->date_reconciled = s->date_reconciled;
@ -675,7 +634,7 @@ xaccSplitCloneNoKvp (const Split *s)
void
xaccSplitCopyKvp (const Split *from, Split *to)
{
to->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
}
/*################## Added for Reg2 #################*/
@ -727,7 +686,7 @@ xaccSplitDump (const Split *split, const char *tag)
printf(" Gains: %p\n", split->gains_split);
printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
printf(" Action: %s\n", split->action ? split->action : "(null)");
printf(" KVP Data: %p\n", split->inst.kvp_data);
printf(" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
printf(" Recncld: %c (date %s)\n", split->reconciled,
gnc_print_date(split->date_reconciled));
printf(" Value: %s\n", gnc_numeric_to_string(split->value));
@ -770,10 +729,7 @@ xaccFreeSplit (Split *split)
split->date_reconciled.tv_sec = 0;
split->date_reconciled.tv_nsec = 0;
if (split->inst.kvp_data)
kvp_frame_delete(split->inst.kvp_data);
split->inst.kvp_data = NULL;
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
// Is this right?
if (split->gains_split) split->gains_split->gains_split = NULL;
/* qof_instance_release(&split->inst); */
@ -859,13 +815,13 @@ xaccSplitEqual(const Split *sa, const Split *sb,
return FALSE;
}
if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
{
char *frame_a;
char *frame_b;
frame_a = kvp_frame_to_string (sa->inst.kvp_data);
frame_b = kvp_frame_to_string (sb->inst.kvp_data);
frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
@ -1128,7 +1084,8 @@ void
xaccSplitDetermineGainStatus (Split *split)
{
Split *other;
KvpValue *val;
GValue v = G_VALUE_INIT;
GncGUID *guid = NULL;
if (GAINS_STATUS_UNKNOWN != split->gains) return;
@ -1140,8 +1097,10 @@ xaccSplitDetermineGainStatus (Split *split)
return;
}
val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
if (!val)
qof_instance_get_kvp (QOF_INSTANCE (split), "gains-source", &v);
if (G_VALUE_HOLDS_BOXED (&v))
guid = (GncGUID*)g_value_get_boxed (&v);
if (!guid)
{
// CHECKME: We leave split->gains_split alone. Is that correct?
split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
@ -1149,10 +1108,10 @@ xaccSplitDetermineGainStatus (Split *split)
else
{
QofCollection *col;
col = qof_book_get_collection (qof_instance_get_book(split), GNC_ID_SPLIT);
col = qof_book_get_collection (qof_instance_get_book(split),
GNC_ID_SPLIT);
split->gains = GAINS_STATUS_GAINS;
other = (Split *) qof_collection_lookup_entity (col,
kvp_value_get_guid (val));
other = (Split *) qof_collection_lookup_entity (col, guid);
split->gains_split = other;
}
}
@ -2052,10 +2011,13 @@ xaccSplitGetBook (const Split *split)
const char *
xaccSplitGetType(const Split *s)
{
const char *split_type;
GValue v = G_VALUE_INIT;
const char *split_type = NULL;
if (!s) return NULL;
split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
qof_instance_get_kvp (QOF_INSTANCE (s), "split-type", &v);
if (G_VALUE_HOLDS_STRING (&v))
split_type = g_value_get_string (&v);
return split_type ? split_type : "normal";
}
@ -2064,16 +2026,83 @@ xaccSplitGetType(const Split *s)
void
xaccSplitMakeStockSplit(Split *s)
{
GValue v = G_VALUE_INIT;
xaccTransBeginEdit (s->parent);
s->value = gnc_numeric_zero();
kvp_frame_set_string(s->inst.kvp_data, "split-type", "stock-split");
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, "stock-split");
qof_instance_set_kvp (QOF_INSTANCE (s), "split-type", &v);
SET_GAINS_VDIRTY(s);
mark_split(s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
}
void
xaccSplitAddPeerSplit (Split *split, const Split *other_split,
time64 timestamp)
{
const GncGUID* guid;
g_return_if_fail (split != NULL);
g_return_if_fail (other_split != NULL);
guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
xaccTransBeginEdit (split->parent);
qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
timespec_now(), "peer_guid", guid);
mark_split (split);
qof_instance_set_dirty (QOF_INSTANCE (split));
xaccTransCommitEdit (split->parent);
}
gboolean
xaccSplitHasPeers (const Split *split)
{
return qof_instance_has_slot (QOF_INSTANCE (split), "lot-split");
}
gboolean
xaccSplitIsPeerSplit (const Split *split, const Split *other_split)
{
const GncGUID* guid;
g_return_val_if_fail (split != NULL, FALSE);
g_return_val_if_fail (other_split != NULL, FALSE);
guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
return qof_instance_kvp_has_guid (QOF_INSTANCE (split), "lot-split",
"peer_guid", guid);
}
void
xaccSplitRemovePeerSplit (Split *split, const Split *other_split)
{
const GncGUID* guid;
g_return_if_fail (split != NULL);
g_return_if_fail (other_split != NULL);
guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
xaccTransBeginEdit (split->parent);
qof_instance_kvp_remove_guid (QOF_INSTANCE (split), "lot-split",
"peer_guid", guid);
mark_split (split);
qof_instance_set_dirty (QOF_INSTANCE (split));
xaccTransCommitEdit (split->parent);
}
void
xaccSplitMergePeerSplits (Split *split, const Split *other_split)
{
xaccTransBeginEdit (split->parent);
qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
QOF_INSTANCE (other_split), "lot-split");
mark_split (split);
qof_instance_set_dirty (QOF_INSTANCE (split));
xaccTransCommitEdit (split->parent);
}
/********************************************************************\
\********************************************************************/
@ -2094,29 +2123,18 @@ xaccSplitGetOtherSplit (const Split *split)
Transaction *trans;
int count, num_splits;
Split *other = NULL;
KvpValue *sva;
gboolean lot_split;
gboolean trading_accts;
if (!split) return NULL;
trans = split->parent;
if (!trans) return NULL;
#ifdef OLD_ALGO_HAS_ONLY_TWO_SPLITS
Split *s1, *s2;
if (g_list_length (trans->splits) != 2) return NULL;
s1 = g_list_nth_data (trans->splits, 0);
s2 = g_list_nth_data (trans->splits, 1);
if (s1 == split) return s2;
return s1;
#endif
trading_accts = xaccTransUseTradingAccounts (trans);
num_splits = xaccTransCountSplits(trans);
count = num_splits;
sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
if (!sva && !trading_accts && (2 != count)) return NULL;
lot_split = qof_instance_has_slot(QOF_INSTANCE (split), "lot-split");
if (!lot_split && !trading_accts && (2 != count)) return NULL;
for (i = 0; i < num_splits; i++)
{
@ -2126,7 +2144,7 @@ xaccSplitGetOtherSplit (const Split *split)
--count;
continue;
}
if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
if (qof_instance_has_slot (QOF_INSTANCE (s), "lot-split"))
{
--count;
continue;
@ -2148,27 +2166,40 @@ xaccSplitGetOtherSplit (const Split *split)
gnc_numeric
xaccSplitVoidFormerAmount(const Split *split)
{
GValue v = G_VALUE_INIT;
gnc_numeric *num = NULL;
g_return_val_if_fail(split, gnc_numeric_zero());
return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
qof_instance_get_kvp (QOF_INSTANCE (split), void_former_amt_str, &v);
if (G_VALUE_HOLDS_BOXED (&v))
num = (gnc_numeric*)g_value_get_boxed (&v);
return num ? *num : gnc_numeric_zero();
}
gnc_numeric
xaccSplitVoidFormerValue(const Split *split)
{
GValue v = G_VALUE_INIT;
gnc_numeric *num = NULL;
g_return_val_if_fail(split, gnc_numeric_zero());
return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
qof_instance_get_kvp (QOF_INSTANCE (split), void_former_val_str, &v);
if (G_VALUE_HOLDS_BOXED (&v))
num = (gnc_numeric*)g_value_get_boxed (&v);
return num ? *num : gnc_numeric_zero();
}
void
xaccSplitVoid(Split *split)
{
gnc_numeric zero = gnc_numeric_zero();
KvpFrame *frame = split->inst.kvp_data;
gnc_numeric zero = gnc_numeric_zero(), num;
GValue v = G_VALUE_INIT;
kvp_frame_set_gnc_numeric(frame, void_former_amt_str,
xaccSplitGetAmount(split));
kvp_frame_set_gnc_numeric(frame, void_former_val_str,
xaccSplitGetValue(split));
g_value_init (&v, GNC_TYPE_NUMERIC);
num = xaccSplitGetAmount(split);
g_value_set_boxed (&v, &num);
qof_instance_set_kvp (QOF_INSTANCE (split), void_former_amt_str, &v);
num = xaccSplitGetValue(split);
g_value_set_boxed (&v, &num);
qof_instance_set_kvp (QOF_INSTANCE (split), void_former_val_str, &v);
/* Marking dirty handled by SetAmount etc. */
xaccSplitSetAmount (split, zero);
@ -2179,13 +2210,11 @@ xaccSplitVoid(Split *split)
void
xaccSplitUnvoid(Split *split)
{
KvpFrame *frame = split->inst.kvp_data;
xaccSplitSetAmount (split, xaccSplitVoidFormerAmount(split));
xaccSplitSetValue (split, xaccSplitVoidFormerValue(split));
xaccSplitSetReconcile(split, NREC);
kvp_frame_set_slot(frame, void_former_amt_str, NULL);
kvp_frame_set_slot(frame, void_former_val_str, NULL);
qof_instance_set_kvp (QOF_INSTANCE (split), void_former_amt_str, NULL);
qof_instance_set_kvp (QOF_INSTANCE (split), void_former_val_str, NULL);
qof_instance_set_dirty (QOF_INSTANCE (split));
}
@ -2342,7 +2371,6 @@ gboolean xaccSplitRegister (void)
{ SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, NULL },
{ SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, NULL },
{ SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, NULL },
{ SPLIT_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)xaccSplitGetBook, NULL },
{
QOF_PARAM_GUID, QOF_TYPE_GUID,

View File

@ -338,7 +338,7 @@ gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
*
* @param check_txn_splits If the pointers are not equal, but
* 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.
*/
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. */
GList *xaccSplitListGetUniqueTransactions(const GList *splits);
/*################## 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
@ -492,8 +515,6 @@ gnc_numeric xaccSplitVoidFormerValue(const Split *split);
* override so the gnome-search dialog displays the right type.
@{
*/
#define SPLIT_KVP "kvp"
#define SPLIT_DATE_RECONCILED "date-reconciled"
#define SPLIT_BALANCE "balance"
#define SPLIT_CLEARED_BALANCE "cleared-balance"

View File

@ -312,7 +312,6 @@ gnc_transaction_get_property(GObject* object,
GParamSpec* pspec)
{
Transaction* tx;
KvpFrame *frame;
gchar *key;
GValue *temp;
@ -361,7 +360,6 @@ gnc_transaction_set_property(GObject* object,
GParamSpec* pspec)
{
Transaction* tx;
KvpFrame *frame;
gchar *key;
g_return_if_fail(GNC_IS_TRANSACTION(object));
@ -633,7 +631,7 @@ dupe_trans (const Transaction *from)
to->inst.e_type = NULL;
qof_instance_set_guid(to, guid_null());
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;
}
@ -688,7 +686,7 @@ xaccTransClone (const Transaction *from)
int length = g_list_length (from->splits);
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);
for (i = 0; i < length; ++i)
xaccSplitCopyKvp (g_list_nth_data (from->splits, i),
@ -934,13 +932,14 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb,
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_b;
frame_a = kvp_frame_to_string (ta->inst.kvp_data);
frame_b = kvp_frame_to_string (tb->inst.kvp_data);
frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (ta));
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);
@ -1688,7 +1687,7 @@ xaccTransRollbackEdit (Transaction *trans)
trans->date_entered = orig->date_entered;
trans->date_posted = orig->date_posted;
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
splits as in the original, but some of them may have changed, so
@ -1713,7 +1712,7 @@ xaccTransRollbackEdit (Transaction *trans)
xaccSplitRollbackEdit(s);
SWAP(s->action, so->action);
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->amount = so->amount;
s->value = so->value;
@ -1924,20 +1923,15 @@ xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
void
xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
{
KvpValue* kvp_value;
KvpFrame* frame;
GValue v = G_VALUE_INIT;
if (!trans) return;
/* We additionally save this date into a kvp frame to ensure in
* the future a date which was set as *date* (without time) can
* clearly be distinguished from the Timespec. */
kvp_value = kvp_value_new_gdate(date);
frame = kvp_frame_set_value_nc(trans->inst.kvp_data, TRANS_DATE_POSTED, kvp_value);
if (!frame)
{
kvp_value_delete(kvp_value);
}
g_value_init (&v, G_TYPE_DATE);
g_value_set_boxed (&v, &date);
qof_instance_set_kvp (QOF_INSTANCE(trans), TRANS_DATE_POSTED, &v);
/* mark dirty and commit handled by SetDateInternal */
xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_timespec(date));
@ -2002,9 +1996,12 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year)
void
xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts)
{
GValue v = G_VALUE_INIT;
if (!trans || !ts) return;
g_value_init (&v, GNC_TYPE_TIMESPEC);
g_value_set_boxed (&v, ts);
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));
xaccTransCommitEdit(trans);
}
@ -2013,9 +2010,12 @@ void
xaccTransSetTxnType (Transaction *trans, char type)
{
char s[2] = {type, '\0'};
GValue v = G_VALUE_INIT;
g_return_if_fail(trans);
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, s);
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));
xaccTransCommitEdit(trans);
}
@ -2025,7 +2025,7 @@ void xaccTransClearReadOnly (Transaction *trans)
if (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);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
@ -2037,9 +2037,11 @@ xaccTransSetReadOnly (Transaction *trans, const char *reason)
{
if (trans && reason)
{
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, reason);
xaccTransBeginEdit(trans);
kvp_frame_set_string (trans->inst.kvp_data,
TRANS_READ_ONLY_REASON, reason);
qof_instance_set_kvp (QOF_INSTANCE (trans), TRANS_READ_ONLY_REASON, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
@ -2092,10 +2094,12 @@ xaccTransSetDescription (Transaction *trans, const char *desc)
void
xaccTransSetAssociation (Transaction *trans, const char *assoc)
{
GValue v = G_VALUE_INIT;
if (!trans || !assoc) return;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, assoc);
xaccTransBeginEdit(trans);
kvp_frame_set_string (trans->inst.kvp_data, assoc_uri_str, assoc);
qof_instance_set_kvp (QOF_INSTANCE (trans), assoc_uri_str, &v);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
@ -2111,10 +2115,13 @@ qofTransSetNotes (Transaction *trans, const char *notes)
void
xaccTransSetNotes (Transaction *trans, const char *notes)
{
GValue v = G_VALUE_INIT;
if (!trans || !notes) return;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, notes);
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));
xaccTransCommitEdit(trans);
}
@ -2126,9 +2133,14 @@ xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
xaccTransBeginEdit(trans);
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
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));
xaccTransCommitEdit(trans);
}
@ -2186,23 +2198,34 @@ xaccTransGetDescription (const Transaction *trans)
const char *
xaccTransGetAssociation (const Transaction *trans)
{
return trans ?
kvp_frame_get_string (trans->inst.kvp_data, assoc_uri_str) : NULL;
GValue v = G_VALUE_INIT;
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 *
xaccTransGetNotes (const Transaction *trans)
{
return trans ?
kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL;
GValue v = G_VALUE_INIT;
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
xaccTransGetIsClosingTxn (const Transaction *trans)
{
return trans ?
kvp_frame_get_gint64 (trans->inst.kvp_data, trans_is_closing_str)
: FALSE;
GValue v = G_VALUE_INIT;
if (!trans) return 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
* from there because it doesn't suffer from time zone
* shifts. */
const KvpValue* kvp_value =
kvp_frame_get_slot(trans->inst.kvp_data, TRANS_DATE_POSTED);
if (kvp_value)
result = kvp_value_get_gdate(kvp_value);
else
GValue v = G_VALUE_INIT;
qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_DATE_POSTED, &v);
if (G_VALUE_HOLDS_BOXED (&v))
result = *(GDate*)g_value_get_boxed (&v);
if (! g_date_valid (&result))
result = timespec_to_gdate(xaccTransRetDatePostedTS(trans));
}
else
@ -2276,14 +2299,13 @@ xaccTransRetDateEnteredTS (const Transaction *trans)
void
xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts)
{
KvpValue *value;
GValue v = G_VALUE_INIT;
if (!trans || !ts) return;
value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP);
if (value)
*ts = kvp_value_get_timespec (value);
else
qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_DATE_DUE_KVP, &v);
if (G_VALUE_HOLDS_BOXED (&v))
*ts = *(Timespec*)g_value_get_boxed (&v);
if (ts->tv_sec == 0)
xaccTransGetDatePostedTS (trans, ts);
}
@ -2298,10 +2320,15 @@ xaccTransRetDateDueTS (const Transaction *trans)
char
xaccTransGetTxnType (const Transaction *trans)
{
const char *s;
const char *s = NULL;
GValue v = G_VALUE_INIT;
if (!trans) return TXN_TYPE_NONE;
s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP);
if (s) return *s;
qof_instance_get_kvp (QOF_INSTANCE (trans), TRANS_TXN_TYPE_KVP, &v);
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s && strlen (s) == 0)
return *s;
return TXN_TYPE_NONE;
}
@ -2312,8 +2339,16 @@ xaccTransGetReadOnly (const Transaction *trans)
/* XXX This flag should be cached in the transaction structure
* for performance reasons, since its checked every trans commit.
*/
return trans ? kvp_frame_get_string (
trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
GValue v = G_VALUE_INIT;
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
@ -2491,26 +2526,26 @@ gnc_book_count_transactions(QofBook *book)
void
xaccTransVoid(Transaction *trans, const char *reason)
{
KvpFrame *frame;
KvpValue *val;
Timespec now;
GValue v = G_VALUE_INIT;
char iso8601_str[ISO_DATELENGTH + 1] = "";
g_return_if_fail(trans && reason);
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);
kvp_frame_set_slot(frame, void_former_notes_str, val);
g_value_set_string (&v, _("Voided transaction"));
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"));
kvp_frame_set_string(frame, void_reason_str, reason);
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);
gnc_timespec_to_iso8601_buff (timespec_now (), iso8601_str);
g_value_set_string (&v, iso8601_str);
qof_instance_set_kvp (QOF_INSTANCE (trans), void_time_str, &v);
FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
@ -2522,48 +2557,63 @@ xaccTransVoid(Transaction *trans, const char *reason)
gboolean
xaccTransGetVoidStatus(const Transaction *trans)
{
const char *s = NULL;
GValue v = G_VALUE_INIT;
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 *
xaccTransGetVoidReason(const Transaction *trans)
{
g_return_val_if_fail(trans, NULL);
return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str);
GValue v = G_VALUE_INIT;
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
xaccTransGetVoidTime(const Transaction *tr)
{
const char *val;
Timespec void_time = {0, 0};
GValue v = G_VALUE_INIT;
const char *s = NULL;
Timespec void_time = {0, 0}, *ts;
g_return_val_if_fail(tr, void_time);
val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str);
return val ? gnc_iso8601_to_timespec_gmt(val) : void_time;
qof_instance_get_kvp (QOF_INSTANCE (tr), void_time_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s)
return gnc_iso8601_to_timespec_gmt (s);
return void_time;
}
void
xaccTransUnvoid (Transaction *trans)
{
KvpFrame *frame;
KvpValue *val;
GValue v = G_VALUE_INIT;
const char *s = NULL;
g_return_if_fail(trans);
frame = trans->inst.kvp_data;
val = kvp_frame_get_slot(frame, void_reason_str);
if (!val) return; /* Transaction isn't voided. Bail. */
qof_instance_get_kvp (QOF_INSTANCE (trans), void_reason_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s == NULL) return; /* Transaction isn't voided. Bail. */
xaccTransBeginEdit(trans);
val = kvp_frame_get_slot(frame, void_former_notes_str);
kvp_frame_set_slot(frame, trans_notes_str, val);
kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL);
kvp_frame_set_slot_nc(frame, void_reason_str, NULL);
kvp_frame_set_slot_nc(frame, void_time_str, NULL);
qof_instance_get_kvp (QOF_INSTANCE (trans), void_former_notes_str, &v);
if (G_VALUE_HOLDS_STRING (&v))
qof_instance_set_kvp (QOF_INSTANCE (trans), trans_notes_str, &v);
qof_instance_set_kvp (QOF_INSTANCE (trans), void_former_notes_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));
@ -2576,7 +2626,7 @@ Transaction *
xaccTransReverse (Transaction *orig)
{
Transaction *trans;
KvpValue *kvp_val;
GValue v = G_VALUE_INIT;
g_return_val_if_fail(orig, NULL);
trans = xaccTransClone(orig);
@ -2591,8 +2641,9 @@ xaccTransReverse (Transaction *orig)
});
/* Now update the original with a pointer to the new one */
kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans));
kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val);
g_value_init (&v, GNC_TYPE_GUID);
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));
xaccTransCommitEdit(trans);
@ -2602,11 +2653,13 @@ xaccTransReverse (Transaction *orig)
Transaction *
xaccTransGetReversedBy(const Transaction *trans)
{
GncGUID *guid;
GValue v = G_VALUE_INIT;
g_return_val_if_fail(trans, NULL);
guid = kvp_frame_get_guid(trans->inst.kvp_data, TRANS_REVERSED_BY);
return xaccTransLookup(guid, qof_instance_get_book(trans));
qof_instance_get_kvp (QOF_INSTANCE(trans), TRANS_REVERSED_BY, &v);
if (G_VALUE_HOLDS_BOXED (&v))
return xaccTransLookup((GncGUID*)g_value_get_boxed (&v),
qof_instance_get_book(trans));
return NULL;
}
void
@ -2849,10 +2902,6 @@ gboolean xaccTransRegister (void)
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

View File

@ -164,13 +164,6 @@ QofBackend * xaccTransactionGetBackend (Transaction *trans);
void xaccEnableDataScrubbing(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 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
* splits to indicate that they're linked.
*/
qof_instance_set (QOF_INSTANCE (split),
"lot-split", now,
"peer_guid", xaccSplitGetGUID (new_split),
NULL);
qof_instance_set (QOF_INSTANCE (new_split),
"lot-split", now,
"peer_guid", xaccSplitGetGUID (split),
NULL);
xaccSplitAddPeerSplit(split, new_split, now);
xaccSplitAddPeerSplit(new_split, split, now);
xaccAccountInsertSplit (acc, new_split);
xaccTransAppendSplit (trans, new_split);
/* Set the amount and value after the split is in the transaction

View File

@ -37,8 +37,9 @@
#include "gnc-session.h"
#include "guile-mappings.h"
#include "gnc-guile-utils.h"
#include "qof.h"
#include "qofbookslots.h"
#include <qof.h>
#include <qofbookslots.h>
/** \todo Code dependent on the private query headers
qofquery-p.h and qofquerycore-p.h may need to be modified.
These files are temporarily exported for QOF 0.6.0 but
@ -477,32 +478,6 @@ gnc_scm2amt_match_how (SCM how_scm)
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
gnc_scm2bitfield (SCM field_scm)
{
@ -558,33 +533,6 @@ gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
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
gnc_guid_glist2scm (const GList *account_guids)
{
@ -719,287 +667,6 @@ gnc_query_path_free (GSList *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
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 (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
{
@ -1287,31 +946,6 @@ gnc_scm2query_term_query_v2 (SCM qt_scm)
pd = qof_query_char_predicate (options, 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
{
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);
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
{

View File

@ -142,18 +142,6 @@ functions. */
QofSession * qof_session_new (void);
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
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(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
void gnc_kvp_frame_delete_at_path(KvpFrame *frame, GSList *key_path);
void kvp_frame_set_slot_path_gslist(
KvpFrame *frame, KvpValue *new_value, GSList *key_path);
KvpValue * kvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path);
void qof_book_options_delete (QofBook *book);
void qof_book_set_option (QofBook *book, KvpValue *new_value, GSList *key_path);
KvpValue* qof_book_get_option (QofBook *book, GSList *key_path);
%clear GSList *key_path;

View File

@ -476,24 +476,29 @@ gnc_budget_get_num_periods(const GncBudget* budget)
#define BUF_SIZE (10 + GUID_ENCODING_LENGTH + \
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 */
/* What happens when account is deleted, after we have an entry for it? */
void
gnc_budget_unset_account_period_value(GncBudget *budget, const Account *account,
guint period_num)
{
const GncGUID *guid;
KvpFrame *frame;
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);
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
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_kvp (QOF_INSTANCE (budget), path, NULL);
qof_instance_set_dirty(&budget->inst);
gnc_budget_commit_edit(budget);
@ -507,10 +512,7 @@ void
gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
guint period_num, gnc_numeric val)
{
const GncGUID *guid;
KvpFrame *frame;
gchar path[BUF_SIZE];
gchar *bufend;
/* Watch out for an off-by-one error here:
* 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;
}
gnc_budget_begin_edit(budget);
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
guid = xaccAccountGetGUID(account);
bufend = guid_to_string_buff(guid, path);
g_sprintf(bufend, "/%d", period_num);
g_return_if_fail (budget != NULL);
g_return_if_fail (account != NULL);
make_period_path (account, period_num, path);
gnc_budget_begin_edit(budget);
if (gnc_numeric_check(val))
kvp_frame_set_value(frame, path, NULL);
qof_instance_set_kvp (QOF_INSTANCE (budget), path, NULL);
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);
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 */
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)
{
GValue v = G_VALUE_INIT;
gchar path[BUF_SIZE];
gchar *bufend;
KvpFrame *frame;
gconstpointer ptr = NULL;
g_return_val_if_fail(GNC_IS_BUDGET(budget), FALSE);
g_return_val_if_fail(account, FALSE);
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
bufend = guid_to_string_buff(xaccAccountGetGUID(account), path);
g_sprintf(bufend, "/%d", period_num);
return (kvp_frame_get_value(frame, path) != NULL);
make_period_path (account, period_num, path);
qof_instance_get_kvp (QOF_INSTANCE (budget), path, &v);
if (G_VALUE_HOLDS_BOXED (&v))
ptr = g_value_get_boxed (&v);
return (ptr != NULL);
}
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)
{
gnc_numeric numeric;
gnc_numeric *numeric = NULL;
gchar path[BUF_SIZE];
gchar *bufend;
KvpFrame *frame;
GValue v = G_VALUE_INIT;
numeric = gnc_numeric_zero();
g_return_val_if_fail(GNC_IS_BUDGET(budget), numeric);
g_return_val_if_fail(account, numeric);
g_return_val_if_fail(GNC_IS_BUDGET(budget), gnc_numeric_zero());
g_return_val_if_fail(account, gnc_numeric_zero());
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
bufend = guid_to_string_buff(xaccAccountGetGUID(account), path);
g_sprintf(bufend, "/%d", period_num);
make_period_path (account, period_num, path);
qof_instance_get_kvp (QOF_INSTANCE (budget), path, &v);
if (G_VALUE_HOLDS_BOXED (&v))
numeric = (gnc_numeric*)g_value_get_boxed (&v);
numeric = kvp_frame_get_numeric(frame, path);
/* This still returns zero if unset, but callers can check for that. */
return numeric;
if (numeric)
return *numeric;
return gnc_numeric_zero();
}
@ -637,8 +646,6 @@ gnc_budget_get_default (QofBook *book)
g_return_val_if_fail(book, NULL);
/* See if there is a budget selected in the KVP perferences */
qof_instance_get (QOF_INSTANCE (book),
"default-budget", &default_budget_guid,
NULL);

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_source (dest, gnc_commodity_get_quote_source (src));
gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
kvp_frame_delete (dest->inst.kvp_data);
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
}
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));
kvp_frame_delete (dest->inst.kvp_data);
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
reset_printname(dest_priv);
reset_unique_name(dest_priv);
@ -1087,11 +1085,14 @@ static gboolean
gnc_commodity_get_auto_quote_control_flag(const gnc_commodity *cm)
{
const char *str;
GValue v = G_VALUE_INIT;
if (!cm) return FALSE;
str = kvp_frame_get_string(cm->inst.kvp_data, "auto_quote_control");
return !str || (strcmp(str, "false") != 0);
qof_instance_get_kvp (QOF_INSTANCE (cm), "auto_quote_control", &v);
if (G_VALUE_HOLDS_STRING (&v) &&
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)
{
const char *str;
GValue v = G_VALUE_INIT;
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,
const gboolean flag)
{
GValue v = G_VALUE_INIT;
ENTER ("(cm=%p, flag=%d)", cm, flag);
if (!cm)
@ -1315,10 +1321,15 @@ gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
LEAVE("");
return;
}
gnc_commodity_begin_edit(cm);
kvp_frame_set_string(cm->inst.kvp_data,
"auto_quote_control", flag ? NULL : "false");
if (flag)
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);
gnc_commodity_commit_edit(cm);
LEAVE("");
@ -1431,7 +1442,7 @@ void
gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
{
struct lconv *lc;
GValue v = G_VALUE_INIT;
if (!cm) return;
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;
else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
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);
gnc_commodity_commit_edit(cm);

View File

@ -138,7 +138,6 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
{
GNCLot* lot;
LotPrivate* priv;
KvpFrame *frame;
gchar *key;
GValue *temp;
@ -180,7 +179,6 @@ gnc_lot_set_property (GObject* object,
{
GNCLot* lot;
LotPrivate* priv;
KvpFrame *frame;
gchar *key = NULL;
g_return_if_fail(GNC_IS_LOT(object));
@ -436,38 +434,48 @@ gint gnc_lot_count_splits (const GNCLot *lot)
const char *
gnc_lot_get_title (const GNCLot *lot)
{
GValue v = G_VALUE_INIT;
if (!lot) return NULL;
return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
"/title");
qof_instance_get_kvp (QOF_INSTANCE (lot), "/title", &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
}
const char *
gnc_lot_get_notes (const GNCLot *lot)
{
GValue v = G_VALUE_INIT;
if (!lot) return NULL;
return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
"/notes");
qof_instance_get_kvp (QOF_INSTANCE (lot), "/notes", &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
}
void
gnc_lot_set_title (GNCLot *lot, const char *str)
{
GValue v = G_VALUE_INIT;
if (!lot) return;
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));
kvp_frame_set_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
"/title", str);
gnc_lot_commit_edit(lot);
}
void
gnc_lot_set_notes (GNCLot *lot, const char *str)
{
GValue v = G_VALUE_INIT;
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));
kvp_frame_set_string (qof_instance_get_slots (QOF_INSTANCE (lot)),
"/notes", str);
gnc_lot_commit_edit(lot);
}

View File

@ -49,6 +49,38 @@ enum
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 */
G_DEFINE_TYPE(GNCPrice, gnc_price, QOF_TYPE_INSTANCE);
@ -2261,10 +2293,10 @@ unstable_price_traversal(GNCPriceDB *db,
}
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;
GHashTableKVPair *kvpb = (GHashTableKVPair *) b;
HashEntry *he_a = (HashEntry *) a;
HashEntry *he_b = (HashEntry *) b;
gnc_commodity *ca;
gnc_commodity *cb;
int cmp_result;
@ -2274,8 +2306,8 @@ compare_kvpairs_by_commodity_key(gconstpointer a, gconstpointer b)
if (!a) return -1;
if (!b) return 1;
ca = (gnc_commodity *) kvpa->key;
cb = (gnc_commodity *) kvpb->key;
ca = (gnc_commodity *) he_a->key;
cb = (gnc_commodity *) he_b->key;
cmp_result = g_strcmp0(gnc_commodity_get_namespace(ca),
gnc_commodity_get_namespace(cb));
@ -2297,22 +2329,22 @@ stable_price_traversal(GNCPriceDB *db,
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,
compare_kvpairs_by_commodity_key);
compare_hash_entries_by_commodity_key);
for (i = currency_hashes; i; i = i->next)
{
GHashTableKVPair *kv_pair = (GHashTableKVPair *) i->data;
GHashTable *currency_hash = (GHashTable *) kv_pair->value;
GSList *price_lists = g_hash_table_key_value_pairs(currency_hash);
HashEntry *entry = (HashEntry *) i->data;
GHashTable *currency_hash = (GHashTable *) entry->value;
GSList *price_lists = hash_table_to_list(currency_hash);
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)
{
GHashTableKVPair *pricelist_kvp = (GHashTableKVPair *) j->data;
GList *price_list = (GList *) pricelist_kvp->value;
HashEntry *pricelist_entry = (HashEntry *) j->data;
GList *price_list = (GList *) pricelist_entry->value;
GList *node;
for (node = (GList *) price_list; node; node = node->next)
@ -2326,7 +2358,7 @@ stable_price_traversal(GNCPriceDB *db,
}
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);
price_lists = NULL;
}
@ -2334,7 +2366,7 @@ stable_price_traversal(GNCPriceDB *db,
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);
}
return ok;

View File

@ -495,7 +495,7 @@ static void address_free (QofInstance *inst)
void gncAddressCommitEdit (GncAddress *addr)
{
/* 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);
if (!qof_commit_edit (QOF_INSTANCE(addr))) return;

View File

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

View File

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

View File

@ -314,16 +314,15 @@ void gncJobSetRate (GncJob *job, gnc_numeric rate)
gncJobBeginEdit (job);
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
{
KvpFrame *frame;
KvpValue *value;
value = NULL;
frame = kvp_frame_set_value_nc (job->inst.kvp_data,
GNC_JOB_RATE, value);
if (!frame) kvp_value_delete (value);
qof_instance_set_kvp (QOF_INSTANCE (job), GNC_JOB_RATE, NULL);
}
mark_job (job);
gncJobCommitEdit (job);
@ -423,7 +422,7 @@ static void gncJobOnDone (QofInstance *qof) { }
void gncJobCommitEdit (GncJob *job)
{
/* 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);
if (!qof_commit_edit (QOF_INSTANCE(job))) return;
@ -454,8 +453,15 @@ const char * gncJobGetReference (const GncJob *job)
gnc_numeric gncJobGetRate (const GncJob *job)
{
GValue v = G_VALUE_INIT;
gnc_numeric *rate = NULL;
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)

View File

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

View File

@ -1,13 +1,19 @@
#include <libguile.h>
extern "C"
{
#include "config.h"
#include "qof.h"
#include <libguile.h>
#include <qof.h>
#include "engine-helpers-guile.h"
#include "kvp-scm.h"
#include "guile-mappings.h"
#include "gnc-guile-utils.h"
#include "swig-runtime.h"
#include "kvp-scm.h"
}
#include <kvp_frame.hpp>
/* NOTE: There are some problems with this approach. Currently,
* 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 */
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
{
return kvp_value_new_double(scm_to_double(val));
return new KvpValue{scm_to_double(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))
{
GncGUID tmpguid = gnc_scm2guid(val);
return kvp_value_new_guid(&tmpguid);
auto guid = gnc_scm2guid(val);
auto tmpguid = guid_copy(&guid);
return new KvpValue{tmpguid};
}
else if (gnc_timepair_p(val))
{
Timespec ts = gnc_timepair2timespec(val);
return kvp_value_new_timespec(ts);
return new KvpValue{ts};
}
else if (scm_is_string(val))
{
gchar *newstr;
KvpValue *ret;
newstr = gnc_scm_to_utf8_string (val);
ret = kvp_value_new_string(newstr);
g_free (newstr);
return ret;
return new KvpValue{gnc_scm_to_utf8_string(val)};
}
else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame")))
{
#define FUNC_NAME G_STRFUNC
KvpFrame *frame = SWIG_MustGetPtr(val, SWIG_TypeQuery("_p_KvpFrame"),
1, 0);
auto vp_frame = SWIG_MustGetPtr(val,
SWIG_TypeQuery("_p_KvpFrame"), 1, 0);
KvpFrame *frame = static_cast<KvpFrame*>(vp_frame);
#undef FUNC_NAME
return kvp_value_new_frame (frame);
return new KvpValue{frame};
}
/* FIXME: add list handler here */
return NULL;
@ -69,52 +72,49 @@ gnc_scm_to_kvp_value_ptr(SCM val)
SCM
gnc_kvp_value_ptr_to_scm(KvpValue* val)
{
const gchar *string;
switch (kvp_value_get_type(val))
if (val == nullptr) return SCM_BOOL_F;
switch (val->get_type())
{
case KVP_TYPE_GINT64:
return scm_from_int64(kvp_value_get_gint64(val));
case KvpValue::Type::INT64:
return scm_from_int64(val->get<int64_t>());
break;
case KVP_TYPE_DOUBLE:
return scm_from_double (kvp_value_get_double(val));
case KvpValue::Type::DOUBLE:
return scm_from_double (val->get<double>());
break;
case KVP_TYPE_NUMERIC:
return gnc_numeric_to_scm(kvp_value_get_numeric(val));
case KvpValue::Type::NUMERIC:
return gnc_numeric_to_scm(val->get<gnc_numeric>());
break;
case KVP_TYPE_STRING:
string = kvp_value_get_string(val);
case KvpValue::Type::STRING:
{
auto string = val->get<const char*>();
return string ? scm_from_utf8_string(string) : SCM_BOOL_F;
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);
}
break;
case KVP_TYPE_TIMESPEC:
return gnc_timespec2timepair(kvp_value_get_timespec(val));
case KvpValue::Type::TIMESPEC:
return gnc_timespec2timepair(val->get<Timespec>());
break;
case KVP_TYPE_FRAME:
case KvpValue::Type::FRAME:
{
KvpFrame *frame = kvp_value_get_frame(val);
if (frame)
auto frame = val->get<KvpFrame*>();
if (frame != nullptr)
return SWIG_NewPointerObj(frame, SWIG_TypeQuery("_p_KvpFrame"), 0);
}
break;
case KVP_TYPE_GDATE:
return gnc_timespec2timepair(gdate_to_timespec(kvp_value_get_gdate(val)));
case KvpValue::Type::GDATE:
return gnc_timespec2timepair(gdate_to_timespec(val->get<GDate>()));
/* FIXME: handle types below */
case KVP_TYPE_GLIST:
case KvpValue::Type::GLIST:
default:
break;
}
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
#define KVP_SCM_H
#include "qof.h"
#ifdef __cplusplus
extern "C"
{
#endif
#include <qof.h>
#include <libguile.h>
KvpValue* gnc_scm_to_kvp_value_ptr(SCM kvpval);
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 */

View File

@ -16,7 +16,7 @@ Name: The name of the key, including key names of parent frames
filename. Use the '/' character to separate keys.
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)
can use this key. Use 'All' if every entity could have

View File

@ -6,7 +6,7 @@ LDADD = \
${top_builddir}/src/libqof/qof/libgnc-qof.la \
${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_LIBADD = \
${top_builddir}/src/gnc-module/libgnc-module.la \

View File

@ -15,6 +15,10 @@
* Created by Linux Developers Group, 2001
* Updates Linas Vepstas July 2004
*/
#include <kvp_frame.hpp>
extern "C"
{
#include "config.h"
#include <sys/types.h>
@ -28,6 +32,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <qof.h>
#include <qofinstance-p.h>
#include "Account.h"
@ -43,6 +48,7 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"
#include "test-engine-strings.h"
}
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);
}
void
kvp_exclude_type (KvpValueType kvp_type)
static void
kvp_exclude_type (KvpValue::Type kvp_type)
{
gint *key;
@ -114,7 +120,7 @@ kvp_exclude_type (KvpValueType kvp_type)
}
static gboolean
kvp_type_excluded (KvpValueType kvp_type)
kvp_type_excluded (KvpValue::Type kvp_type)
{
gint key = kvp_type;
@ -127,12 +133,6 @@ kvp_type_excluded (KvpValueType kvp_type)
return FALSE;
}
void
random_glist_strings_only (gboolean strings_only)
{
glist_strings_only = strings_only;
}
static gboolean zero_nsec = FALSE;
void
@ -188,14 +188,11 @@ get_random_glist_depth (gint depth)
for (i = 0; i < count; i++)
{
KvpValueType kvpt;
KvpValue *value;
kvpt = glist_strings_only ? KVP_TYPE_STRING : -2;
KvpValue *value = nullptr;
do
{
value = get_random_kvp_value_depth (kvpt, depth + 1);
value = get_random_kvp_value_depth (-2, depth + 1);
}
while (!value);
@ -205,12 +202,6 @@ get_random_glist_depth (gint depth)
return ret;
}
GList*
get_random_glist(void)
{
return get_random_glist_depth (0);
}
/* ========================================================== */
/* Time/Date, GncGUID data stuff */
@ -247,23 +238,25 @@ static KvpFrame* get_random_kvp_frame_depth (gint depth);
static KvpValue*
get_random_kvp_value_depth (int type, gint depth)
{
int datype = type;
KvpValue::Type datype;
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;
if (datype == KVP_TYPE_GLIST && depth >= kvp_max_depth)
if (datype == KvpValue::Type::GLIST && depth >= kvp_max_depth)
return NULL;
if (kvp_type_excluded (datype))
@ -271,57 +264,50 @@ get_random_kvp_value_depth (int type, gint depth)
switch (datype)
{
case KVP_TYPE_GINT64:
ret = kvp_value_new_gint64(get_random_gint64());
case KvpValue::Type::INT64:
ret = new KvpValue(get_random_gint64());
break;
case KVP_TYPE_DOUBLE:
case KvpValue::Type::DOUBLE:
ret = NULL;
break;
case KVP_TYPE_NUMERIC:
ret = kvp_value_new_gnc_numeric(get_random_gnc_numeric(GNC_DENOM_AUTO));
case KvpValue::Type::NUMERIC:
ret = new KvpValue(get_random_gnc_numeric(GNC_DENOM_AUTO));
break;
case KVP_TYPE_STRING:
case KvpValue::Type::STRING:
{
gchar *tmp_str;
tmp_str = get_random_string();
if (!tmp_str)
return NULL;
ret = kvp_value_new_string(tmp_str);
g_free(tmp_str);
ret = new KvpValue(tmp_str);
}
break;
case KVP_TYPE_GUID:
case KvpValue::Type::GUID:
{
GncGUID *tmp_guid;
tmp_guid = get_random_guid();
ret = kvp_value_new_guid(tmp_guid);
g_free(tmp_guid);
return new KvpValue(get_random_guid());
}
break;
case KVP_TYPE_TIMESPEC:
case KvpValue::Type::TIMESPEC:
{
Timespec *ts = get_random_timespec();
ret = kvp_value_new_timespec (*ts);
ret = new KvpValue(*ts);
g_free(ts);
}
break;
case KVP_TYPE_GLIST:
ret = kvp_value_new_glist_nc(get_random_glist_depth (depth + 1));
case KvpValue::Type::GLIST:
ret = new KvpValue(get_random_glist_depth (depth + 1));
break;
case KVP_TYPE_FRAME:
case KvpValue::Type::FRAME:
{
KvpFrame *tmp_frame;
tmp_frame = get_random_kvp_frame_depth(depth + 1);
ret = kvp_value_new_frame(tmp_frame);
kvp_frame_delete(tmp_frame);
return new KvpValue(get_random_kvp_frame_depth(depth + 1));
}
break;
@ -335,14 +321,13 @@ get_random_kvp_value_depth (int type, gint depth)
static KvpFrame*
get_random_kvp_frame_depth (gint depth)
{
KvpFrame *ret;
int vals_to_add;
gboolean val_added;
if (depth >= kvp_max_depth)
return NULL;
ret = kvp_frame_new();
auto ret = new KvpFrame;
vals_to_add = get_random_int_in_range(1, kvp_frame_max_elements);
val_added = FALSE;
@ -374,7 +359,7 @@ get_random_kvp_frame_depth (gint depth)
val_added = TRUE;
kvp_frame_set_slot_nc(ret, key, val);
ret->set_path(key, val);
g_free(key);
}
@ -495,13 +480,13 @@ get_random_commodity_from_table (gnc_commodity_table *table)
GList *commodities;
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);
if (!commodities)
continue;
com = get_random_list_element (commodities);
com = static_cast<gnc_commodity*>(get_random_list_element (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)
{
const char *ns = node->data;
auto ns = static_cast<const char *>(node->data);
GList *commodities;
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)
{
gnc_commodity *com = com_node->data;
auto com = static_cast<gnc_commodity *>(com_node->data);
gnc_commodity_table_remove (table, com);
make_random_changes_to_commodity (com);
@ -747,7 +732,7 @@ get_random_pricedb(QofBook *book)
static gboolean
price_accumulator (GNCPrice *p, gpointer data)
{
GList **list = data;
auto list = static_cast<GList**>(data);
*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)
{
GNCPrice *p = node->data;
auto p = static_cast<GNCPrice *>(node->data);
switch (get_random_int_in_range (0, 5))
{
@ -897,7 +882,6 @@ get_random_account_tree (QofBook *book)
static void
add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
{
Account *acc, *bcc;
Split *s1, *s2;
gnc_numeric val;
int s2_scu;
@ -905,11 +889,11 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
/* Gotta have at least two different accounts */
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);
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()))
{
/* 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? */
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);
for (node = splits; node; node = node->next)
{
Split *split = node->data;
Account *account;
account = get_random_list_element (accounts);
auto split = static_cast<Split *>(node->data);
auto account = static_cast<Account*>(get_random_list_element (accounts));
xaccAccountInsertSplit (account, split);
}
@ -1021,7 +1003,7 @@ make_random_changes_to_transaction_and_splits (QofBook *book,
splits = xaccTransGetSplitList (trans);
for (node = splits; node; node = node->next)
{
Split *split = node->data;
auto split = static_cast<Split *>(node->data);
if (get_random_boolean ())
make_random_changes_to_split (split);
@ -1037,7 +1019,7 @@ static int
add_trans_helper (Transaction *trans, gpointer data)
{
TransInfo *ti;
GList **list = data;
auto list = static_cast<GList **>(data);
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);
else
{
account = get_random_list_element (accounts);
account = static_cast<Account*>(get_random_list_element (accounts));
gnc_account_append_child (account, new_account);
}
@ -1082,7 +1064,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
/* Mess with the accounts */
for (node = accounts; node; node = node->next)
{
Account *account = node->data;
auto account = static_cast<Account *>(node->data);
if (get_random_boolean ())
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)
{
TransInfo *ti = node->data;
auto ti = static_cast<TransInfo *>(node->data);
Transaction *trans = xaccTransLookup (&ti->guid, book);
if (!trans)
@ -1105,7 +1087,7 @@ make_random_changes_to_level (QofBook *book, Account *parent)
for (node = transes; node; node = node->next)
{
TransInfo *ti = node->data;
auto ti = static_cast<TransInfo *>(node->data);
g_free (ti);
}
@ -1113,18 +1095,18 @@ make_random_changes_to_level (QofBook *book, Account *parent)
transes = NULL;
/* delete an account */
account = get_random_list_element (accounts);
account = static_cast<Account*>(get_random_list_element (accounts));
splits = xaccAccountGetSplitList (account);
splits = g_list_copy (splits);
for (node = splits; node; node = node->next)
{
Split *split = node->data;
auto split = static_cast<Split *>(node->data);
do
{
new_account = get_random_list_element (accounts);
new_account = static_cast<Account*>(get_random_list_element (accounts));
}
while (new_account == account);
@ -1146,12 +1128,12 @@ make_random_changes_to_level (QofBook *book, Account *parent)
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 ())
a2 = get_random_list_element (accounts);
a2 = static_cast<Account*>(get_random_list_element (accounts));
else
a2 = NULL;
@ -1190,7 +1172,7 @@ get_random_account(QofBook *book)
sane_account_names);
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, xaccAccountSetDescription);
@ -1223,7 +1205,7 @@ make_random_changes_to_account (QofBook *book, Account *account)
set_account_random_string (account, xaccAccountSetName);
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, xaccAccountSetDescription);
@ -1386,7 +1368,7 @@ set_tran_random_string(Transaction* trn,
void(*func)(Transaction *act, const gchar*str))
{
gchar *tmp_str = get_random_string();
if (!trn || !(&trn->inst))
if (!trn)
{
return;
}
@ -1464,7 +1446,7 @@ get_random_transaction_with_currency(QofBook *book,
trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS);
f = get_random_kvp_frame();
xaccTransSetSlots_nc(trans, f);
qof_instance_set_slots (QOF_INSTANCE (trans), f);
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);
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 */
@ -1659,7 +1641,7 @@ set_query_sort (QofQuery *q, sort_type_t sort_code)
{
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)
{
@ -1667,36 +1649,36 @@ set_query_sort (QofQuery *q, sort_type_t sort_code)
p1 = standard;
break;
case BY_DATE:
p1 = g_slist_prepend (p1, TRANS_DATE_POSTED);
p1 = g_slist_prepend (p1, SPLIT_TRANS);
p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DATE_POSTED));
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard;
break;
case BY_DATE_ENTERED:
p1 = g_slist_prepend (p1, TRANS_DATE_ENTERED);
p1 = g_slist_prepend (p1, SPLIT_TRANS);
p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DATE_ENTERED));
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard;
break;
case BY_DATE_RECONCILED:
p1 = g_slist_prepend (p1, SPLIT_RECONCILE);
p2 = g_slist_prepend (p2, SPLIT_DATE_RECONCILED);
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_RECONCILE));
p2 = g_slist_prepend (p2, const_cast<char*>(SPLIT_DATE_RECONCILED));
p3 = standard;
break;
case BY_NUM:
p1 = g_slist_prepend (p1, TRANS_NUM);
p1 = g_slist_prepend (p1, SPLIT_TRANS);
p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_NUM));
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard;
break;
case BY_AMOUNT:
p1 = g_slist_prepend (p1, SPLIT_VALUE);
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_VALUE));
p2 = standard;
break;
case BY_MEMO:
p1 = g_slist_prepend (p1, SPLIT_MEMO);
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_MEMO));
p2 = standard;
break;
case BY_DESC:
p1 = g_slist_prepend (p1, TRANS_DESCRIPTION);
p1 = g_slist_prepend (p1, SPLIT_TRANS);
p1 = g_slist_prepend (p1, const_cast<char*>(TRANS_DESCRIPTION));
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
p2 = standard;
break;
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);
}
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 *
get_random_query(void)
{
@ -1743,7 +1732,7 @@ get_random_query(void)
xaccQueryAddAccountGUIDMatch
(q,
guids,
get_random_int_in_range (1, QOF_GUID_MATCH_NONE),
compare_param<QofGuidMatch>(QOF_GUID_MATCH_NONE),
get_random_queryop ());
free_random_guids (guids);
break;
@ -1754,7 +1743,7 @@ get_random_query(void)
string,
get_random_boolean (),
get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ());
g_free (string);
break;
@ -1762,19 +1751,19 @@ get_random_query(void)
case 3: /* PR_BALANCE */
xaccQueryAddBalanceMatch
(q,
get_random_boolean (),
compare_param<QofQueryCompare> (1),
get_random_queryop ());
break;
case 4: /* PR_CLEARED */
xaccQueryAddClearedMatch
(q,
get_random_int_in_range (1,
static_cast<cleared_match_t>(get_random_int_in_range (1,
CLEARED_NO |
CLEARED_CLEARED |
CLEARED_RECONCILED |
CLEARED_FROZEN |
CLEARED_VOIDED),
CLEARED_VOIDED)),
get_random_queryop ());
break;
@ -1797,7 +1786,7 @@ get_random_query(void)
string,
get_random_boolean (),
get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ());
g_free (string);
break;
@ -1812,20 +1801,6 @@ get_random_query(void)
break;
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;
case 9: /* PR_MEMO */
@ -1834,7 +1809,7 @@ get_random_query(void)
string,
get_random_boolean (),
get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ());
g_free (string);
break;
@ -1845,7 +1820,7 @@ get_random_query(void)
string,
get_random_boolean (),
get_random_boolean (),
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
compare_param<QofQueryCompare>(QOF_COMPARE_CONTAINS),
get_random_queryop ());
g_free (string);
break;
@ -1854,7 +1829,7 @@ get_random_query(void)
xaccQueryAddSharePriceMatch
(q,
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 ());
break;
@ -1862,7 +1837,7 @@ get_random_query(void)
xaccQueryAddSharesMatch
(q,
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 ());
break;
@ -1870,8 +1845,8 @@ get_random_query(void)
xaccQueryAddValueMatch
(q,
get_random_gnc_numeric (GNC_DENOM_AUTO),
get_random_int_in_range (1, QOF_NUMERIC_MATCH_ANY),
get_random_int_in_range (1, QOF_COMPARE_NEQ),
compare_param<QofNumericMatch> (QOF_NUMERIC_MATCH_ANY),
compare_param<QofQueryCompare> (QOF_COMPARE_NEQ),
get_random_queryop ());
break;
@ -1883,7 +1858,7 @@ get_random_query(void)
}
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,
get_random_boolean (),
@ -1977,39 +1952,6 @@ typedef struct
QofQuery *q;
} 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;
void
@ -2021,17 +1963,11 @@ trans_query_include_price (gboolean include_price_in)
TestQueryTypes
get_random_query_type (void)
{
switch (get_random_int_in_range (0, 4))
switch (get_random_int_in_range (0, 1))
{
case 0:
return SIMPLE_QT;
case 1:
return SPLIT_KVP_QT;
case 2:
return TRANS_KVP_QT;
case 3:
return ACCOUNT_KVP_QT;
case 4:
return GUID_QT;
default:
return SIMPLE_QT;
@ -2140,7 +2076,7 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
list = NULL;
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));
}
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);
}
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;
}

View File

@ -4,7 +4,10 @@
#ifndef TEST_ENGINE_STUFF_H
#define TEST_ENGINE_STUFF_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <glib.h>
#include <stdlib.h>
#include <stdint.h>
@ -14,6 +17,8 @@
#include "gnc-pricedb.h"
#include "SchedXaction.h"
typedef struct KvpValueImpl KvpValue;
typedef struct KvpFrameImpl KvpFrame;
Timespec* get_random_timespec(void);
void random_timespec_zero_nsec (gboolean zero_nsec);
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);
gnc_numeric get_random_gnc_numeric(int64_t);
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_frame_elements (gint max_kvp_frame_elements);
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);
void remove_sx(SchedXaction *sx);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -23,6 +23,8 @@ LDADD = \
${top_builddir}/src/core-utils/libgnc-core-utils.la \
${GLIB_LIBS}
test_guid_SOURCES = test-guid.cpp
# these tests are ordered kind more or less in the order
# 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})
check_PROGRAMS = ${TEST_GROUP_1} ${TEST_GROUP_2}
AM_DEFAULT_SOURCE_EXT = .cpp
TESTS = ${TEST_GROUP_1} test-create-account ${TEST_GROUP_2}
@ -94,7 +97,7 @@ EXTRA_DIST += \
test_engine_SOURCES = \
test-engine.c \
utest-Account.c \
utest-Account.cpp \
utest-Budget.c \
utest-Entry.c \
utest-Invoice.c \
@ -124,10 +127,36 @@ libutest_Split_la_CXXFLAGS = -Wno-write-strings $(AM_CXXFLAGS)
libutest_Split_la_LIBADD = $(LDADD)
libutest_Trans_la_SOURCES = \
utest-Transaction.c
utest-Transaction.cpp
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:
rm -f translog.*

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