From 5636afc4a298c355a5ffb6f849a21977aba3ac9a Mon Sep 17 00:00:00 2001 From: lmat Date: Mon, 6 Nov 2017 14:51:25 -0500 Subject: [PATCH] Kvp no longer parses entries looking for delimiters --- .../app-utils/test/test-option-util.cpp | 10 +- .../dbi/test/test-backend-dbi-basic.cpp | 14 +- libgnucash/backend/sql/gnc-slots-sql.cpp | 8 +- libgnucash/backend/xml/io-gncxml-v1.cpp | 2 +- libgnucash/backend/xml/sixtp-dom-parsers.cpp | 2 +- .../backend/xml/test/test-kvp-frames.cpp | 6 +- libgnucash/engine/Account.cpp | 12 +- libgnucash/engine/gnc-aqbanking-templates.cpp | 20 +- libgnucash/engine/kvp-frame.cpp | 198 ++++++------------ libgnucash/engine/kvp-frame.hpp | 28 +-- libgnucash/engine/qofbook.cpp | 14 +- libgnucash/engine/qofinstance-p.h | 5 +- libgnucash/engine/qofinstance.cpp | 26 +-- .../engine/test-core/test-engine-stuff.cpp | 2 +- libgnucash/engine/test/gtest-import-map.cpp | 62 +++--- libgnucash/engine/test/test-kvp-frame.cpp | 70 +++---- libgnucash/engine/test/utest-Split.cpp | 22 +- libgnucash/engine/test/utest-Transaction.cpp | 34 +-- 18 files changed, 212 insertions(+), 323 deletions(-) diff --git a/libgnucash/app-utils/test/test-option-util.cpp b/libgnucash/app-utils/test/test-option-util.cpp index fd560fe55a..4c7d358b44 100644 --- a/libgnucash/app-utils/test/test-option-util.cpp +++ b/libgnucash/app-utils/test/test-option-util.cpp @@ -69,7 +69,7 @@ setup_kvp (Fixture *fixture, gconstpointer pData) "autoreadonly-days", (double)21, NULL); - slots->set_path("options/Business/Company Name", + slots->set_path({"options", "Business", "Company Name"}, new KvpValue("Bogus Company")); qof_commit_edit (QOF_INSTANCE (book)); } @@ -120,10 +120,10 @@ test_option_save (Fixture *fixture, gconstpointer pData) OPTION_NAME_AUTO_READONLY_DAYS, 17)); qof_book_save_options (book, gnc_option_db_save, odb, TRUE); - g_assert_cmpstr (slots->get_slot("options/Accounts/Use Trading Accounts")->get(), == , "t"); - g_assert_cmpstr (slots->get_slot("options/Accounts/Use Split Action Field for Number")->get(), == , "t"); - g_assert_cmpstr (slots->get_slot("options/Business/Company Name")->get(), ==, "Bogus Company"); - g_assert_cmpfloat (slots->get_slot("options/Accounts/Day Threshold for Read-Only Transactions (red line)")->get(), ==, 17); + g_assert_cmpstr (slots->get_slot({"options", "Accounts", "Use Trading Accounts"})->get(), == , "t"); + g_assert_cmpstr (slots->get_slot({"options", "Accounts", "Use Split Action Field for Number"})->get(), == , "t"); + g_assert_cmpstr (slots->get_slot({"options", "Business", "Company Name"})->get(), ==, "Bogus Company"); + g_assert_cmpfloat (slots->get_slot({"options", "Accounts", "Day Threshold for Read-Only Transactions (red line)"})->get(), ==, 17); gnc_option_db_destroy (odb); } diff --git a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp index 245ca9553c..8c0d75eb84 100644 --- a/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp +++ b/libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp @@ -132,15 +132,13 @@ setup_memory (Fixture* fixture, gconstpointer pData) xaccAccountSetCommodity (acct1, currency); 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 ())); - - frame->set ("timespec-val", new KvpValue (timespec_now ())); - - frame->set ("string-val", new KvpValue ("abcdefghijklmnop")); + 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 ())); + frame->set ({"timespec-val"}, new KvpValue (timespec_now ())); + frame->set ({"string-val"}, new KvpValue ("abcdefghijklmnop")); auto guid = qof_instance_get_guid (QOF_INSTANCE (acct1)); - frame->set ("guid-val", new KvpValue (const_cast (guid_copy ( + frame->set ({"guid-val"}, new KvpValue (const_cast (guid_copy ( guid)))); gnc_account_append_child (root, acct1); diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp index 30563a5a29..c8b36ff3a2 100644 --- a/libgnucash/backend/sql/gnc-slots-sql.cpp +++ b/libgnucash/backend/sql/gnc-slots-sql.cpp @@ -226,7 +226,7 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue) case FRAME: { auto key = get_key_from_path (pInfo->path); - pInfo->pKvpFrame->set (key.c_str(), pValue); + pInfo->pKvpFrame->set ({key.c_str()}, pValue); break; } case LIST: @@ -245,7 +245,7 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue) frame->set_path ({path.c_str(), key.c_str()}, pValue); } else - frame->set (key.c_str(), pValue); + frame->set ({key.c_str()}, pValue); break; } } @@ -464,7 +464,7 @@ set_guid_val (gpointer pObject, gpointer pValue) slots_load_info (newInfo); pValue = new KvpValue {newInfo->pList}; - pInfo->pKvpFrame->set (key.c_str(), pValue); + pInfo->pKvpFrame->set ({key.c_str()}, pValue); delete newInfo; break; } @@ -487,7 +487,7 @@ set_guid_val (gpointer pObject, gpointer pValue) default: { auto key = get_key_from_path (pInfo->path); - pInfo->pKvpFrame->set (key.c_str(), new KvpValue {newFrame}); + pInfo->pKvpFrame->set ({key.c_str()}, new KvpValue {newFrame}); break; } } diff --git a/libgnucash/backend/xml/io-gncxml-v1.cpp b/libgnucash/backend/xml/io-gncxml-v1.cpp index df50648e58..53d6039ea4 100644 --- a/libgnucash/backend/xml/io-gncxml-v1.cpp +++ b/libgnucash/backend/xml/io-gncxml-v1.cpp @@ -808,7 +808,7 @@ kvp_frame_slot_end_handler (gpointer data_for_children, if (key_node_count != 1) return (FALSE); value_cr->should_cleanup = TRUE; - f->set (key, value); + f->set ({key}, value); if (delete_value) delete value; return (TRUE); diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp index af4b197f97..fa0dca10e4 100644 --- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp +++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp @@ -440,7 +440,7 @@ dom_tree_to_kvp_frame_given (xmlNodePtr node, KvpFrame* frame) if (val) { //We're deleting the old KvpValue returned by replace_nc(). - delete frame->set (key, val); + delete frame->set ({key}, val); } else { diff --git a/libgnucash/backend/xml/test/test-kvp-frames.cpp b/libgnucash/backend/xml/test/test-kvp-frames.cpp index b9736ce4e2..508d60020c 100644 --- a/libgnucash/backend/xml/test/test-kvp-frames.cpp +++ b/libgnucash/backend/xml/test/test-kvp-frames.cpp @@ -25,7 +25,7 @@ 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 test_val2 = test_frame1->get_slot ({test_key}); auto msg = "KvpFrame::get_slot"; if (compare (test_val1, test_val2) == 0) { @@ -70,7 +70,7 @@ test_kvp_copy_get_slot (int run, const gchar* test_key) { auto test_frame2 = new KvpFrame (*test_frame1); - auto test_val2 = test_frame2->get_slot (test_key); + 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) { @@ -114,7 +114,7 @@ test_kvp_frames1 (void) auto test_frame1 = new KvpFrame; auto test_key = get_random_string_without ("/"); - test_frame1->set (test_key, test_val1); + 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); diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 1208425b37..3ee7882d48 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -5440,7 +5440,7 @@ parse_bayes_imap_info (std::string const & imap_bayes_entry) auto guid_start = imap_bayes_entry.size() - GUID_ENCODING_LENGTH; std::string keyword {imap_bayes_entry.substr (header_length + 1, guid_start - header_length - 2)}; std::string account_guid {imap_bayes_entry.substr (guid_start)}; - return {header, keyword, account_guid}; + return std::tuple {header, keyword, account_guid}; } static void @@ -5530,9 +5530,9 @@ gnc_account_delete_map_entry (Account *acc, char *full_category, gboolean empty) { xaccAccountBeginEdit (acc); if (empty) - qof_instance_slot_delete_if_empty (QOF_INSTANCE(acc), kvp_path); + qof_instance_slot_path_delete_if_empty (QOF_INSTANCE(acc), {kvp_path}); else - qof_instance_slot_delete (QOF_INSTANCE(acc), kvp_path); + qof_instance_slot_path_delete (QOF_INSTANCE(acc), {kvp_path}); PINFO("Account is '%s', path is '%s'", xaccAccountGetName (acc), kvp_path); qof_instance_set_dirty (QOF_INSTANCE(acc)); xaccAccountCommitEdit (acc); @@ -5620,7 +5620,7 @@ static std::vector> get_new_guid_imap (Account * acc) { auto frame = qof_instance_get_slots (QOF_INSTANCE (acc)); - auto slot = frame->get_slot (IMAP_FRAME_BAYES); + auto slot = frame->get_slot ({IMAP_FRAME_BAYES}); if (!slot) return {}; auto imap_frame = slot->get (); @@ -5640,9 +5640,9 @@ convert_imap_account_bayes_to_guid (Account *acc) return; auto new_imap = get_new_guid_imap(acc); xaccAccountBeginEdit(acc); - frame->set(IMAP_FRAME_BAYES, nullptr); + frame->set({IMAP_FRAME_BAYES}, nullptr); std::for_each(new_imap.begin(), new_imap.end(), [&frame] (std::pair const & entry) { - frame->set(entry.first.c_str(), entry.second); + frame->set({entry.first.c_str()}, entry.second); }); qof_instance_set_dirty (QOF_INSTANCE (acc)); xaccAccountCommitEdit(acc); diff --git a/libgnucash/engine/gnc-aqbanking-templates.cpp b/libgnucash/engine/gnc-aqbanking-templates.cpp index fe2c37d831..ad6b8fda0a 100644 --- a/libgnucash/engine/gnc-aqbanking-templates.cpp +++ b/libgnucash/engine/gnc-aqbanking-templates.cpp @@ -106,13 +106,13 @@ KvpFrame* _GncABTransTempl::make_kvp_frame() { auto frame = new KvpFrame; - frame->set(TT_NAME, new KvpValue(m_name.c_str())); - frame->set(TT_RNAME, new KvpValue(m_recipient_name.c_str())); - frame->set(TT_RACC, new KvpValue(m_recipient_account.c_str())); - frame->set(TT_RBCODE, new KvpValue(m_recipient_bankcode.c_str())); - frame->set(TT_AMOUNT, new KvpValue(m_amount)); - frame->set(TT_PURPOS, new KvpValue(m_purpose.c_str())); - frame->set(TT_PURPOSCT, new KvpValue(m_purpose_continuation.c_str())); + frame->set({TT_NAME}, new KvpValue(m_name.c_str())); + frame->set({TT_RNAME}, new KvpValue(m_recipient_name.c_str())); + frame->set({TT_RACC}, new KvpValue(m_recipient_account.c_str())); + frame->set({TT_RBCODE}, new KvpValue(m_recipient_bankcode.c_str())); + frame->set({TT_AMOUNT}, new KvpValue(m_amount)); + frame->set({TT_PURPOS}, new KvpValue(m_purpose.c_str())); + frame->set({TT_PURPOSCT}, new KvpValue(m_purpose_continuation.c_str())); return frame; } @@ -145,12 +145,12 @@ gnc_ab_trans_templ_list_new_from_book(QofBook *b) { KvpFrame *frame = static_cast(node->data)->get(); auto c_func = [frame](const char* key) - { auto slot = frame->get_slot(key); + { auto slot = frame->get_slot({key}); return slot == nullptr ? std::string("") : std::string(slot->get());}; auto n_func = [frame](const char* key) - { auto slot = frame->get_slot(key); + { auto slot = frame->get_slot({key}); return slot == nullptr ? gnc_numeric_zero() : slot->get();}; - auto amt_slot = frame->get_slot(TT_AMOUNT); + auto amt_slot = frame->get_slot({TT_AMOUNT}); auto templ = new _GncABTransTempl (c_func(TT_NAME), c_func(TT_RNAME), c_func(TT_RACC), c_func(TT_RBCODE), n_func(TT_AMOUNT), c_func(TT_PURPOS), diff --git a/libgnucash/engine/kvp-frame.cpp b/libgnucash/engine/kvp-frame.cpp index eff478ad7c..9687cc125b 100644 --- a/libgnucash/engine/kvp-frame.cpp +++ b/libgnucash/engine/kvp-frame.cpp @@ -68,124 +68,90 @@ KvpFrameImpl::~KvpFrameImpl() noexcept m_valuemap.clear(); } -static inline Path -make_vector(std::string key) +KvpFrame * +KvpFrame::get_child_frame_or_nullptr (Path const & path) noexcept { - Path path; - for (auto length = key.find(delim); length != std::string::npos;) - { - if (length != 0) - path.push_back(key.substr(0, length)); - key = key.substr(length + 1); - length = key.find(delim); - } - if (!key.empty()) - path.push_back(key); - return path; + if (!path.size ()) + return this; + auto key = path.front (); + if (m_valuemap.find (key.c_str ()) == m_valuemap.end ()) + return nullptr; + auto child = m_valuemap.at (key.c_str ())->get (); + Path send; + std::copy (path.begin () + 1, path.end (), std::back_inserter (send)); + return child->get_child_frame_or_nullptr (send); } -/* - * If the key is delimited, calls set(path) with the parsed result - * otherwise, inserts the key and value locally and returns the - * old value if there was one. - */ -KvpValue* -KvpFrameImpl::set(const char* key, KvpValue* value) noexcept +KvpFrame * +KvpFrame::get_child_frame_or_create (Path const & path) noexcept { - if (!key) return nullptr; - if (strchr(key, delim)) - return set(make_vector(key), value); - KvpValue* ret {nullptr}; - auto spot = m_valuemap.find(key); - if (spot != m_valuemap.end()) - { - qof_string_cache_remove(spot->first); - ret = spot->second; - m_valuemap.erase(spot); - } + if (!path.size ()) + return this; + auto key = path.front (); + auto spot = m_valuemap.find (key.c_str ()); + if (spot == m_valuemap.end () || spot->second->get_type () != KvpValue::Type::FRAME) + delete set_impl (key.c_str (), new KvpValue {new KvpFrame}); + Path send; + std::copy (path.begin () + 1, path.end (), std::back_inserter (send)); + auto child_val = m_valuemap.at (key.c_str ()); + auto child = child_val->get (); + return child->get_child_frame_or_create (send); +} + +KvpValue * +KvpFrame::set_impl (std::string const & key, KvpValue * value) noexcept +{ + KvpValue * ret {}; + auto spot = m_valuemap.find (key.c_str ()); + if (spot != m_valuemap.end ()) + { + qof_string_cache_remove (spot->first); + ret = spot->second; + m_valuemap.erase (spot); + } if (value) { - auto cachedkey = - static_cast(qof_string_cache_insert(key)); - m_valuemap.insert({cachedkey,value}); + auto cachedkey = static_cast (qof_string_cache_insert (key.c_str ())); + m_valuemap.emplace (cachedkey, value); } - return ret; } -static inline KvpFrameImpl* -walk_path_or_nullptr(const KvpFrameImpl* frame, Path& path) +KvpValue * +KvpFrameImpl::set (Path path, KvpValue* value) noexcept { - KvpFrameImpl* cur_frame = const_cast(frame); - for(auto key:path) - { - auto slot = cur_frame->get_slot(key.c_str()); - if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) - return nullptr; - cur_frame = slot->get(); - } - return cur_frame; -} - -/* - * If the last path parameter has a delimiter, the path before that point is ignored, - * and set is called with only the last parameter with the delimiter as the key. - */ -KvpValue* -KvpFrameImpl::set(Path path, KvpValue* value) noexcept -{ - auto last_key = path.back(); - path.pop_back(); - auto cur_frame = walk_path_or_nullptr(this, path); - if (cur_frame == nullptr) + auto key = path.back (); + path.pop_back (); + auto target = get_child_frame_or_nullptr (path); + if (!target) return nullptr; - if (last_key.find(delim) != std::string::npos) - return set(make_vector(last_key), value); - return cur_frame->set(last_key.c_str(), value); + return target->set_impl (key, value); } -static inline KvpFrameImpl* -walk_path_and_create(KvpFrameImpl* frame, Path path) +KvpValue * +KvpFrameImpl::set_path (Path path, KvpValue* value) noexcept { - for(auto key:path) - { - if (key.empty()) - continue; - if (key.find(delim) != std::string::npos) - { - frame = walk_path_and_create(frame, make_vector(key)); - continue; - } - auto slot = frame->get_slot(key.c_str()); - if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) - { - auto new_frame = new KvpFrame; - delete frame->set(key.c_str(), new KvpValue{new_frame}); - frame = new_frame; - continue; - } - frame = slot->get(); - } - return frame; -} - -KvpValue* -KvpFrameImpl::set_path(const char* path, KvpValue* value) noexcept -{ - return set_path(make_vector(path), value); -} - -KvpValue* -KvpFrameImpl::set_path(Path path, KvpValue* value) noexcept -{ - auto cur_frame = this; - auto last_key = path.back(); + auto key = path.back(); path.pop_back(); - cur_frame = walk_path_and_create(const_cast(this), path); - if (last_key.find(delim) != std::string::npos) - return set_path(make_vector(last_key), value); - return cur_frame->set(last_key.c_str(), value); + auto target = get_child_frame_or_create (path); + if (!target) + return nullptr; + return target->set_impl (key, value); +} + +KvpValue * +KvpFrameImpl::get_slot (Path path) noexcept +{ + auto key = path.back(); + path.pop_back(); + auto target = get_child_frame_or_nullptr (path); + if (!target) + return nullptr; + auto spot = target->m_valuemap.find (key.c_str ()); + if (spot != target->m_valuemap.end ()) + return spot->second; + return nullptr; } std::string @@ -231,32 +197,6 @@ KvpFrameImpl::get_keys() const noexcept return ret; } -KvpValueImpl * -KvpFrameImpl::get_slot(const char * key) const noexcept -{ - if (!key) return nullptr; - if (strchr(key, delim)) - return get_slot(make_vector(key)); - auto spot = m_valuemap.find(key); - if (spot == m_valuemap.end()) - return nullptr; - return spot->second; -} - -KvpValueImpl * -KvpFrameImpl::get_slot(Path path) const noexcept -{ - auto last_key = path.back(); - path.pop_back(); - auto cur_frame = walk_path_or_nullptr(this, path); - if (cur_frame == nullptr) - return nullptr; - if (last_key.find(delim) != std::string::npos) - return get_slot(make_vector(last_key)); - return cur_frame->get_slot(last_key.c_str()); - -} - int compare(const KvpFrameImpl * one, const KvpFrameImpl * two) noexcept { if (one && !two) return 1; @@ -483,7 +423,7 @@ gnc_value_list_get_type (void) } void -KvpFrame::flatten_kvp_impl(std::vector path, std::vector , KvpValue*>> & entries) const +KvpFrame::flatten_kvp_impl(std::vector path, std::vector , KvpValue*>> & entries) const noexcept { for (auto const & entry : m_valuemap) { @@ -504,7 +444,7 @@ KvpFrame::flatten_kvp_impl(std::vector path, std::vector , KvpValue*>> -KvpFrame::flatten_kvp(void) const +KvpFrame::flatten_kvp(void) const noexcept { std::vector , KvpValue*>> ret; flatten_kvp_impl({}, ret); diff --git a/libgnucash/engine/kvp-frame.hpp b/libgnucash/engine/kvp-frame.hpp index 6bdb16fdae..32dd1023f2 100644 --- a/libgnucash/engine/kvp-frame.hpp +++ b/libgnucash/engine/kvp-frame.hpp @@ -141,7 +141,7 @@ struct KvpFrameImpl * @param newvalue: The value to set at key. * @return The old value if there was one or nullptr. */ - KvpValue* set(const char * key, KvpValue* newvalue) noexcept; + //KvpValue* set(const char * key, KvpValue* newvalue) noexcept; /** * Set the value with the key in a subframe following the keys in path, * replacing and returning the old value if it exists or nullptr if it @@ -156,18 +156,6 @@ struct KvpFrameImpl * @return The old value if there was one or nullptr. */ KvpValue* set(Path path, KvpValue* newvalue) noexcept; - /** - * Set the value with the key in a subframe following the keys in path, - * replacing and returning the old value if it exists or nullptr if it - * doesn't. Creates any missing intermediate frames. Takes - * ownership of new value and releases ownership of the returned old - * value. Values must be allocated on the free store with operator new. - * @param path: The path of subframes as a '/'-delimited string leading to - * the frame in which to insert/replace. - * @param newvalue: The value to set at key. - * @return The old value if there was one or nullptr. - */ - KvpValue* set_path(const char* path, KvpValue* newvalue) noexcept; /** * Set the value with the key in a subframe following the keys in path, * replacing and returning the old value if it exists or nullptr if it @@ -198,16 +186,11 @@ struct KvpFrameImpl */ std::vector get_keys() const noexcept; - /** Get the value for the key or nullptr if it doesn't exist. - * @param key: The key. - * @return The value at the key or nullptr. - */ - KvpValue* get_slot(const char * key) const noexcept; /** Get the value for the tail of the path or nullptr if it doesn't exist. * @param path: Path of keys leading to the desired value. * @return The value at the key or nullptr. */ - KvpValue* get_slot(Path keys) const noexcept; + KvpValue* get_slot(Path keys) noexcept; /** * proc is called with each of the immediate contents of this frame, passing it the key, @@ -240,7 +223,7 @@ struct KvpFrameImpl * the frame-containing values. */ std::vector , KvpValue*>> - flatten_kvp(void) const; + flatten_kvp(void) const noexcept; /** Test for emptiness * @return true if the frame contains nothing. @@ -251,7 +234,10 @@ struct KvpFrameImpl private: map_type m_valuemap; - void flatten_kvp_impl(std::vector , std::vector , KvpValue*>> &) const; + KvpFrame * get_child_frame_or_nullptr (Path const &) noexcept; + KvpFrame * get_child_frame_or_create (Path const &) noexcept; + void flatten_kvp_impl(std::vector , std::vector , KvpValue*>> &) const noexcept; + KvpValue * set_impl (std::string const &, KvpValue *) noexcept; }; template diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp index 1694ec4242..82f998ed79 100644 --- a/libgnucash/engine/qofbook.cpp +++ b/libgnucash/engine/qofbook.cpp @@ -1040,7 +1040,7 @@ GDate* qof_book_get_autoreadonly_gdate (const QofBook *book) const char* qof_book_get_string_option(const QofBook* book, const char* opt_name) { - auto slot = qof_instance_get_slots(QOF_INSTANCE (book))->get_slot(opt_name); + auto slot = qof_instance_get_slots(QOF_INSTANCE (book))->get_slot({opt_name}); if (slot == nullptr) return nullptr; return slot->get(); @@ -1052,9 +1052,9 @@ qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_ qof_book_begin_edit(book); auto frame = qof_instance_get_slots(QOF_INSTANCE(book)); if (opt_val && (*opt_val != '\0')) - delete frame->set(opt_name, new KvpValue(g_strdup(opt_val))); + delete frame->set({opt_name}, new KvpValue(g_strdup(opt_val))); else - delete frame->set(opt_name, nullptr); + delete frame->set({opt_name}, nullptr); qof_instance_set_dirty (QOF_INSTANCE (book)); qof_book_commit_edit(book); } @@ -1086,7 +1086,7 @@ qof_book_get_features (QofBook *book) GHashTable *features = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); - auto slot = frame->get_slot(GNC_FEATURES); + auto slot = frame->get_slot({GNC_FEATURES}); if (slot != nullptr) { frame = slot->get(); @@ -1100,11 +1100,11 @@ qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr) { KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book)); KvpValue* feature = nullptr; - auto feature_slot = frame->get_slot(GNC_FEATURES); + auto feature_slot = frame->get_slot({GNC_FEATURES}); if (feature_slot) { auto feature_frame = feature_slot->get(); - feature = feature_frame->get_slot(key); + feature = feature_frame->get_slot({key}); } if (feature == nullptr || g_strcmp0 (feature->get(), descr)) { @@ -1178,7 +1178,7 @@ qof_book_options_delete (QofBook *book, GSList *path) delete root->set_path(path_v, nullptr); } else - delete root->set_path(KVP_OPTION_PATH, nullptr); + delete root->set_path({KVP_OPTION_PATH}, nullptr); } /* QofObject function implementation and registration */ diff --git a/libgnucash/engine/qofinstance-p.h b/libgnucash/engine/qofinstance-p.h index bce6ead1fd..9fd5e4f995 100644 --- a/libgnucash/engine/qofinstance-p.h +++ b/libgnucash/engine/qofinstance-p.h @@ -154,10 +154,7 @@ void qof_instance_kvp_merge_guids (const QofInstance *target, const QofInstance *donor, const char* path); gboolean qof_instance_has_slot (const QofInstance *inst, const char *path); void qof_instance_slot_var_delete (const QofInstance *, unsigned count, ...); -void qof_instance_slot_delete (const QofInstance *inst, const char *path); void qof_instance_slot_var_delete_if_empty (const QofInstance *, unsigned count, ...); -void qof_instance_slot_delete_if_empty (const QofInstance *inst, - const char *path); void qof_instance_foreach_slot (const QofInstance *inst, const char *path, void(*proc)(const char*, const GValue*, void*), void* data); @@ -183,7 +180,7 @@ template void qof_instance_foreach_slot_temp (QofInstance const * inst, std::string const & path, func_type const & func, data_type & data) { - auto slot = inst->kvp_data->get_slot(path.c_str()); + auto slot = inst->kvp_data->get_slot({path}); if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) return; auto frame = slot->get(); diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp index a222668f3c..7a3b6bf242 100644 --- a/libgnucash/engine/qofinstance.cpp +++ b/libgnucash/engine/qofinstance.cpp @@ -1144,8 +1144,8 @@ qof_instance_kvp_add_guid (const QofInstance *inst, const char* path, g_return_if_fail (inst->kvp_data != NULL); auto container = new KvpFrame; - container->set(key, new KvpValue(const_cast(guid))); - container->set("date", new KvpValue(time)); + container->set({key}, new KvpValue(const_cast(guid))); + container->set({"date"}, new KvpValue(time)); delete inst->kvp_data->set_path({path}, new KvpValue(container)); } @@ -1286,7 +1286,7 @@ bool qof_instance_has_path_slot (QofInstance const * inst, std::vectorkvp_data->get_slot(path) != NULL; + return inst->kvp_data->get_slot({path}) != NULL; } void qof_instance_slot_path_delete (QofInstance const * inst, std::vector const & path) @@ -1306,12 +1306,6 @@ qof_instance_slot_var_delete (QofInstance const *inst, unsigned count, ...) delete inst->kvp_data->set (path, nullptr); } -void -qof_instance_slot_delete (const QofInstance *inst, const char *path) -{ - delete inst->kvp_data->set(path, nullptr); -} - void qof_instance_slot_path_delete_if_empty (QofInstance const * inst, std::vector const & path) { auto slot = inst->kvp_data->get_slot (path); @@ -1341,18 +1335,6 @@ qof_instance_slot_var_delete_if_empty (QofInstance const *inst, unsigned count, } } -void -qof_instance_slot_delete_if_empty (const QofInstance *inst, const char *path) -{ - auto slot = inst->kvp_data->get_slot(path); - if (slot) - { - auto frame = slot->get(); - if (frame && frame->empty()) - delete inst->kvp_data->set(path, nullptr); - } -} - std::vector > qof_instance_get_slots_prefix (QofInstance const * inst, std::string const & prefix) { @@ -1393,7 +1375,7 @@ qof_instance_foreach_slot (const QofInstance *inst, const char* path, void (*proc)(const char*, const GValue*, void*), void* data) { - auto slot = inst->kvp_data->get_slot(path); + auto slot = inst->kvp_data->get_slot({path}); if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) return; auto frame = slot->get(); diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp index c4c4170101..ab2cb021fe 100644 --- a/libgnucash/engine/test-core/test-engine-stuff.cpp +++ b/libgnucash/engine/test-core/test-engine-stuff.cpp @@ -381,7 +381,7 @@ get_random_kvp_frame_depth (gint depth) val_added = TRUE; - ret->set_path(key, val); + ret->set_path({key}, val); g_free(key); } diff --git a/libgnucash/engine/test/gtest-import-map.cpp b/libgnucash/engine/test/gtest-import-map.cpp index 1d5b693490..d811574387 100644 --- a/libgnucash/engine/test/gtest-import-map.cpp +++ b/libgnucash/engine/test/gtest-import-map.cpp @@ -254,12 +254,12 @@ TEST_F(ImapBayesTest, FindAccountBayes) auto acct2_guid = guid_to_string (xaccAccountGetGUID(t_expense_account2)); auto value = new KvpValue(INT64_C(42)); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid).c_str(), value); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid).c_str(), new KvpValue{*value}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid).c_str(), new KvpValue{*value}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid).c_str(), new KvpValue{*value}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + pepper + "-" + acct1_guid).c_str(), new KvpValue{*value}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct2_guid).c_str(), new KvpValue{*value}); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid}, value); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid}, new KvpValue{*value}); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid}, new KvpValue{*value}); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid}, new KvpValue{*value}); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + pepper + "-" + acct1_guid}, new KvpValue{*value}); + root->set_path({std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct2_guid}, new KvpValue{*value}); auto account = gnc_account_imap_find_account_bayes(t_imap, t_list1); EXPECT_EQ(t_expense_account1, account); @@ -292,29 +292,29 @@ TEST_F(ImapBayesTest, AddAccountBayes) auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account)); auto acct1_guid = guid_to_string (xaccAccountGetGUID(t_expense_account1)); auto acct2_guid = guid_to_string (xaccAccountGetGUID(t_expense_account2)); - auto value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-foo-bar").c_str()); + auto value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-foo-bar"}); auto check_account = [this](KvpValue* v) { return (v->get(), this->t_imap->book); }; - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + pepper + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + pepper + "-" + acct1_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct2_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct1_guid}); EXPECT_EQ(nullptr, value); qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account)); gnc_account_imap_add_account_bayes(t_imap, t_list2, t_expense_account2); qof_instance_mark_clean(QOF_INSTANCE(t_bank_account)); qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account)); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid}); EXPECT_EQ(2, value->get()); } @@ -335,43 +335,43 @@ TEST_F(ImapBayesTest, ConvertAccountBayes) auto val2 = new KvpValue(static_cast(5)); auto val3 = new KvpValue(static_cast(2)); // Test for existing entries, all will be 1 - auto value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid).c_str()); + auto value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + bar + "-" + acct1_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + baz + "-" + acct2_guid}); EXPECT_EQ(1, value->get()); - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + waldo + "-" + acct2_guid}); EXPECT_EQ(1, value->get()); // Set up some old entries - root->set_path((std::string{IMAP_FRAME_BAYES} + "/token/with/slashes/" + "Asset-Bank").c_str(), val1); - root->set_path((std::string{IMAP_FRAME_BAYES} + "/" + salt + "/" + "Asset-Bank#Bank").c_str(), new KvpValue{*val1}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "/" + salt + "/" + "Asset>Bank#Bank").c_str(), val2); - root->set_path((std::string{IMAP_FRAME_BAYES} + "/" + pork + "/" + "Expense#Food").c_str(), new KvpValue{*val2}); - root->set_path((std::string{IMAP_FRAME_BAYES} + "/" + sausage + "/" + "Expense#Drink").c_str(), val3); - root->set_path((std::string{IMAP_FRAME_BAYES} + "/" + foo + "/" + "Expense#Food").c_str(), new KvpValue{*val2}); + root->set_path({IMAP_FRAME_BAYES, "token", "with", "slashes", "Asset-Bank"}, val1); + root->set_path({IMAP_FRAME_BAYES, salt, "Asset-Bank#Bank"}, new KvpValue{*val1}); + root->set_path({IMAP_FRAME_BAYES, salt, "Asset>Bank#Bank"}, val2); + root->set_path({IMAP_FRAME_BAYES, pork, "Expense#Food"}, new KvpValue{*val2}); + root->set_path({IMAP_FRAME_BAYES, sausage, "Expense#Drink"}, val3); + root->set_path({IMAP_FRAME_BAYES, foo, "Expense#Food"}, new KvpValue{*val2}); EXPECT_EQ(1, qof_instance_get_editlevel(QOF_INSTANCE(t_bank_account))); EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account))); qof_instance_mark_clean(QOF_INSTANCE(t_bank_account)); // Start Convert gnc_account_imap_convert_bayes (t_imap->book); // convert from 'Asset-Bank' to 'Asset-Bank' guid - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-token-with-slashes-" + acct3_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-token-with-slashes-" + acct3_guid}); EXPECT_EQ(10, value->get()); // convert from 'Asset-Bank#Bank' to 'Sav Bank' guid - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct4_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + salt + "-" + acct4_guid}); EXPECT_EQ(10, value->get()); // convert from 'Expense#Food' to 'Food' guid - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + pork + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + pork + "-" + acct1_guid}); EXPECT_EQ(5, value->get()); // convert from 'Expense#Drink' to 'Drink' guid - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + sausage + "-" + acct2_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + sausage + "-" + acct2_guid}); EXPECT_EQ(2, value->get()); // convert from 'Expense#Food' to 'Food' guid but add to original value - value = root->get_slot((std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid).c_str()); + value = root->get_slot({std::string{IMAP_FRAME_BAYES} + "-" + foo + "-" + acct1_guid}); EXPECT_EQ(5, value->get()); // Check for run once flag - auto vals = book->get_slot("changed-bayesian-to-guid"); + auto vals = book->get_slot({"changed-bayesian-to-guid"}); EXPECT_STREQ("true", vals->get()); EXPECT_EQ(1, qof_instance_get_editlevel(QOF_INSTANCE(t_bank_account))); EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account))); diff --git a/libgnucash/engine/test/test-kvp-frame.cpp b/libgnucash/engine/test/test-kvp-frame.cpp index d67639f890..4a57c4560f 100644 --- a/libgnucash/engine/test/test-kvp-frame.cpp +++ b/libgnucash/engine/test/test-kvp-frame.cpp @@ -35,10 +35,10 @@ public: t_int_val{new KvpValue {INT64_C(15)}}, t_str_val{new KvpValue{"a value"}} { auto f1 = new KvpFrame; - t_root.set("top", new KvpValue{f1}); - f1->set("first", t_int_val); - f1->set("second", new KvpValue{new KvpFrame}); - f1->set("third", t_str_val); + t_root.set({"top"}, new KvpValue{f1}); + f1->set({"first"}, t_int_val); + f1->set({"second"}, new KvpValue{new KvpFrame}); + f1->set({"third"}, t_str_val); } protected: KvpFrameImpl t_root; @@ -59,13 +59,12 @@ TEST_F (KvpFrameTest, SetLocal) auto v1 = new KvpValueImpl {15.0}; auto v2 = new KvpValueImpl { (int64_t)52}; const char* k1 = "first key"; - const char* k2 = "first key/second key"; - EXPECT_EQ (nullptr, f1->set (k1, v1)); + EXPECT_EQ (nullptr, f1->set ({k1}, v1)); auto first_frame = new KvpFrame; - EXPECT_EQ (v1, f1->set (k1, new KvpValue{first_frame})); - EXPECT_EQ (nullptr, f1->set(k2, v2)); - EXPECT_EQ (v2, first_frame->get_slot("second key")); + EXPECT_EQ (v1, f1->set ({k1}, new KvpValue{first_frame})); + EXPECT_EQ (nullptr, f1->set({"first key", "second key"}, v2)); + EXPECT_EQ (v2, first_frame->get_slot({"second key"})); delete f1; //this should also delete v2. delete v1; @@ -88,15 +87,14 @@ TEST_F (KvpFrameTest, SetPath) TEST_F (KvpFrameTest, SetPathSlash) { - Path path1 {"top", "second/twenty", "twenty-first"}; + Path path1 {"top", "second", "twenty", "twenty-first"}; Path path2 {"top", "third", "thirty-first"}; auto v1 = new KvpValueImpl {15.0}; auto v2 = new KvpValueImpl { (int64_t)52}; - EXPECT_EQ (nullptr, t_root.set(path1, v1)); EXPECT_EQ (nullptr, t_root.set(path1, v2)); - auto second_frame = t_root.get_slot("top")->get()->get_slot("second")->get(); - second_frame->set("twenty", new KvpValue{new KvpFrame}); + auto second_frame = t_root.get_slot({"top"})->get()->get_slot({"second"})->get(); + second_frame->set({"twenty"}, new KvpValue{new KvpFrame}); EXPECT_EQ (nullptr, t_root.set(path1, v1)); EXPECT_EQ (v1, t_root.set(path1, v2)); EXPECT_EQ (v2, t_root.get_slot(path1)); @@ -104,16 +102,6 @@ TEST_F (KvpFrameTest, SetPathSlash) delete v1; } -TEST_F (KvpFrameTest, SetPathIgnoreBeginEndSlash) -{ - Path path1 {"top", "/second/", "twenty-first"}; - Path path2 {"top", "second", "twenty-first"}; - auto v1 = new KvpValueImpl {15.0}; - - EXPECT_EQ (nullptr, t_root.set_path(path1, v1)); - EXPECT_EQ (v1, t_root.get_slot(path2)); -} - TEST_F (KvpFrameTest, SetPathWithCreate) { Path path1 {"top", "second", "twenty-first"}; @@ -130,7 +118,7 @@ TEST_F (KvpFrameTest, SetPathWithCreate) TEST_F (KvpFrameTest, SetPathWithCreateSlash) { - Path path1 {"top", "second/twenty", "twenty-first"}; + Path path1 {"top", "second", "twenty", "twenty-first"}; Path path2 {"top", "third", "thirty-first"}; Path path1a {"top", "second", "twenty", "twenty-first"}; auto v1 = new KvpValueImpl {15.0}; @@ -154,7 +142,7 @@ TEST_F (KvpFrameTest, GetKeys) EXPECT_EQ (keys.size (), 1ul); assert_contains (keys, k1); - auto frameval = t_root.get_slot(k1); + auto frameval = t_root.get_slot({k1}); ASSERT_EQ(frameval->get_type(), KvpValue::Type::FRAME); keys = frameval->get()->get_keys(); assert_contains (keys, k2); @@ -166,15 +154,13 @@ TEST_F (KvpFrameTest, GetLocalSlot) auto k1 = "first"; auto k2 = "third"; auto k3 = "doesn't exist"; - auto k4 = "top/first"; - - auto frameval = t_root.get_slot("top"); + auto frameval = t_root.get_slot({"top"}); ASSERT_EQ(frameval->get_type(), KvpValue::Type::FRAME); auto f1 = frameval->get(); - EXPECT_EQ (t_int_val, f1->get_slot(k1)); - EXPECT_EQ (t_str_val, f1->get_slot(k2)); - EXPECT_EQ (nullptr, f1->get_slot(k3)); - EXPECT_EQ (t_int_val, t_root.get_slot(k4)); + EXPECT_EQ (t_int_val, f1->get_slot({k1})); + EXPECT_EQ (t_str_val, f1->get_slot({k2})); + EXPECT_EQ (nullptr, f1->get_slot({k3})); + EXPECT_EQ (t_int_val, t_root.get_slot({"top", "first"})); } TEST_F (KvpFrameTest, GetSlotPath) @@ -182,7 +168,7 @@ TEST_F (KvpFrameTest, GetSlotPath) Path path1 {"top", "second", "twenty-first"}; Path path2 {"top", "third", "thirty-first"}; Path path3 {"top", "second", "twenty", "twenty-first"}; - Path path3a {"top", "second/twenty", "twenty-first"}; + Path path3a {"top", "second", "twenty", "twenty-first"}; auto v1 = new KvpValueImpl {15.0}; auto v2 = new KvpValueImpl { (int64_t)52}; @@ -198,7 +184,7 @@ TEST_F (KvpFrameTest, GetSlotPath) TEST_F (KvpFrameTest, Empty) { KvpFrameImpl f1, f2; - f2.set("value", new KvpValue {2.2}); + f2.set({"value"}, new KvpValue {2.2}); EXPECT_TRUE(f1.empty()); EXPECT_FALSE(f2.empty()); } @@ -206,12 +192,12 @@ TEST_F (KvpFrameTest, Empty) TEST (KvpFrameTestForEachPrefix, for_each_prefix_1) { KvpFrame fr; - fr.set("one", new KvpValue{new KvpFrame}); - fr.set("one/two", new KvpValue{new KvpFrame}); - fr.set("top/two/three", new KvpValue {15.0}); - fr.set("onetwo", new KvpValue{new KvpFrame}); - fr.set("onetwo/three", new KvpValue {15.0}); - fr.set("onetwothree", new KvpValue {(int64_t)52}); + fr.set({"one"}, new KvpValue{new KvpFrame}); + fr.set({"one", "two"}, new KvpValue{new KvpFrame}); + fr.set({"top", "two", "three"}, new KvpValue {15.0}); + fr.set({"onetwo"}, new KvpValue{new KvpFrame}); + fr.set({"onetwo", "three"}, new KvpValue {15.0}); + fr.set({"onetwothree"}, new KvpValue {(int64_t)52}); unsigned count {}; auto counter = [] (char const *, KvpValue*, unsigned & count) { ++count; }; fr.for_each_slot_prefix("one", counter, count); @@ -230,8 +216,8 @@ TEST (KvpFrameTestForEachPrefix, for_each_prefix_1) TEST (KvpFrameTestForEachPrefix, for_each_prefix_2) { KvpFrame fr; - fr.set("onetwo/three", new KvpValue {15.0}); - fr.set("onethree", new KvpValue {(int64_t)52}); + fr.set({"onetwo", "three"}, new KvpValue {15.0}); + fr.set({"onethree"}, new KvpValue {(int64_t)52}); unsigned count; fr.for_each_slot_prefix("onetwo", [](char const *, KvpValue * value, unsigned) { EXPECT_EQ(value->get_type(), KvpValue::Type::FRAME); diff --git a/libgnucash/engine/test/utest-Split.cpp b/libgnucash/engine/test/utest-Split.cpp index d60fbe19c5..704211d29e 100644 --- a/libgnucash/engine/test/utest-Split.cpp +++ b/libgnucash/engine/test/utest-Split.cpp @@ -735,12 +735,12 @@ test_xaccSplitDetermineGainStatus (Fixture *fixture, gconstpointer pData) fixture->split->gains = GAINS_STATUS_UNKNOWN; fixture->split->gains_split = NULL; - g_assert (fixture->split->inst.kvp_data->get_slot("gains_source") == NULL); + g_assert (fixture->split->inst.kvp_data->get_slot({"gains_source"}) == NULL); xaccSplitDetermineGainStatus (fixture->split); g_assert (fixture->split->gains_split == NULL); g_assert_cmpint (fixture->split->gains, ==, GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY); - fixture->split->inst.kvp_data->set("gains-source", new KvpValue(guid_copy(g_guid))); + fixture->split->inst.kvp_data->set({"gains-source"}, new KvpValue(guid_copy(g_guid))); g_assert (fixture->split->gains_split == NULL); fixture->split->gains = GAINS_STATUS_UNKNOWN; xaccSplitDetermineGainStatus (fixture->split); @@ -1802,7 +1802,7 @@ test_xaccSplitGetOtherSplit (Fixture *fixture, gconstpointer pData) g_assert (xaccSplitGetOtherSplit (split1) == NULL); g_assert (xaccTransUseTradingAccounts (txn) == FALSE); - g_assert (split->inst.kvp_data->get_slot("lot-split") == NULL); + g_assert (split->inst.kvp_data->get_slot({"lot-split"}) == NULL); g_assert_cmpint (xaccTransCountSplits (txn), !=, 2); g_assert (xaccSplitGetOtherSplit (split) == NULL); @@ -1813,18 +1813,18 @@ test_xaccSplitGetOtherSplit (Fixture *fixture, gconstpointer pData) xaccSplitSetParent (split2, txn); g_assert (xaccSplitGetOtherSplit (split) == NULL); - split->inst.kvp_data->set("lot-split", kvpnow); - g_assert (split->inst.kvp_data->get_slot("lot-split")); + split->inst.kvp_data->set({"lot-split"}, kvpnow); + g_assert (split->inst.kvp_data->get_slot({"lot-split"})); g_assert (xaccSplitGetOtherSplit (split) == NULL); - split1->inst.kvp_data->set("lot-split", kvpnow); - g_assert (split1->inst.kvp_data->get_slot("lot-split")); + split1->inst.kvp_data->set({"lot-split"}, kvpnow); + g_assert (split1->inst.kvp_data->get_slot({"lot-split"})); g_assert (xaccSplitGetOtherSplit (split) == split2); - split->inst.kvp_data->set("lot-split", NULL); - g_assert (split->inst.kvp_data->get_slot("lot-split") == NULL); - split1->inst.kvp_data->set("lot-split", NULL); - g_assert (split1->inst.kvp_data->get_slot("lot-split") == NULL); + split->inst.kvp_data->set({"lot-split"}, NULL); + g_assert (split->inst.kvp_data->get_slot({"lot-split"}) == NULL); + split1->inst.kvp_data->set({"lot-split"}, NULL); + g_assert (split1->inst.kvp_data->get_slot({"lot-split"}) == NULL); qof_book_begin_edit (book); qof_instance_set (QOF_INSTANCE (book), "trading-accts", "t", diff --git a/libgnucash/engine/test/utest-Transaction.cpp b/libgnucash/engine/test/utest-Transaction.cpp index a95a5acaff..c322c66f53 100644 --- a/libgnucash/engine/test/utest-Transaction.cpp +++ b/libgnucash/engine/test/utest-Transaction.cpp @@ -153,8 +153,8 @@ setup (Fixture *fixture, gconstpointer pData) xaccTransSetCurrency (txn, fixture->curr); xaccSplitSetParent (split1, txn); xaccSplitSetParent (split2, txn); - frame->set(trans_notes_str, new KvpValue("Salt pork sausage")); - frame->set_path("/qux/quux/corge", new KvpValue(123.456)); + frame->set({trans_notes_str}, new KvpValue("Salt pork sausage")); + frame->set_path({"qux", "quux", "corge"}, new KvpValue(123.456)); qof_instance_set_slots (QOF_INSTANCE (txn), frame); } xaccTransCommitEdit (txn); @@ -562,7 +562,7 @@ test_dupe_trans (Fixture *fixture, gconstpointer pData) oldtxn->date_posted = posted; oldtxn->date_entered = entered; - oldtxn->inst.kvp_data->set("/foo/bar/baz", + oldtxn->inst.kvp_data->set({"foo", "bar", "baz"}, new KvpValue("The Great Waldo Pepper")); newtxn = fixture->func->dupe_trans (oldtxn); @@ -881,7 +881,7 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) g_free(clone->description); clone->description = static_cast(CACHE_INSERT ("Waldo Pepper")); auto frame = qof_instance_get_slots (QOF_INSTANCE (clone)); - frame->set("/qux/quux/corge", new KvpValue(654.321)); + frame->set({"qux", "quux", "corge"}, new KvpValue(654.321)); xaccTransCommitEdit (clone); g_free (cleanup->msg); g_free (check->msg); @@ -893,7 +893,7 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) xaccTransBeginEdit (clone); cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig); clone->description = static_cast(CACHE_INSERT ("Waldo Pepper")); - frame->set("/qux/quux/corge", new KvpValue(123.456)); + frame->set({"qux", "quux", "corge"}, new KvpValue(123.456)); xaccTransCommitEdit (clone); g_free (cleanup->msg); g_free (check->msg); @@ -1858,22 +1858,22 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData) /* Actual function variables start here. */ auto frame = fixture->txn->inst.kvp_data; auto void_reason = "Voided for Unit Test"; - auto txn_notes = g_strdup (frame->get_slot(trans_notes_str)->get()); + auto txn_notes = g_strdup (frame->get_slot({trans_notes_str})->get()); Timespec now = timespec_now (); char iso8601_str[ISO_DATELENGTH + 1] = ""; GList *split = NULL; xaccTransVoid (fixture->txn, void_reason); - g_assert_cmpstr (frame->get_slot(trans_notes_str)->get(), ==, + g_assert_cmpstr (frame->get_slot({trans_notes_str})->get(), ==, "Voided transaction"); - g_assert_cmpstr (frame->get_slot(void_former_notes_str)->get(), + g_assert_cmpstr (frame->get_slot({void_former_notes_str})->get(), ==, txn_notes); - g_assert_cmpstr (frame->get_slot(void_reason_str)->get(), ==, + g_assert_cmpstr (frame->get_slot({void_reason_str})->get(), ==, void_reason); gnc_timespec_to_iso8601_buff (now, iso8601_str); - g_assert_cmpstr (frame->get_slot(void_time_str)->get(), ==, + g_assert_cmpstr (frame->get_slot({void_time_str})->get(), ==, iso8601_str); - g_assert_cmpstr (frame->get_slot(TRANS_READ_ONLY_REASON)->get(), + g_assert_cmpstr (frame->get_slot({TRANS_READ_ONLY_REASON})->get(), ==, "Transaction Voided"); for (split = fixture->txn->splits; split; split=g_list_next (split)) { @@ -1883,12 +1883,12 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData) xaccTransUnvoid (fixture->txn); - g_assert_cmpstr (frame->get_slot(trans_notes_str)->get(), ==, + g_assert_cmpstr (frame->get_slot({trans_notes_str})->get(), ==, txn_notes); - g_assert (frame->get_slot(void_former_notes_str) == NULL); - g_assert (frame->get_slot(void_reason_str) == NULL); - g_assert (frame->get_slot(void_time_str) == NULL); - g_assert (frame->get_slot(TRANS_READ_ONLY_REASON) == NULL); + g_assert (frame->get_slot({void_former_notes_str}) == NULL); + g_assert (frame->get_slot({void_reason_str}) == NULL); + g_assert (frame->get_slot({void_time_str}) == NULL); + g_assert (frame->get_slot({TRANS_READ_ONLY_REASON}) == NULL); for (split = fixture->txn->splits; split; split=g_list_next (split)) { g_assert (!gnc_numeric_zero_p (((Split*)(split->data))->value)); @@ -1909,7 +1909,7 @@ test_xaccTransReverse (Fixture *fixture, gconstpointer pData) auto frame = fixture->txn->inst.kvp_data; GList *orig_splits = NULL, *rev_splits = NULL; - g_assert (guid_equal (frame->get_slot(TRANS_REVERSED_BY)->get(), + g_assert (guid_equal (frame->get_slot({TRANS_REVERSED_BY})->get(), xaccTransGetGUID (rev))); g_assert (!qof_instance_is_dirty (QOF_INSTANCE (rev))); //Cleared by commit