Skip to content

Commit

Permalink
[Account.cpp][api] gnc_account_foreach_split takes std::function<void…
Browse files Browse the repository at this point in the history
…(Split*)>
  • Loading branch information
christopherlam committed Apr 21, 2024
1 parent 31e80a1 commit 0f791c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,20 @@ xaccInitAccount (Account * acc, QofBook *book)
/********************************************************************\
\********************************************************************/

void
gnc_account_foreach_split (const Account *acc, std::function<void(Split*)> func,
bool reverse)
{
if (!GNC_IS_ACCOUNT (acc))
return;

auto splits{GET_PRIVATE(acc)->splits};
if (reverse)
std::for_each(splits.rbegin(), splits.rend(), func);
else
std::for_each(splits.begin(), splits.end(), func);
}

Split*
gnc_account_find_split (const Account *acc, std::function<bool(const Split*)> predicate,
bool reverse)
Expand Down
2 changes: 2 additions & 0 deletions libgnucash/engine/Account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ using SplitsVec = std::vector<Split*>;

const SplitsVec xaccAccountGetSplits (const Account*);

void gnc_account_foreach_split (const Account*, std::function<void(Split*)>, bool);

/** scans account split list (in forward or reverse order) until
* predicate split->bool returns true. Maybe return the split.
*
Expand Down

0 comments on commit 0f791c4

Please sign in to comment.