diff options
-rw-r--r-- | journal.cc | 7 | ||||
-rw-r--r-- | journal.h | 14 | ||||
-rw-r--r-- | ledger.h | 9 | ||||
-rw-r--r-- | main.cc | 37 | ||||
-rw-r--r-- | textual.cc | 7 |
5 files changed, 19 insertions, 55 deletions
@@ -360,7 +360,6 @@ journal_t::~journal_t() { DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t"); - delete default_finalizer; delete master; // Don't bother unhooking each entry's transactions from the @@ -591,8 +590,7 @@ std::list<py_entry_finalizer_t> py_finalizers; void py_add_entry_finalizer(journal_t& journal, object x) { py_finalizers.push_back(py_entry_finalizer_t(x)); - add_hook<entry_finalizer_t *>(journal.entry_finalize_hooks, - &py_finalizers.back()); + journal.add_entry_finalizer(&py_finalizers.back()); } void py_remove_entry_finalizer(journal_t& journal, object x) @@ -601,7 +599,8 @@ void py_remove_entry_finalizer(journal_t& journal, object x) i != py_finalizers.end(); i++) if ((*i).pyobj == x) { - remove_hook<entry_finalizer_t *>(journal.entry_finalize_hooks, &(*i)); + journal.remove_entry_finalizer(&(*i)); + py_finalizers.erase(i); return; } } @@ -227,14 +227,13 @@ class journal_t mutable accounts_map accounts_cache; + func_finalizer_t default_finalizer; std::list<entry_finalizer_t *> entry_finalize_hooks; - entry_finalizer_t * default_finalizer; - journal_t() { + journal_t() : default_finalizer(finalize_entry) { master = new account_t(NULL, ""); item_pool = item_pool_end = NULL; - default_finalizer = new func_finalizer_t(finalize_entry); - add_hook(entry_finalize_hooks, default_finalizer); + add_entry_finalizer(&default_finalizer); } ~journal_t(); @@ -266,6 +265,13 @@ class journal_t bool add_entry(entry_t * entry); bool remove_entry(entry_t * entry); + void add_entry_finalizer(entry_finalizer_t * finalizer) { + add_hook<entry_finalizer_t *>(entry_finalize_hooks, finalizer); + } + void remove_entry_finalizer(entry_finalizer_t * finalizer) { + remove_hook<entry_finalizer_t *>(entry_finalize_hooks, finalizer); + } + bool valid() const; }; @@ -21,7 +21,8 @@ #include <quotes.h> #include <valexpr.h> #include <walk.h> - +#include <derive.h> +#include <error.h> #include <option.h> #include <config.h> @@ -29,13 +30,7 @@ #include <textual.h> #include <autoxact.h> #include <binary.h> -#ifdef READ_GNUCASH #include <gnucash.h> -#endif #include <qif.h> -#include <error.h> -#include <timing.h> -#include <util.h> - #endif // _LEDGER_H @@ -1,22 +1,5 @@ -#include "journal.h" -#include "parser.h" -#include "textual.h" -#include "binary.h" -#include "qif.h" +#include <ledger.h> #include "acconf.h" -#ifdef READ_GNUCASH -#include "gnucash.h" -#endif -#include "valexpr.h" -#include "format.h" -#include "walk.h" -#include "quotes.h" -#include "derive.h" -#include "option.h" -#include "config.h" -#include "debug.h" -#include "timing.h" -#include "error.h" using namespace ledger; @@ -31,12 +14,6 @@ using namespace ledger; #include <cstring> #include <ctime> -namespace { - TIMER_DEF(write_cache, "writing cache file"); - TIMER_DEF(report_gen, "generation of final report"); - TIMER_DEF(process_opts, "processing args and environment"); -} - #if !defined(DEBUG_LEVEL) || DEBUG_LEVEL <= RELEASE #define auto_ptr bogus_auto_ptr @@ -166,8 +143,6 @@ int parse_and_report(int argc, char * argv[], char * envp[]) // Parse command-line arguments, and those set in the environment - TIMER_START(process_opts); - std::list<std::string> args; process_arguments(config_options, argc - 1, argv + 1, false, args); @@ -195,8 +170,6 @@ int parse_and_report(int argc, char * argv[], char * envp[]) if (config.data_file == config.cache_file) config.use_cache = false; - TIMER_STOP(process_opts); - // Read the command word, canonicalize it to its one letter form, // then configure the system based on the kind of report to be // generated @@ -247,8 +220,6 @@ int parse_and_report(int argc, char * argv[], char * envp[]) // Configure the output stream - TIMER_START(report_gen); - std::ostream * out = &std::cout; if (! config.output_file.empty()) { if (access(config.output_file.c_str(), W_OK) == -1) @@ -330,12 +301,8 @@ int parse_and_report(int argc, char * argv[], char * envp[]) delete *i; #endif - TIMER_STOP(report_gen); - // Write out the binary cache, if need be - TIMER_START(write_cache); - if (config.use_cache && config.cache_dirty && ! config.cache_file.empty()) { if (access(config.cache_file.c_str(), W_OK) == -1) { @@ -347,8 +314,6 @@ int parse_and_report(int argc, char * argv[], char * envp[]) } } - TIMER_STOP(write_cache); - return 0; } @@ -431,8 +431,7 @@ unsigned int textual_parser_t::parse(std::istream& in, case '=': // automated transactions if (! added_autoxact_hook) { - add_hook<entry_finalizer_t *>(journal->entry_finalize_hooks, - &autoxact_finalizer); + journal->add_entry_finalizer(&autoxact_finalizer); added_autoxact_hook = true; } parse_automated_transactions(in, account_stack.front(), @@ -495,8 +494,8 @@ unsigned int textual_parser_t::parse(std::istream& in, done: if (added_autoxact_hook) - remove_hook<entry_finalizer_t *>(journal->entry_finalize_hooks, - &autoxact_finalizer); + journal->remove_entry_finalizer(&autoxact_finalizer); + if (time_commodity) { time_commodity->precision = 2; time_commodity->flags |= COMMODITY_STYLE_NOMARKET; |