From 3038b7cee82bd7db5f19827a7db12aa7524438f3 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 24 Sep 2004 04:56:46 -0400 Subject: finalizer fixes; removed use of timing.h from main.cc --- journal.cc | 7 +++---- journal.h | 14 ++++++++++---- ledger.h | 9 ++------- main.cc | 37 +------------------------------------ textual.cc | 7 +++---- 5 files changed, 19 insertions(+), 55 deletions(-) diff --git a/journal.cc b/journal.cc index 4166d45e..40454b28 100644 --- a/journal.cc +++ b/journal.cc @@ -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_finalizers; void py_add_entry_finalizer(journal_t& journal, object x) { py_finalizers.push_back(py_entry_finalizer_t(x)); - add_hook(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(journal.entry_finalize_hooks, &(*i)); + journal.remove_entry_finalizer(&(*i)); + py_finalizers.erase(i); return; } } diff --git a/journal.h b/journal.h index 30271f6a..0e645064 100644 --- a/journal.h +++ b/journal.h @@ -227,14 +227,13 @@ class journal_t mutable accounts_map accounts_cache; + func_finalizer_t default_finalizer; std::list 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_finalize_hooks, finalizer); + } + void remove_entry_finalizer(entry_finalizer_t * finalizer) { + remove_hook(entry_finalize_hooks, finalizer); + } + bool valid() const; }; diff --git a/ledger.h b/ledger.h index 94488ea4..6121b74f 100644 --- a/ledger.h +++ b/ledger.h @@ -21,7 +21,8 @@ #include #include #include - +#include +#include #include #include @@ -29,13 +30,7 @@ #include #include #include -#ifdef READ_GNUCASH #include -#endif #include -#include -#include -#include - #endif // _LEDGER_H diff --git a/main.cc b/main.cc index 69efce73..9ce6fa0d 100644 --- a/main.cc +++ b/main.cc @@ -1,22 +1,5 @@ -#include "journal.h" -#include "parser.h" -#include "textual.h" -#include "binary.h" -#include "qif.h" +#include #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 #include -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 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; } diff --git a/textual.cc b/textual.cc index ac205441..1916860a 100644 --- a/textual.cc +++ b/textual.cc @@ -431,8 +431,7 @@ unsigned int textual_parser_t::parse(std::istream& in, case '=': // automated transactions if (! added_autoxact_hook) { - add_hook(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(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; -- cgit v1.2.3