Skip to content

Commit

Permalink
Merge Chris Lam's 'acc-children-vector' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Jun 27, 2024
2 parents 63927aa + d1807b6 commit ad7a51a
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 197 deletions.
4 changes: 0 additions & 4 deletions bindings/engine-common.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Account.h>

%include <Transaction.h>
Expand Down
20 changes: 20 additions & 0 deletions bindings/engine.i
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include "gncTaxTable.h"
#include "gncVendor.h"

#include <numeric>
#include <unordered_set>
%}
#if defined(SWIGGUILE) //Always C++
%{
Expand All @@ -64,6 +66,8 @@ using AccountVec = std::vector<Account*>;
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);
Expand Down Expand Up @@ -155,6 +159,22 @@ SplitsVec gnc_get_match_commodity_splits (AccountVec accounts, bool use_end_date
return rv;
}

using AccountSet = std::unordered_set<Account*>;
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
Expand Down
Loading

0 comments on commit ad7a51a

Please sign in to comment.