GnuCash fec5643+
Loading...
Searching...
No Matches
Account.hpp
Go to the documentation of this file.
1/**********************************************************************
2 * Account.hpp
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License as *
6 * published by the Free Software Foundation; either version 2 of *
7 * the License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, contact: *
16 * *
17 * Free Software Foundation Voice: +1-617-542-5942 *
18 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19 * Boston, MA 02110-1301, USA gnu@gnu.org *
20 * *
21 *********************************************************************/
22
32#ifndef GNC_ACCOUNT_HPP
33#define GNC_ACCOUNT_HPP
34
35#include <vector>
36#include <functional>
37#include <algorithm>
38#include <optional>
39
40#include <Account.h>
41#include <SplitP.hpp>
42#include <TransactionP.hpp>
43
44using SplitsVec = std::vector<Split*>;
45using AccountVec = std::vector<Account*>;
46
47const SplitsVec& xaccAccountGetSplits (const Account*);
48
49void gnc_account_foreach_descendant (const Account *, std::function<void(Account*)> func);
50
51
52static inline SplitsVec::const_iterator
53splits_start (const SplitsVec& splits, std::optional<time64> start_date)
54{
55 if (!start_date) return splits.begin();
56 return std::lower_bound (splits.begin(), splits.end(), *start_date,
57 [](auto s, time64 t){ return s->parent->date_posted < t; });
58}
59
60static inline SplitsVec::const_iterator
61splits_end (const SplitsVec& splits, std::optional<time64> end_date)
62{
63 if (!end_date) return splits.end();
64 return std::upper_bound (splits.begin(), splits.end(), *end_date,
65 [](time64 t, auto s){ return t < s->parent->date_posted; });
66}
67
68template <typename Fn>
69void gnc_account_foreach_split_between_dates (const Account* account,
70 std::optional<time64> start_date,
71 std::optional<time64> end_date,
72 bool include_descendants, Fn&& fn)
73{
74 g_return_if_fail (GNC_IS_ACCOUNT (account));
75 auto scan_account = [&](const Account* acc)
76 {
77 const auto& splits = xaccAccountGetSplits (acc);
78 std::for_each (splits_start (splits, start_date), splits_end (splits, end_date),
79 fn);
80 };
81
82 scan_account (account);
83 if (include_descendants)
84 gnc_account_foreach_descendant (account, scan_account);
85}
86
87void gnc_account_foreach_split (const Account*, std::function<void(Split*)>);
88
89void gnc_account_foreach_split_until_date (const Account *acc, time64 end_date,
90 std::function<void(Split*)> f);
91
102Split* gnc_account_find_split (const Account*, std::function<bool(const Split*)>, bool);
103
104std::vector<const Account*> gnc_account_get_all_parents (const Account *account);
105
106#endif /* GNC_COMMODITY_HPP */
Account handling public routines.
Split * gnc_account_find_split(const Account *, std::function< bool(const Split *)>, bool)
scans account split list (in forward or reverse order) until predicate split->bool returns true.
Definition Account.cpp:1155
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
STRUCTS.