From 0f791c474a0617bc17f70fec1bd759136eb1fc82 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 21 Apr 2024 23:25:30 +0800 Subject: [PATCH] [Account.cpp][api] gnc_account_foreach_split takes std::function --- libgnucash/engine/Account.cpp | 14 ++++++++++++++ libgnucash/engine/Account.hpp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 6625c1900c4..589593b799a 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 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 predicate, bool reverse) diff --git a/libgnucash/engine/Account.hpp b/libgnucash/engine/Account.hpp index a947bee71fa..b246bf68853 100644 --- a/libgnucash/engine/Account.hpp +++ b/libgnucash/engine/Account.hpp @@ -41,6 +41,8 @@ using SplitsVec = std::vector; const SplitsVec xaccAccountGetSplits (const Account*); +void gnc_account_foreach_split (const Account*, std::function, bool); + /** scans account split list (in forward or reverse order) until * predicate split->bool returns true. Maybe return the split. *