mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[account.cpp] add gnc_account_foreach_until_date
- uses binary search to find first split after date - for_each from earliest split to (but excluding) the above first split
This commit is contained in:
parent
2c6f15090a
commit
87dbbf25f8
@ -1151,6 +1151,22 @@ gnc_account_foreach_split (const Account *acc, std::function<void(Split*)> func,
|
||||
std::for_each(splits.begin(), splits.end(), func);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_account_foreach_split_until_date (const Account *acc, time64 end_date,
|
||||
std::function<void(Split*)> f)
|
||||
{
|
||||
if (!GNC_IS_ACCOUNT (acc))
|
||||
return;
|
||||
|
||||
auto after_date = [](time64 end_date, auto s) -> bool
|
||||
{ return (xaccTransGetDate (xaccSplitGetParent (s)) > end_date); };
|
||||
|
||||
auto splits{GET_PRIVATE(acc)->splits};
|
||||
auto after_date_iter = std::upper_bound (splits.begin(), splits.end(), end_date, after_date);
|
||||
std::for_each (splits.begin(), after_date_iter, f);
|
||||
}
|
||||
|
||||
|
||||
Split*
|
||||
gnc_account_find_split (const Account *acc, std::function<bool(const Split*)> predicate,
|
||||
bool reverse)
|
||||
|
@ -43,6 +43,9 @@ const SplitsVec xaccAccountGetSplits (const Account*);
|
||||
|
||||
void gnc_account_foreach_split (const Account*, std::function<void(Split*)>, bool);
|
||||
|
||||
void gnc_account_foreach_split_until_date (const Account *acc, time64 end_date,
|
||||
std::function<void(Split*)> f);
|
||||
|
||||
/** scans account split list (in forward or reverse order) until
|
||||
* predicate split->bool returns true. Maybe return the split.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user