Moved ownership of master account into journal_t
The journal_t now completely represents the data part of a session.
This commit is contained in:
parent
a3799eebdb
commit
63aa8992a8
9 changed files with 62 additions and 81 deletions
14
src/chain.cc
14
src/chain.cc
|
|
@ -223,33 +223,33 @@ post_handler_ptr chain_post_handlers(report_t& report,
|
||||||
|
|
||||||
if (report.HANDLED(set_account_))
|
if (report.HANDLED(set_account_))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::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.HANDLER(set_account_).str(),
|
||||||
report));
|
report));
|
||||||
else if (report.HANDLED(set_payee_))
|
else if (report.HANDLED(set_payee_))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::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.HANDLER(set_payee_).str(),
|
||||||
report));
|
report));
|
||||||
else if (report.HANDLED(comm_as_payee))
|
else if (report.HANDLED(comm_as_payee))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE,
|
handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE,
|
||||||
report.session.master.get(),
|
report.session.journal->master,
|
||||||
expr_t("commodity"), report));
|
expr_t("commodity"), report));
|
||||||
else if (report.HANDLED(code_as_payee))
|
else if (report.HANDLED(code_as_payee))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE,
|
handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE,
|
||||||
report.session.master.get(),
|
report.session.journal->master,
|
||||||
expr_t("code"), report));
|
expr_t("code"), report));
|
||||||
else if (report.HANDLED(payee_as_account))
|
else if (report.HANDLED(payee_as_account))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
||||||
report.session.master.get(),
|
report.session.journal->master,
|
||||||
expr_t("payee"), report));
|
expr_t("payee"), report));
|
||||||
else if (report.HANDLED(comm_as_account))
|
else if (report.HANDLED(comm_as_account))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
||||||
report.session.master.get(),
|
report.session.journal->master,
|
||||||
expr_t("commodity"), report));
|
expr_t("commodity"), report));
|
||||||
else if (report.HANDLED(code_as_account))
|
else if (report.HANDLED(code_as_account))
|
||||||
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
|
||||||
report.session.master.get(),
|
report.session.journal->master,
|
||||||
expr_t("code"), report));
|
expr_t("code"), report));
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
|
|
|
||||||
|
|
@ -435,17 +435,18 @@ void global_scope_t::normalize_report_options(const string& verb)
|
||||||
item_t::use_effective_date = (rep.HANDLED(effective) &&
|
item_t::use_effective_date = (rep.HANDLED(effective) &&
|
||||||
! rep.HANDLED(actual_dates));
|
! rep.HANDLED(actual_dates));
|
||||||
|
|
||||||
rep.session.commodity_pool->keep_base = rep.HANDLED(base);
|
rep.session.journal->commodity_pool->keep_base = rep.HANDLED(base);
|
||||||
rep.session.commodity_pool->get_quotes = rep.session.HANDLED(download);
|
rep.session.journal->commodity_pool->get_quotes = rep.session.HANDLED(download);
|
||||||
|
|
||||||
if (rep.session.HANDLED(price_exp_))
|
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();
|
rep.session.HANDLER(price_exp_).value.as_long();
|
||||||
|
|
||||||
if (rep.session.HANDLED(price_db_))
|
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
|
else
|
||||||
rep.session.commodity_pool->price_db = none;
|
rep.session.journal->commodity_pool->price_db = none;
|
||||||
|
|
||||||
if (rep.HANDLED(date_format_))
|
if (rep.HANDLED(date_format_))
|
||||||
set_date_format(rep.HANDLER(date_format_).str().c_str());
|
set_date_format(rep.HANDLER(date_format_).str().c_str());
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,34 @@
|
||||||
#include <system.hh>
|
#include <system.hh>
|
||||||
|
|
||||||
#include "journal.h"
|
#include "journal.h"
|
||||||
|
#include "amount.h"
|
||||||
|
#include "commodity.h"
|
||||||
|
#include "pool.h"
|
||||||
#include "xact.h"
|
#include "xact.h"
|
||||||
#include "account.h"
|
#include "account.h"
|
||||||
|
|
||||||
namespace ledger {
|
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()
|
journal_t::~journal_t()
|
||||||
{
|
{
|
||||||
TRACE_DTOR(journal_t);
|
TRACE_DTOR(journal_t);
|
||||||
|
|
@ -52,6 +75,9 @@ journal_t::~journal_t()
|
||||||
|
|
||||||
foreach (period_xact_t * xact, period_xacts)
|
foreach (period_xact_t * xact, period_xacts)
|
||||||
checked_delete(xact);
|
checked_delete(xact);
|
||||||
|
|
||||||
|
checked_delete(master);
|
||||||
|
commodity_pool.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void journal_t::add_account(account_t * acct)
|
void journal_t::add_account(account_t * acct)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ namespace ledger {
|
||||||
|
|
||||||
typedef std::list<path> paths_list;
|
typedef std::list<path> paths_list;
|
||||||
|
|
||||||
|
class commodity_pool_t;
|
||||||
class xact_t;
|
class xact_t;
|
||||||
class auto_xact_t;
|
class auto_xact_t;
|
||||||
class xact_finalizer_t;
|
class xact_finalizer_t;
|
||||||
|
|
@ -75,15 +76,13 @@ public:
|
||||||
account_t * master;
|
account_t * master;
|
||||||
account_t * basket;
|
account_t * basket;
|
||||||
xacts_list xacts;
|
xacts_list xacts;
|
||||||
|
|
||||||
auto_xacts_list auto_xacts;
|
auto_xacts_list auto_xacts;
|
||||||
period_xacts_list period_xacts;
|
period_xacts_list period_xacts;
|
||||||
|
|
||||||
|
shared_ptr<commodity_pool_t> commodity_pool;
|
||||||
hooks_t<xact_finalizer_t, xact_t> xact_finalize_hooks;
|
hooks_t<xact_finalizer_t, xact_t> xact_finalize_hooks;
|
||||||
|
|
||||||
journal_t(account_t * _master = NULL) : master(_master) {
|
journal_t();
|
||||||
TRACE_CTOR(journal_t, "");
|
|
||||||
}
|
|
||||||
~journal_t();
|
~journal_t();
|
||||||
|
|
||||||
// These four methods are delegated to the current session, since all
|
// These four methods are delegated to the current session, since all
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ void format_accounts::flush()
|
||||||
disp_pred.predicate.parse(report.HANDLER(display_).str());
|
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;
|
std::size_t displayed = 0;
|
||||||
|
|
||||||
|
|
@ -212,7 +212,7 @@ void format_accounts::flush()
|
||||||
|
|
||||||
if (displayed > 1 &&
|
if (displayed > 1 &&
|
||||||
! report.HANDLED(no_total) && ! report.HANDLED(percent)) {
|
! 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);
|
separator_format.format(out, bound_scope);
|
||||||
total_line_format.format(out, bound_scope);
|
total_line_format.format(out, bound_scope);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,11 +87,11 @@ void report_t::accounts_report(acct_handler_ptr handler)
|
||||||
|
|
||||||
scoped_ptr<accounts_iterator> iter;
|
scoped_ptr<accounts_iterator> iter;
|
||||||
if (! HANDLED(sort_)) {
|
if (! HANDLED(sort_)) {
|
||||||
iter.reset(new basic_accounts_iterator(*session.master));
|
iter.reset(new basic_accounts_iterator(*session.journal->master));
|
||||||
} else {
|
} else {
|
||||||
expr_t sort_expr(HANDLER(sort_).str());
|
expr_t sort_expr(HANDLER(sort_).str());
|
||||||
sort_expr.set_context(this);
|
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)));
|
sort_expr, HANDLED(flat)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,33 +32,12 @@
|
||||||
#include <system.hh>
|
#include <system.hh>
|
||||||
|
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "commodity.h"
|
|
||||||
#include "pool.h"
|
|
||||||
#include "xact.h"
|
#include "xact.h"
|
||||||
#include "account.h"
|
#include "account.h"
|
||||||
#include "journal.h"
|
#include "journal.h"
|
||||||
#include "iterators.h"
|
#include "iterators.h"
|
||||||
#include "filters.h"
|
#include "filters.h"
|
||||||
|
#include "pstream.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
|
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
|
|
@ -66,7 +45,7 @@ void set_session_context(session_t * session)
|
||||||
{
|
{
|
||||||
if (session) {
|
if (session) {
|
||||||
times_initialize();
|
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
|
// jww (2009-02-04): Is amount_t the right place for parse_conversion to
|
||||||
// happen?
|
// happen?
|
||||||
|
|
@ -84,12 +63,8 @@ void set_session_context(session_t * session)
|
||||||
|
|
||||||
session_t::session_t()
|
session_t::session_t()
|
||||||
: flush_on_next_data_file(false),
|
: flush_on_next_data_file(false),
|
||||||
|
|
||||||
current_year(CURRENT_DATE().year()),
|
current_year(CURRENT_DATE().year()),
|
||||||
|
journal(new journal_t)
|
||||||
commodity_pool(new commodity_pool_t),
|
|
||||||
master(new account_t),
|
|
||||||
journal(new journal_t(master.get()))
|
|
||||||
{
|
{
|
||||||
TRACE_CTOR(session_t, "");
|
TRACE_CTOR(session_t, "");
|
||||||
|
|
||||||
|
|
@ -97,19 +72,6 @@ session_t::session_t()
|
||||||
HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string());
|
HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string());
|
||||||
else
|
else
|
||||||
HANDLER(price_db_).on(none, path("./.pricedb").string());
|
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,
|
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()
|
void session_t::close_journal_files()
|
||||||
{
|
{
|
||||||
journal.reset();
|
journal.reset();
|
||||||
master.reset();
|
|
||||||
commodity_pool.reset();
|
|
||||||
amount_t::shutdown();
|
amount_t::shutdown();
|
||||||
|
|
||||||
commodity_pool.reset(new commodity_pool_t);
|
journal.reset(new journal_t);
|
||||||
amount_t::initialize(commodity_pool);
|
amount_t::initialize(journal->commodity_pool);
|
||||||
master.reset(new account_t);
|
|
||||||
journal.reset(new journal_t(master.get()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_t::clean_posts()
|
void session_t::clean_posts()
|
||||||
|
|
@ -244,9 +202,9 @@ void session_t::clean_posts(xact_t& xact)
|
||||||
|
|
||||||
void session_t::clean_accounts()
|
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);
|
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)
|
option_t<session_t> * session_t::lookup_option(const char * p)
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,7 @@ class session_t : public symbol_scope_t
|
||||||
public:
|
public:
|
||||||
bool flush_on_next_data_file;
|
bool flush_on_next_data_file;
|
||||||
date_t::year_type current_year;
|
date_t::year_type current_year;
|
||||||
|
shared_ptr<journal_t> journal;
|
||||||
shared_ptr<commodity_pool_t> commodity_pool;
|
|
||||||
scoped_ptr<account_t> master;
|
|
||||||
scoped_ptr<journal_t> journal;
|
|
||||||
|
|
||||||
explicit session_t();
|
explicit session_t();
|
||||||
virtual ~session_t() {
|
virtual ~session_t() {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ value_t report_statistics(call_scope_t& args)
|
||||||
std::ostream& out(report.output_stream);
|
std::ostream& out(report.output_stream);
|
||||||
|
|
||||||
const account_t::xdata_t::details_t&
|
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) &&
|
if (! is_valid(statistics.earliest_post) &&
|
||||||
! is_valid(statistics.latest_post))
|
! is_valid(statistics.latest_post))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue