diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-30 19:03:23 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-30 19:03:28 -0400 |
commit | 63aa8992a81dfaececa4a9b38ba8daf29b57912e (patch) | |
tree | 808871837734f3779c369e71774f30fde7d89034 | |
parent | a3799eebdb682162eb1edb3706a6ff1097b12f41 (diff) | |
download | fork-ledger-63aa8992a81dfaececa4a9b38ba8daf29b57912e.tar.gz fork-ledger-63aa8992a81dfaececa4a9b38ba8daf29b57912e.tar.bz2 fork-ledger-63aa8992a81dfaececa4a9b38ba8daf29b57912e.zip |
Moved ownership of master account into journal_t
The journal_t now completely represents the data part of a session.
-rw-r--r-- | src/chain.cc | 14 | ||||
-rw-r--r-- | src/global.cc | 11 | ||||
-rw-r--r-- | src/journal.cc | 26 | ||||
-rw-r--r-- | src/journal.h | 17 | ||||
-rw-r--r-- | src/output.cc | 4 | ||||
-rw-r--r-- | src/report.cc | 4 | ||||
-rw-r--r-- | src/session.cc | 56 | ||||
-rw-r--r-- | src/session.h | 9 | ||||
-rw-r--r-- | src/stats.cc | 2 |
9 files changed, 62 insertions, 81 deletions
diff --git a/src/chain.cc b/src/chain.cc index 018b3812..d7d1460b 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -223,33 +223,33 @@ post_handler_ptr chain_post_handlers(report_t& report, if (report.HANDLED(set_account_)) handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, - report.session.master.get(), + report.session.journal->master, report.HANDLER(set_account_).str(), report)); else if (report.HANDLED(set_payee_)) handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, - report.session.master.get(), + report.session.journal->master, report.HANDLER(set_payee_).str(), report)); else if (report.HANDLED(comm_as_payee)) handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, - report.session.master.get(), + report.session.journal->master, expr_t("commodity"), report)); else if (report.HANDLED(code_as_payee)) handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, - report.session.master.get(), + report.session.journal->master, expr_t("code"), report)); else if (report.HANDLED(payee_as_account)) handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, - report.session.master.get(), + report.session.journal->master, expr_t("payee"), report)); else if (report.HANDLED(comm_as_account)) handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, - report.session.master.get(), + report.session.journal->master, expr_t("commodity"), report)); else if (report.HANDLED(code_as_account)) handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, - report.session.master.get(), + report.session.journal->master, expr_t("code"), report)); return handler; diff --git a/src/global.cc b/src/global.cc index 8204bf69..a26d4cd1 100644 --- a/src/global.cc +++ b/src/global.cc @@ -435,17 +435,18 @@ void global_scope_t::normalize_report_options(const string& verb) item_t::use_effective_date = (rep.HANDLED(effective) && ! rep.HANDLED(actual_dates)); - rep.session.commodity_pool->keep_base = rep.HANDLED(base); - rep.session.commodity_pool->get_quotes = rep.session.HANDLED(download); + rep.session.journal->commodity_pool->keep_base = rep.HANDLED(base); + rep.session.journal->commodity_pool->get_quotes = rep.session.HANDLED(download); if (rep.session.HANDLED(price_exp_)) - rep.session.commodity_pool->quote_leeway = + rep.session.journal->commodity_pool->quote_leeway = rep.session.HANDLER(price_exp_).value.as_long(); if (rep.session.HANDLED(price_db_)) - rep.session.commodity_pool->price_db = rep.session.HANDLER(price_db_).str(); + rep.session.journal->commodity_pool->price_db = + rep.session.HANDLER(price_db_).str(); else - rep.session.commodity_pool->price_db = none; + rep.session.journal->commodity_pool->price_db = none; if (rep.HANDLED(date_format_)) set_date_format(rep.HANDLER(date_format_).str().c_str()); diff --git a/src/journal.cc b/src/journal.cc index fdb49e24..d73d0fb8 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -32,11 +32,34 @@ #include <system.hh> #include "journal.h" +#include "amount.h" +#include "commodity.h" +#include "pool.h" #include "xact.h" #include "account.h" namespace ledger { +journal_t::journal_t() + : master(new account_t), + commodity_pool(new commodity_pool_t) +{ + TRACE_CTOR(journal_t, ""); + + // Add time commodity conversions, so that timelog's may be parsed + // in terms of seconds, but reported as minutes or hours. + if (commodity_t * commodity = commodity_pool->create("s")) + commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); + else + assert(false); + + // Add a "percentile" commodity + if (commodity_t * commodity = commodity_pool->create("%")) + commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); + else + assert(false); +} + journal_t::~journal_t() { TRACE_DTOR(journal_t); @@ -52,6 +75,9 @@ journal_t::~journal_t() foreach (period_xact_t * xact, period_xacts) checked_delete(xact); + + checked_delete(master); + commodity_pool.reset(); } void journal_t::add_account(account_t * acct) diff --git a/src/journal.h b/src/journal.h index 809da25d..4ad10fd3 100644 --- a/src/journal.h +++ b/src/journal.h @@ -53,6 +53,7 @@ namespace ledger { typedef std::list<path> paths_list; +class commodity_pool_t; class xact_t; class auto_xact_t; class xact_finalizer_t; @@ -72,18 +73,16 @@ typedef std::list<period_xact_t *> period_xacts_list; class journal_t : public noncopyable { public: - account_t * master; - account_t * basket; - xacts_list xacts; - - auto_xacts_list auto_xacts; - period_xacts_list period_xacts; + account_t * master; + account_t * basket; + xacts_list xacts; + auto_xacts_list auto_xacts; + period_xacts_list period_xacts; + shared_ptr<commodity_pool_t> commodity_pool; hooks_t<xact_finalizer_t, xact_t> xact_finalize_hooks; - journal_t(account_t * _master = NULL) : master(_master) { - TRACE_CTOR(journal_t, ""); - } + journal_t(); ~journal_t(); // These four methods are delegated to the current session, since all diff --git a/src/output.cc b/src/output.cc index 371319bd..e2bbb7ec 100644 --- a/src/output.cc +++ b/src/output.cc @@ -203,7 +203,7 @@ void format_accounts::flush() disp_pred.predicate.parse(report.HANDLER(display_).str()); } - mark_accounts(*report.session.master, report.HANDLED(flat)); + mark_accounts(*report.session.journal->master, report.HANDLED(flat)); std::size_t displayed = 0; @@ -212,7 +212,7 @@ void format_accounts::flush() if (displayed > 1 && ! report.HANDLED(no_total) && ! report.HANDLED(percent)) { - bind_scope_t bound_scope(report, *report.session.master); + bind_scope_t bound_scope(report, *report.session.journal->master); separator_format.format(out, bound_scope); total_line_format.format(out, bound_scope); } diff --git a/src/report.cc b/src/report.cc index 8628cac7..bc0680d1 100644 --- a/src/report.cc +++ b/src/report.cc @@ -87,11 +87,11 @@ void report_t::accounts_report(acct_handler_ptr handler) scoped_ptr<accounts_iterator> iter; if (! HANDLED(sort_)) { - iter.reset(new basic_accounts_iterator(*session.master)); + iter.reset(new basic_accounts_iterator(*session.journal->master)); } else { expr_t sort_expr(HANDLER(sort_).str()); sort_expr.set_context(this); - iter.reset(new sorted_accounts_iterator(*session.master.get(), + iter.reset(new sorted_accounts_iterator(*session.journal->master, sort_expr, HANDLED(flat))); } diff --git a/src/session.cc b/src/session.cc index 5caf7a61..ad735976 100644 --- a/src/session.cc +++ b/src/session.cc @@ -32,33 +32,12 @@ #include <system.hh> #include "session.h" -#include "commodity.h" -#include "pool.h" #include "xact.h" #include "account.h" #include "journal.h" #include "iterators.h" #include "filters.h" - -#if defined(HAVE_BOOST_SERIALIZATION) -//BOOST_IS_ABSTRACT(ledger::scope_t) -BOOST_CLASS_EXPORT(ledger::scope_t) -BOOST_CLASS_EXPORT(ledger::child_scope_t) -BOOST_CLASS_EXPORT(ledger::symbol_scope_t) -BOOST_CLASS_EXPORT(ledger::call_scope_t) -BOOST_CLASS_EXPORT(ledger::account_t) -BOOST_CLASS_EXPORT(ledger::item_t) -BOOST_CLASS_EXPORT(ledger::post_t) -BOOST_CLASS_EXPORT(ledger::xact_base_t) -BOOST_CLASS_EXPORT(ledger::xact_t) -BOOST_CLASS_EXPORT(ledger::auto_xact_t) -BOOST_CLASS_EXPORT(ledger::period_xact_t) - -template void ledger::journal_t::serialize(boost::archive::binary_oarchive&, - const unsigned int); -template void ledger::journal_t::serialize(boost::archive::binary_iarchive&, - const unsigned int); -#endif // HAVE_BOOST_SERIALIZATION +#include "pstream.h" namespace ledger { @@ -66,7 +45,7 @@ void set_session_context(session_t * session) { if (session) { times_initialize(); - amount_t::initialize(session->commodity_pool); + amount_t::initialize(session->journal->commodity_pool); // jww (2009-02-04): Is amount_t the right place for parse_conversion to // happen? @@ -84,12 +63,8 @@ void set_session_context(session_t * session) session_t::session_t() : flush_on_next_data_file(false), - current_year(CURRENT_DATE().year()), - - commodity_pool(new commodity_pool_t), - master(new account_t), - journal(new journal_t(master.get())) + journal(new journal_t) { TRACE_CTOR(session_t, ""); @@ -97,19 +72,6 @@ session_t::session_t() HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string()); else HANDLER(price_db_).on(none, path("./.pricedb").string()); - - // Add time commodity conversions, so that timelog's may be parsed - // in terms of seconds, but reported as minutes or hours. - if (commodity_t * commodity = commodity_pool->create("s")) - commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); - else - assert(false); - - // Add a "percentile" commodity - if (commodity_t * commodity = commodity_pool->create("%")) - commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); - else - assert(false); } std::size_t session_t::read_journal(std::istream& in, @@ -220,14 +182,10 @@ void session_t::read_journal_files() void session_t::close_journal_files() { journal.reset(); - master.reset(); - commodity_pool.reset(); amount_t::shutdown(); - commodity_pool.reset(new commodity_pool_t); - amount_t::initialize(commodity_pool); - master.reset(new account_t); - journal.reset(new journal_t(master.get())); + journal.reset(new journal_t); + amount_t::initialize(journal->commodity_pool); } void session_t::clean_posts() @@ -244,9 +202,9 @@ void session_t::clean_posts(xact_t& xact) void session_t::clean_accounts() { - basic_accounts_iterator acct_walker(*master); + basic_accounts_iterator acct_walker(*journal->master); pass_down_accounts(acct_handler_ptr(new clear_account_xdata), acct_walker); - master->clear_xdata(); + journal->master->clear_xdata(); } option_t<session_t> * session_t::lookup_option(const char * p) diff --git a/src/session.h b/src/session.h index 4955053d..48960745 100644 --- a/src/session.h +++ b/src/session.h @@ -66,12 +66,9 @@ class session_t : public symbol_scope_t friend void set_session_context(session_t * session); public: - bool flush_on_next_data_file; - date_t::year_type current_year; - - shared_ptr<commodity_pool_t> commodity_pool; - scoped_ptr<account_t> master; - scoped_ptr<journal_t> journal; + bool flush_on_next_data_file; + date_t::year_type current_year; + shared_ptr<journal_t> journal; explicit session_t(); virtual ~session_t() { diff --git a/src/stats.cc b/src/stats.cc index 5bb97fd1..6f0e21f4 100644 --- a/src/stats.cc +++ b/src/stats.cc @@ -46,7 +46,7 @@ value_t report_statistics(call_scope_t& args) std::ostream& out(report.output_stream); const account_t::xdata_t::details_t& - statistics(report.session.master->family_details(true)); + statistics(report.session.journal->master->family_details(true)); if (! is_valid(statistics.earliest_post) && ! is_valid(statistics.latest_post)) |