gnucash stable: [Account.cpp][api] gnc_account_foreach_split takes std::function<void(Split*)>
Christopher Lam
clam at code.gnucash.org
Sun Apr 21 19:50:14 EDT 2024
Updated via https://github.com/Gnucash/gnucash/commit/0f791c47 (commit)
from https://github.com/Gnucash/gnucash/commit/31e80a18 (commit)
commit 0f791c474a0617bc17f70fec1bd759136eb1fc82
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Apr 21 23:25:30 2024 +0800
[Account.cpp][api] gnc_account_foreach_split takes std::function<void(Split*)>
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 6625c1900c..589593b799 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -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)
diff --git a/libgnucash/engine/Account.hpp b/libgnucash/engine/Account.hpp
index a947bee71f..b246bf6885 100644
--- a/libgnucash/engine/Account.hpp
+++ b/libgnucash/engine/Account.hpp
@@ -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.
*
Summary of changes:
libgnucash/engine/Account.cpp | 14 ++++++++++++++
libgnucash/engine/Account.hpp | 2 ++
2 files changed, 16 insertions(+)
More information about the gnucash-changes
mailing list