fixed cache by clear transaction flags before writing

This commit is contained in:
John Wiegley 2004-08-05 23:51:20 -04:00
parent 5409bc04b8
commit 6048ae7c05
4 changed files with 35 additions and 3 deletions

View file

@ -253,6 +253,8 @@ account_t * read_binary_account(std::istream& in, account_t * master = NULL)
acct->note = buf;
}
in.read((char *)&acct->depth, sizeof(acct->depth));
in.read((char *)&len, sizeof(len));
// If all of the subaccounts will be added to a different master
@ -540,6 +542,8 @@ void write_binary_account(std::ostream& out, account_t * account)
if (len)
out.write(account->note.c_str(), len);
out.write((char *)&account->depth, sizeof(account->depth));
len = account->accounts.size();
out.write((char *)&len, sizeof(len));
@ -592,13 +596,14 @@ void write_binary_journal(std::ostream& out, journal_t * journal,
write_binary_account(out, journal->master);
unsigned long count = commodity_t::commodities.size();
unsigned long count = commodity_t::commodities.size() - 1;
out.write((char *)&count, sizeof(count));
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
i != commodity_t::commodities.end();
i++)
write_binary_commodity(out, (*i).second);
if (! (*i).first.empty())
write_binary_commodity(out, (*i).second);
count = journal->entries.size();
out.write((char *)&count, sizeof(count));

View file

@ -100,11 +100,11 @@ class account_t
account_t * parent;
std::string name;
std::string note;
unsigned long depth;
accounts_map accounts;
transactions_list transactions;
balance_pair_t value;
balance_pair_t total;
unsigned long depth;
unsigned long ident;
mutable std::string _fullname;

View file

@ -810,6 +810,8 @@ int main(int argc, char * argv[])
if (const char * p = std::getenv("LEDGER_CACHE")) {
std::ofstream outstr(p);
assert(std::getenv("LEDGER"));
clear_transaction_display_flags(journal->entries.begin(),
journal->entries.end());
write_binary_journal(outstr, journal.get(), std::getenv("LEDGER"));
}

25
walk.h
View file

@ -164,6 +164,31 @@ void walk_entries(entries_list::iterator begin,
handle_transaction(*j, functor, disp_pred_functor, flags);
}
template <typename Function>
void walk_entries(entries_list::iterator begin,
entries_list::iterator end, Function functor)
{
for (entries_list::iterator i = begin; i != end; i++)
for (transactions_list::iterator j = (*i)->transactions.begin();
j != (*i)->transactions.end();
j++)
functor(*j);
}
class clear_flags
{
public:
void operator()(transaction_t * xact) const {
xact->flags &= ~(TRANSACTION_HANDLED | TRANSACTION_DISPLAYED);
}
};
inline void clear_transaction_display_flags(entries_list::iterator begin,
entries_list::iterator end)
{
walk_entries<clear_flags>(begin, end, clear_flags());
}
template <typename Function>
void walk_transactions(transactions_list::iterator begin,
transactions_list::iterator end, Function functor)