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