diff options
-rw-r--r-- | amount.cc | 6 | ||||
-rw-r--r-- | derive.cc | 5 | ||||
-rw-r--r-- | journal.cc | 15 | ||||
-rw-r--r-- | journal.h | 25 | ||||
-rw-r--r-- | textual.cc | 2 |
5 files changed, 31 insertions, 22 deletions
@@ -835,13 +835,13 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt) std::string ender; if (i == len) ender = str; - else if (i < comm.precision()) - ender = std::string(str, 0, comm.precision()); + else if (i < comm.precision) + ender = std::string(str, 0, comm.precision); else ender = std::string(str, 0, i); if (! ender.empty()) { - out << ((comm.flags() & COMMODITY_STYLE_EUROPEAN) ? ',' : '.'); + out << ((comm.flags & COMMODITY_STYLE_EUROPEAN) ? ',' : '.'); out << ender; } } @@ -167,8 +167,9 @@ entry_t * derive_new_entry(journal_t& journal, } done: - if (! run_hooks(journal.entry_finalize_hooks, *added) || - ! added->finalize()) + if (! run_hooks(journal.entry_finalize_hooks, *added, false) || + ! added->finalize() || + ! run_hooks(journal.entry_finalize_hooks, *added, true)) throw error("Failed to finalize derived entry (check commodities)"); return added.release(); @@ -264,7 +264,7 @@ auto_entry_t::~auto_entry_t() delete predicate; } -void auto_entry_t::extend_entry(entry_base_t& entry) +void auto_entry_t::extend_entry(entry_base_t& entry, bool post) { transactions_list initial_xacts(entry.transactions.begin(), entry.transactions.end()); @@ -277,10 +277,15 @@ void auto_entry_t::extend_entry(entry_base_t& entry) t != transactions.end(); t++) { amount_t amt; - if ((*t)->amount.commodity().symbol.empty()) + if (! (*t)->amount.commodity()) { + if (! post) + continue; amt = (*i)->amount * (*t)->amount; - else + } else { + if (post) + continue; amt = (*t)->amount; + } account_t * account = (*t)->account; std::string fullname = account->fullname(); @@ -458,7 +463,9 @@ bool journal_t::add_entry(entry_t * entry) { entry->journal = this; - if (! run_hooks(entry_finalize_hooks, *entry) || ! entry->finalize()) { + if (! run_hooks(entry_finalize_hooks, *entry, false) || + ! entry->finalize() || + ! run_hooks(entry_finalize_hooks, *entry, true)) { entry->journal = NULL; return false; } @@ -203,7 +203,7 @@ class entry_t : public entry_base_t struct entry_finalizer_t { virtual ~entry_finalizer_t() {} - virtual bool operator()(entry_t& entry) = 0; + virtual bool operator()(entry_t& entry, bool post) = 0; }; @@ -223,7 +223,7 @@ public: virtual ~auto_entry_t(); - virtual void extend_entry(entry_base_t& entry); + virtual void extend_entry(entry_base_t& entry, bool post); virtual bool valid() const { return true; } @@ -233,7 +233,7 @@ class journal_t; struct auto_entry_finalizer_t : public entry_finalizer_t { journal_t * journal; auto_entry_finalizer_t(journal_t * _journal) : journal(_journal) {} - virtual bool operator()(entry_t& entry); + virtual bool operator()(entry_t& entry, bool post); }; @@ -328,12 +328,12 @@ std::ostream& operator<<(std::ostream& out, const account_t& account); struct func_finalizer_t : public entry_finalizer_t { - typedef bool (*func_t)(entry_t& entry); + typedef bool (*func_t)(entry_t& entry, bool post); func_t func; func_finalizer_t(func_t _func) : func(_func) {} func_finalizer_t(const func_finalizer_t& other) : func(other.func) {} - virtual bool operator()(entry_t& entry) { - return func(entry); + virtual bool operator()(entry_t& entry, bool post) { + return func(entry, post); } }; @@ -351,11 +351,11 @@ void remove_hook(std::list<T>& list, T obj) { } template <typename T, typename Data> -bool run_hooks(std::list<T>& list, Data& item) { +bool run_hooks(std::list<T>& list, Data& item, bool post) { for (typename std::list<T>::const_iterator i = list.begin(); i != list.end(); i++) - if (! (*(*i))(item)) + if (! (*(*i))(item, post)) return false; return true; } @@ -432,15 +432,16 @@ class journal_t bool valid() const; }; -inline void extend_entry_base(journal_t * journal, entry_base_t& entry) { +inline void extend_entry_base(journal_t * journal, entry_base_t& entry, + bool post) { for (auto_entries_list::iterator i = journal->auto_entries.begin(); i != journal->auto_entries.end(); i++) - (*i)->extend_entry(entry); + (*i)->extend_entry(entry, post); } -inline bool auto_entry_finalizer_t::operator()(entry_t& entry) { - extend_entry_base(journal, entry); +inline bool auto_entry_finalizer_t::operator()(entry_t& entry, bool post) { + extend_entry_base(journal, entry, post); return true; } @@ -716,7 +716,7 @@ unsigned int textual_parser_t::parse(std::istream& in, if (parse_transactions(in, account_stack.front(), *pe, "period", end_pos)) { if (pe->finalize()) { - extend_entry_base(journal, *pe); + extend_entry_base(journal, *pe, true); journal->period_entries.push_back(pe); pe->src_idx = src_idx; pe->beg_pos = beg_pos; |