From 374443747d33aad60326a748484dfd07ca2e4fcb Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Tue, 14 Sep 2021 07:23:22 +0800 Subject: [PATCH] [account.cpp] new static: get/set_kvp_string_path exactly the same as set_kvp_string_tag but will accept the full kvp path. --- libgnucash/engine/Account.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 39cb5b88e8..f6ac68f381 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2486,7 +2486,8 @@ stripdup_or_null (const char *value) // note the *value argument is expected to be either a strstripped // char* or nullptr, as returned by stripdup_or_null above. static void -set_kvp_string_tag (Account *acc, const char *tag, const char *value) +set_kvp_string_path (Account *acc, std::vector const & path, + const char *value) { g_return_if_fail(GNC_IS_ACCOUNT(acc)); @@ -2496,28 +2497,40 @@ set_kvp_string_tag (Account *acc, const char *tag, const char *value) GValue v = G_VALUE_INIT; g_value_init (&v, G_TYPE_STRING); g_value_set_string (&v, value); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {tag}); + qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); g_value_unset (&v); } else { - qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, {tag}); + qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, path); } mark_account (acc); xaccAccountCommitEdit(acc); } +static void +set_kvp_string_tag (Account *acc, const char *tag, const char *value) +{ + set_kvp_string_path (acc, {tag}, value); +} + static char* -get_kvp_string_tag (const Account *acc, const char *tag) +get_kvp_string_path (const Account *acc, std::vector const & path) { GValue v = G_VALUE_INIT; - if (acc == NULL || tag == NULL) return NULL; - qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, {tag}); + if (acc == NULL) return NULL; // how to check path is valid?? + qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path); auto retval = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL; g_value_unset (&v); return retval; } +static char* +get_kvp_string_tag (const Account *acc, const char *tag) +{ + return get_kvp_string_path (acc, {tag}); +} + void xaccAccountSetColor (Account *acc, const char *str) {