Removed the global references to session->report.
This commit is contained in:
parent
3434650848
commit
43c4636d9d
10 changed files with 34 additions and 32 deletions
|
|
@ -197,7 +197,7 @@ expr_t::ptr_op_t account_t::lookup(const string& name)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return session_t::current->report->lookup(name);
|
return session_t::current->global_scope->lookup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool account_t::valid() const
|
bool account_t::valid() const
|
||||||
|
|
@ -222,12 +222,12 @@ bool account_t::valid() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void account_t::calculate_sums()
|
void account_t::calculate_sums(expr_t& amount_expr)
|
||||||
{
|
{
|
||||||
xdata_t& xd(xdata());
|
xdata_t& xd(xdata());
|
||||||
|
|
||||||
foreach (accounts_map::value_type& pair, accounts) {
|
foreach (accounts_map::value_type& pair, accounts) {
|
||||||
(*pair.second).calculate_sums();
|
(*pair.second).calculate_sums(amount_expr);
|
||||||
|
|
||||||
xdata_t& child_xd((*pair.second).xdata());
|
xdata_t& child_xd((*pair.second).xdata());
|
||||||
if (! child_xd.total.is_null()) {
|
if (! child_xd.total.is_null()) {
|
||||||
|
|
@ -240,7 +240,7 @@ void account_t::calculate_sums()
|
||||||
}
|
}
|
||||||
|
|
||||||
call_scope_t args(*this);
|
call_scope_t args(*this);
|
||||||
value_t amount(session_t::current->report->get_amount_expr(args));
|
value_t amount(amount_expr.calc(args));
|
||||||
if (! amount.is_null()) {
|
if (! amount.is_null()) {
|
||||||
add_or_set_value(xd.total, amount);
|
add_or_set_value(xd.total, amount);
|
||||||
xd.total_count += xd.count;
|
xd.total_count += xd.count;
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ class account_t : public scope_t
|
||||||
return *xdata_;
|
return *xdata_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculate_sums();
|
void calculate_sums(expr_t& amount_expr);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const account_t& account);
|
std::ostream& operator<<(std::ostream& out, const account_t& account);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
|
bool item_t::use_effective_date = false;
|
||||||
|
|
||||||
bool item_t::has_tag(const string& tag) const
|
bool item_t::has_tag(const string& tag) const
|
||||||
{
|
{
|
||||||
if (! metadata)
|
if (! metadata)
|
||||||
|
|
@ -224,7 +226,7 @@ value_t get_comment(item_t& item)
|
||||||
|
|
||||||
optional<date_t> item_t::date() const
|
optional<date_t> item_t::date() const
|
||||||
{
|
{
|
||||||
if (session_t::current->report->use_effective_date && _date_eff)
|
if (use_effective_date && _date_eff)
|
||||||
return effective_date();
|
return effective_date();
|
||||||
else
|
else
|
||||||
return actual_date();
|
return actual_date();
|
||||||
|
|
@ -293,7 +295,7 @@ expr_t::ptr_op_t item_t::lookup(const string& name)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return session_t::current->report->lookup(name);
|
return session_t::current->global_scope->lookup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool item_t::valid() const
|
bool item_t::valid() const
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ public:
|
||||||
std::size_t full_end_line;
|
std::size_t full_end_line;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool use_effective_date;
|
||||||
|
|
||||||
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
|
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
|
||||||
: supports_flags<>(_flags),
|
: supports_flags<>(_flags),
|
||||||
_state(UNCLEARED), note(_note), journal(NULL), src_idx(0),
|
_state(UNCLEARED), note(_note), journal(NULL), src_idx(0),
|
||||||
|
|
|
||||||
31
src/main.cc
31
src/main.cc
|
|
@ -39,6 +39,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
using namespace ledger;
|
using namespace ledger;
|
||||||
|
|
||||||
session_t * session = NULL;
|
session_t * session = NULL;
|
||||||
|
report_t * report = NULL;
|
||||||
int status = 1;
|
int status = 1;
|
||||||
try {
|
try {
|
||||||
// The very first thing we do is handle some very special command-line
|
// The very first thing we do is handle some very special command-line
|
||||||
|
|
@ -67,8 +68,8 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
// between session and report doesn't really matter, but if a GUI were
|
// between session and report doesn't really matter, but if a GUI were
|
||||||
// calling into Ledger it would have one session object per open document,
|
// calling into Ledger it would have one session object per open document,
|
||||||
// with a separate report_t object for each report it generated.
|
// with a separate report_t object for each report it generated.
|
||||||
session->report.reset(new report_t(*session));
|
report = new report_t(*session);
|
||||||
report_t& report(*session->report.get());
|
session->global_scope = report;
|
||||||
|
|
||||||
// Read the user's options, in the following order:
|
// Read the user's options, in the following order:
|
||||||
//
|
//
|
||||||
|
|
@ -79,10 +80,10 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
// Before processing command-line options, we must notify the session
|
// Before processing command-line options, we must notify the session
|
||||||
// object that such options are beginning, since options like -f cause a
|
// object that such options are beginning, since options like -f cause a
|
||||||
// complete override of files found anywhere else.
|
// complete override of files found anywhere else.
|
||||||
read_environment_settings(report, envp);
|
read_environment_settings(*report, envp);
|
||||||
session->read_init(); // accesses report object via session.report
|
session->read_init();
|
||||||
session->now_at_command_line(true);
|
session->now_at_command_line(true);
|
||||||
strings_list args = read_command_line_arguments(report, argc, argv);
|
strings_list args = read_command_line_arguments(*report, argc, argv);
|
||||||
|
|
||||||
// Look for a precommand first, which is defined as any defined function
|
// Look for a precommand first, which is defined as any defined function
|
||||||
// whose name starts with "ledger_precmd_". The difference between a
|
// whose name starts with "ledger_precmd_". The difference between a
|
||||||
|
|
@ -100,21 +101,21 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
string_iterator arg = args.begin();
|
string_iterator arg = args.begin();
|
||||||
string verb = *arg++;
|
string verb = *arg++;
|
||||||
|
|
||||||
if (function_t command = look_for_precommand(report, verb)) {
|
if (function_t command = look_for_precommand(*report, verb)) {
|
||||||
// Create the output stream (it might be a file, the console or a PAGER
|
// Create the output stream (it might be a file, the console or a PAGER
|
||||||
// subprocess) and invoke the report command.
|
// subprocess) and invoke the report command.
|
||||||
create_output_stream(report);
|
create_output_stream(*report);
|
||||||
invoke_command_verb(report, command, arg, args.end());
|
invoke_command_verb(*report, command, arg, args.end());
|
||||||
}
|
}
|
||||||
else if (function_t command = look_for_command(report, verb)) {
|
else if (function_t command = look_for_command(*report, verb)) {
|
||||||
// This is regular command verb, so parse the user's data.
|
// This is regular command verb, so parse the user's data.
|
||||||
if (journal_t * journal = read_journal_files(*session)) {
|
if (journal_t * journal = read_journal_files(*session, report->account)) {
|
||||||
normalize_report_options(report, verb); // jww (2009-02-02): a hack
|
normalize_report_options(*report, verb); // jww (2009-02-02): a hack
|
||||||
|
|
||||||
// Create the output stream (it might be a file, the console or a
|
// Create the output stream (it might be a file, the console or a
|
||||||
// PAGER subprocess) and invoke the report command.
|
// PAGER subprocess) and invoke the report command.
|
||||||
create_output_stream(report);
|
create_output_stream(*report);
|
||||||
invoke_command_verb(report, command, arg, args.end());
|
invoke_command_verb(*report, command, arg, args.end());
|
||||||
|
|
||||||
// Write out a binary cache of the journal data, if needful and
|
// Write out a binary cache of the journal data, if needful and
|
||||||
// appropriate to do so.
|
// appropriate to do so.
|
||||||
|
|
@ -146,7 +147,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the output stream, waiting on the pager process to exit if need be
|
// Close the output stream, waiting on the pager process to exit if need be
|
||||||
session->report->output_stream.close();
|
report->output_stream.close();
|
||||||
|
|
||||||
// If memory verification is being performed (which can be very slow), clean
|
// If memory verification is being performed (which can be very slow), clean
|
||||||
// up everything by closing the session and deleting the session object, and
|
// up everything by closing the session and deleting the session object, and
|
||||||
|
|
@ -156,6 +157,8 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
set_session_context(NULL);
|
set_session_context(NULL);
|
||||||
if (session != NULL)
|
if (session != NULL)
|
||||||
checked_delete(session);
|
checked_delete(session);
|
||||||
|
if (report != NULL)
|
||||||
|
checked_delete(report);
|
||||||
|
|
||||||
INFO("Ledger ended (Boost/libstdc++ may still hold memory)");
|
INFO("Ledger ended (Boost/libstdc++ may still hold memory)");
|
||||||
shutdown_memory_tracing();
|
shutdown_memory_tracing();
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ void report_t::sum_all_accounts()
|
||||||
pass_down_xacts
|
pass_down_xacts
|
||||||
(chain_xact_handlers(*this, xact_handler_ptr(new set_account_value), false),
|
(chain_xact_handlers(*this, xact_handler_ptr(new set_account_value), false),
|
||||||
walker);
|
walker);
|
||||||
session.master->calculate_sums();
|
session.master->calculate_sums(amount_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void report_t::accounts_report(acct_handler_ptr handler)
|
void report_t::accounts_report(acct_handler_ptr handler)
|
||||||
|
|
|
||||||
|
|
@ -149,8 +149,6 @@ public:
|
||||||
bool entry_sort;
|
bool entry_sort;
|
||||||
bool sort_all;
|
bool sort_all;
|
||||||
bool anonymize;
|
bool anonymize;
|
||||||
bool use_effective_date;
|
|
||||||
|
|
||||||
|
|
||||||
string account;
|
string account;
|
||||||
optional<path> pager_path;
|
optional<path> pager_path;
|
||||||
|
|
@ -186,7 +184,6 @@ public:
|
||||||
entry_sort(false),
|
entry_sort(false),
|
||||||
sort_all(false),
|
sort_all(false),
|
||||||
anonymize(false),
|
anonymize(false),
|
||||||
use_effective_date(false),
|
|
||||||
|
|
||||||
raw_mode(false),
|
raw_mode(false),
|
||||||
|
|
||||||
|
|
@ -277,7 +274,7 @@ public:
|
||||||
// Report filtering
|
// Report filtering
|
||||||
|
|
||||||
value_t option_effective(call_scope_t& args) {
|
value_t option_effective(call_scope_t& args) {
|
||||||
use_effective_date = true;
|
item_t::use_effective_date = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,6 @@
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
class report_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Brief
|
* @brief Brief
|
||||||
*
|
*
|
||||||
|
|
@ -71,7 +69,7 @@ class session_t : public noncopyable, public scope_t
|
||||||
public:
|
public:
|
||||||
static session_t * current;
|
static session_t * current;
|
||||||
|
|
||||||
scoped_ptr<report_t> report;
|
scope_t * global_scope;
|
||||||
|
|
||||||
std::list<path> data_files;
|
std::list<path> data_files;
|
||||||
bool next_data_file_from_command_line;
|
bool next_data_file_from_command_line;
|
||||||
|
|
|
||||||
|
|
@ -148,13 +148,13 @@ function_t look_for_precommand(report_t& report, const string& verb)
|
||||||
return function_t();
|
return function_t();
|
||||||
}
|
}
|
||||||
|
|
||||||
journal_t * read_journal_files(session_t& session)
|
journal_t * read_journal_files(session_t& session, const string& account)
|
||||||
{
|
{
|
||||||
INFO_START(journal, "Read journal file");
|
INFO_START(journal, "Read journal file");
|
||||||
|
|
||||||
journal_t * journal(session.create_journal());
|
journal_t * journal(session.create_journal());
|
||||||
|
|
||||||
std::size_t count = session.read_data(*journal, session.report->account);
|
std::size_t count = session.read_data(*journal, account);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
throw_(parse_error, "Failed to locate any journal entries; "
|
throw_(parse_error, "Failed to locate any journal entries; "
|
||||||
"did you specify a valid file with -f?");
|
"did you specify a valid file with -f?");
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ strings_list read_command_line_arguments(report_t& report,
|
||||||
int argc, char * argv[]);
|
int argc, char * argv[]);
|
||||||
void normalize_session_options(session_t& session);
|
void normalize_session_options(session_t& session);
|
||||||
function_t look_for_precommand(report_t& report, const string& verb);
|
function_t look_for_precommand(report_t& report, const string& verb);
|
||||||
journal_t * read_journal_files(session_t& session);
|
journal_t * read_journal_files(session_t& session, const string& account);
|
||||||
function_t look_for_command(report_t& report, const string& verb);
|
function_t look_for_command(report_t& report, const string& verb);
|
||||||
void normalize_report_options(report_t& report, const string& verb);
|
void normalize_report_options(report_t& report, const string& verb);
|
||||||
void create_output_stream(report_t& report);
|
void create_output_stream(report_t& report);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue