diff options
author | John Wiegley <johnw@newartisans.com> | 2004-09-23 21:08:42 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-09-23 21:08:42 -0400 |
commit | c57bfb72c3fd0c40bab1c47503c7f22c6a79a643 (patch) | |
tree | 4b3965e5df8bc9a5c58160f6ac8e08a542466df0 /ledger.h | |
parent | 02580c2efbad9b364ab0dfa535c5fe0577cb818d (diff) | |
download | fork-ledger-c57bfb72c3fd0c40bab1c47503c7f22c6a79a643.tar.gz fork-ledger-c57bfb72c3fd0c40bab1c47503c7f22c6a79a643.tar.bz2 fork-ledger-c57bfb72c3fd0c40bab1c47503c7f22c6a79a643.zip |
moved entry hooking mechanism to journal_t; further improvements to "entry"
Diffstat (limited to 'ledger.h')
-rw-r--r-- | ledger.h | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -116,6 +116,8 @@ class entry_t bool valid() const; }; +bool finalize_entry(entry_t& entry); + typedef std::map<const std::string, account_t *> accounts_map; typedef std::pair<const std::string, account_t *> accounts_pair; @@ -181,6 +183,30 @@ class account_t std::ostream& operator<<(std::ostream& out, const account_t& account); +template <typename T> +void add_hook(std::list<T>& list, T func, const bool prepend = false) { + if (prepend) + list.push_front(func); + else + list.push_back(func); +} + +template <typename T> +void remove_hook(std::list<T>& list, T func) { + list.remove(func); +} + +template <typename T, typename Data> +bool run_hooks(std::list<T>& list, Data& entry) { + for (typename std::list<T>::const_iterator i = list.begin(); + i != list.end(); + i++) + if (! (*i)(entry)) + return false; + return true; +} + + typedef std::list<entry_t *> entries_list; typedef std::list<std::string> strings_list; @@ -195,9 +221,14 @@ class journal_t mutable accounts_map accounts_cache; + typedef bool (*entry_finalize_hook_t)(entry_t& entry); + + std::list<entry_finalize_hook_t> entry_finalize_hooks; + journal_t() { master = new account_t(NULL, ""); item_pool = item_pool_end = NULL; + add_hook(entry_finalize_hooks, finalize_entry); } ~journal_t(); |