From 5a90fe735772fd4d52216ae76ddad893bce177e6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 2 Aug 2008 22:45:35 -0400 Subject: Moved xact_xdata_t into xact_t itself, as a set of "extended data" that might be gathered during reporting. Removed the references to accounts and such from the mask logic, which means that the value expression "acount =~ /foo/" is needed in place of just "/foo/". --- xact.cc | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 12 deletions(-) (limited to 'xact.cc') diff --git a/xact.cc b/xact.cc index 8c9014f4..c6f76ebe 100644 --- a/xact.cc +++ b/xact.cc @@ -58,18 +58,39 @@ date_t xact_t::effective_date() const } namespace { - value_t get_amount(xact_t& xact) - { - return xact.amount; + value_t get_state(xact_t& xact) { + return long(xact.state); + } + + value_t state_uncleared(call_scope_t&) { + return 0L; + } + + value_t state_cleared(call_scope_t&) { + return 1L; } - value_t get_date(xact_t& xact) - { + value_t state_pending(call_scope_t&) { + return 2L; + } + + value_t get_date(xact_t& xact) { return xact.date(); } - value_t get_account(call_scope_t& scope) - { + value_t get_amount(xact_t& xact) { + return xact.amount; + } + + value_t get_cost(xact_t& xact) { + return xact.cost ? *xact.cost : xact.amount; + } + + value_t get_note(xact_t& xact) { + return string_value(xact.note ? *xact.note : ":NOTELESS:"); + } + + value_t get_account(call_scope_t& scope) { xact_t& xact(downcast(*scope.parent)); long width = 0; @@ -78,7 +99,7 @@ namespace { // jww (2008-08-02): Accept a width here so that we can abbreviate the // string. - string name = xact.account->fullname(); + string name = xact.reported_account()->fullname(); if (width > 2) name = format_t::truncate(name, width - 2, true); @@ -92,10 +113,33 @@ namespace { return string_value(name); } - value_t get_account_base(xact_t& xact) - { - assert(false); - return NULL_VALUE; + value_t get_account_base(xact_t& xact) { + return string_value(xact.reported_account()->name); + } + + value_t get_beg_pos(xact_t& xact) { + return long(xact.beg_pos); + } + + value_t get_beg_line(xact_t& xact) { + return long(xact.beg_line); + } + + value_t get_end_pos(xact_t& xact) { + return long(xact.end_pos); + } + + value_t get_end_line(xact_t& xact) { + return long(xact.end_line); + } + + // xdata_t members... + + value_t get_total(xact_t& xact) { + if (xact.xdata_) + return xact.xdata_->total; + else + return xact.amount; } template @@ -115,16 +159,33 @@ expr_t::ptr_op_t xact_t::lookup(const string& name) else if (name == "account_base") return WRAP_FUNCTOR(get_wrapper<&get_account_base>); break; + + case 'c': + if (name == "cleared") + return expr_t::op_t::wrap_value(0L); + break; + case 'd': if (name[1] == '\0' || name == "date") return WRAP_FUNCTOR(get_wrapper<&get_date>); break; + case 'f': if (name.find("fmt_") == 0) { if (name == "fmt_A") return WRAP_FUNCTOR(get_account); } break; + + case 'p': + if (name == "pending") + return expr_t::op_t::wrap_value(2L); + break; + + case 'u': + if (name == "uncleared") + return expr_t::op_t::wrap_value(1L); + break; } return entry->lookup(name); } @@ -187,4 +248,17 @@ xact_context::xact_context(const xact_t& _xact, const string& desc) throw() } #endif +void xact_t::add_to_value(value_t& value) +{ + if (xdata_ && xdata_->has_flags(XACT_EXT_COMPOUND)) { + value += xdata_->value; + } + else if (cost || (! value.is_null() && ! value.is_realzero())) { + value.add(amount, cost); + } + else { + value = amount; + } +} + } // namespace ledger -- cgit v1.2.3