From d1807b6c15177e49c47427eefa2f11cf61fb4c83 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 3 Jun 2024 15:24:04 +0800 Subject: [PATCH] [engine.i] move gnc_accounts_and_all_descendants to engine.i --- bindings/engine-common.i | 4 ---- bindings/engine.i | 20 ++++++++++++++++++++ libgnucash/engine/Account.cpp | 18 ------------------ libgnucash/engine/Account.h | 2 -- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/bindings/engine-common.i b/bindings/engine-common.i index cd9fd4bb98c..4d360f481ee 100644 --- a/bindings/engine-common.i +++ b/bindings/engine-common.i @@ -50,14 +50,10 @@ AccountList * gnc_account_get_descendants (const Account *account); %newobject gnc_account_get_descendants_sorted; AccountList * gnc_account_get_descendants_sorted (const Account *account); -%newobject gnc_accounts_and_all_descendants; -AccountList * gnc_accounts_and_all_descendants (AccountList *accounts); - %ignore gnc_account_get_children; %ignore gnc_account_get_children_sorted; %ignore gnc_account_get_descendants; %ignore gnc_account_get_descendants_sorted; -%ignore gnc_accounts_and_all_descendants; %include %include diff --git a/bindings/engine.i b/bindings/engine.i index 20158bf52f4..5620f38e1c5 100644 --- a/bindings/engine.i +++ b/bindings/engine.i @@ -54,6 +54,8 @@ #include "gncTaxTable.h" #include "gncVendor.h" +#include +#include %} #if defined(SWIGGUILE) //Always C++ %{ @@ -64,6 +66,8 @@ using AccountVec = std::vector; SplitsVec gnc_get_match_commodity_splits (AccountVec accounts, bool use_end_date, time64 end_date, gnc_commodity *comm, bool sort); +AccountVec gnc_accounts_and_all_descendants (AccountVec accounts); + extern "C" { SCM scm_init_sw_engine_module (void); @@ -155,6 +159,22 @@ SplitsVec gnc_get_match_commodity_splits (AccountVec accounts, bool use_end_date return rv; } +using AccountSet = std::unordered_set; +static void maybe_add_descendants (Account* acc, AccountSet* accset) +{ + if (accset->insert (acc).second) + gnc_account_foreach_child (acc, (AccountCb)maybe_add_descendants, accset); +}; + +AccountVec +gnc_accounts_and_all_descendants (AccountVec accounts) +{ + AccountSet accset; + for (auto a : accounts) + maybe_add_descendants (a, &accset); + return AccountVec (accset.begin(), accset.end()); +} + %} /* NB: The object ownership annotations should already cover all the diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 8945a6e1c62..81a10129b5f 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -6383,24 +6383,6 @@ gboolean xaccAccountRegister (void) return qof_object_register (&account_object_def); } -using AccountSet = std::unordered_set; -static void maybe_add_descendants (Account* acc, gpointer arg) -{ - g_return_if_fail (acc); - - if (static_cast (arg)->insert (acc).second) - std::for_each (GET_PRIVATE(acc)->children.begin(), GET_PRIVATE(acc)->children.end(), - [&](auto acc){ maybe_add_descendants (acc, arg); }); -}; - -GList * -gnc_accounts_and_all_descendants (GList *accounts) -{ - AccountSet accset; - g_list_foreach (accounts, (GFunc) maybe_add_descendants, &accset); - return std::accumulate (accset.begin(), accset.end(), (GList*) nullptr, g_list_prepend); -} - /* ======================= UNIT TESTING ACCESS ======================= * The following functions are for unit testing use only. */ diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h index 51379dacd68..842db88486b 100644 --- a/libgnucash/engine/Account.h +++ b/libgnucash/engine/Account.h @@ -1687,8 +1687,6 @@ typedef enum const char * dxaccAccountGetQuoteTZ (const Account *account); /** @} */ - GList * gnc_accounts_and_all_descendants (GList *accounts); - /** @name Account parameter names @{ */