summaryrefslogtreecommitdiff
path: root/walk.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2005-11-09 07:11:22 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:21 -0400
commitf691735c6ce89a19356769084449d3f5691ab030 (patch)
treedf7a5de60353d3558b00d21ee83cf01e8da56331 /walk.h
parent3a689c568a715e7c6604825eab537d66333ce291 (diff)
downloadfork-ledger-f691735c6ce89a19356769084449d3f5691ab030.tar.gz
fork-ledger-f691735c6ce89a19356769084449d3f5691ab030.tar.bz2
fork-ledger-f691735c6ce89a19356769084449d3f5691ab030.zip
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).
Diffstat (limited to 'walk.h')
-rw-r--r--walk.h60
1 files changed, 44 insertions, 16 deletions
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<transaction_xdata_t> transactions_xdata;
-extern std::list<void **> 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<transaction_t&>(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<transaction_t>
@@ -146,6 +154,17 @@ class ignore_transactions : public item_handler<transaction_t>
virtual void operator()(transaction_t& xact) {}
};
+class clear_transaction_xdata : public item_handler<transaction_t>
+{
+ 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<transaction_t>
{
int head_count;
@@ -594,9 +613,6 @@ inline bool account_has_xdata(const account_t& account) {
return account.data != NULL;
}
-extern std::list<account_xdata_t> accounts_xdata;
-extern std::list<void **> 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<account_t>
+{
+ 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<account_t *> accounts_deque;
@@ -619,18 +646,19 @@ void walk_accounts(account_t& account,
item_handler<account_t>& 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<transaction_t>& 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