From f691735c6ce89a19356769084449d3f5691ab030 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 9 Nov 2005 07:11:22 +0000 Subject: Restructed the code that it can build and be used as a shared library. The command-line version is still statically bound in the build process by default (for the sake of speed). --- walk.h | 60 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'walk.h') diff --git a/walk.h b/walk.h index 9a37d456..887963bf 100644 --- a/walk.h +++ b/walk.h @@ -91,18 +91,17 @@ struct transaction_xdata_t unsigned int index; unsigned short dflags; std::time_t date; + account_t * account; void * ptr; - transaction_xdata_t() : index(0), dflags(0), date(0), ptr(0) {} + transaction_xdata_t() + : index(0), dflags(0), date(0), account(0), ptr(0) {} }; inline bool transaction_has_xdata(const transaction_t& xact) { return xact.data != NULL; } -extern std::list transactions_xdata; -extern std::list transactions_xdata_ptrs; - inline transaction_xdata_t& transaction_xdata_(const transaction_t& xact) { return *((transaction_xdata_t *) xact.data); } @@ -110,6 +109,17 @@ inline transaction_xdata_t& transaction_xdata_(const transaction_t& xact) { transaction_xdata_t& transaction_xdata(const transaction_t& xact); void add_transaction_to(const transaction_t& xact, value_t& value); +inline account_t * xact_account(transaction_t& xact) { + account_t * account = transaction_xdata(xact).account; + if (account) + return account; + return xact.account; +} + +inline const account_t * xact_account(const transaction_t& xact) { + return xact_account(const_cast(xact)); +} + ////////////////////////////////////////////////////////////////////// inline void walk_transactions(transactions_list::iterator begin, @@ -136,8 +146,6 @@ inline void walk_entries(entries_list& list, walk_entries(list.begin(), list.end(), handler); } -void clear_transactions_xdata(); - ////////////////////////////////////////////////////////////////////// class ignore_transactions : public item_handler @@ -146,6 +154,17 @@ class ignore_transactions : public item_handler virtual void operator()(transaction_t& xact) {} }; +class clear_transaction_xdata : public item_handler +{ + public: + virtual void operator()(transaction_t& xact) { + if (xact.data) { + delete (transaction_xdata_t *) xact.data; + xact.data = NULL; + } + } +}; + class truncate_entries : public item_handler { int head_count; @@ -594,9 +613,6 @@ inline bool account_has_xdata(const account_t& account) { return account.data != NULL; } -extern std::list accounts_xdata; -extern std::list accounts_xdata_ptrs; - inline account_xdata_t& account_xdata_(const account_t& account) { return *((account_xdata_t *) account.data); } @@ -605,6 +621,17 @@ account_xdata_t& account_xdata(const account_t& account); ////////////////////////////////////////////////////////////////////// +class clear_account_xdata : public item_handler +{ + public: + virtual void operator()(account_t& acct) { + if (acct.data) { + delete (account_xdata_t *) acct.data; + acct.data = NULL; + } + } +}; + void sum_accounts(account_t& account); typedef std::deque accounts_deque; @@ -619,18 +646,19 @@ void walk_accounts(account_t& account, item_handler& handler, const std::string& sort_string); -void clear_accounts_xdata(); - -inline void clear_all_xdata() { - clear_transactions_xdata(); - clear_accounts_xdata(); -} - ////////////////////////////////////////////////////////////////////// void walk_commodities(commodities_map& commodities, item_handler& handler); +inline void clear_journal_xdata(journal_t * journal) { + clear_transaction_xdata xact_cleaner; + walk_entries(journal->entries, xact_cleaner); + + clear_account_xdata acct_cleaner; + walk_accounts(*journal->master, acct_cleaner); +} + } // namespace ledger #endif // _WALK_H -- cgit v1.2.3