From 03219d910f527b6a4c5f563aab6152145a51e0fa Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 15 Feb 2009 15:41:24 -0400 Subject: [PATCH] Added xact_t::count member This allows reports to access the "whicheth" index of the reported transaction. It's used mainly by the --average report, which divides the running total by this count to get the arithmetic mean. --- src/filters.cc | 7 ++++++- src/xact.cc | 7 +++++++ src/xact.h | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index f97e58d0..8d8589e4 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -186,8 +186,13 @@ void calc_xacts::operator()(xact_t& xact) try { xact_t::xdata_t& xdata(xact.xdata()); - if (last_xact && last_xact->has_xdata()) + if (last_xact) { + assert(last_xact->has_xdata()); add_or_set_value(xdata.total, last_xact->xdata().total); + xdata.count = last_xact->xdata().count + 1; + } else { + xdata.count = 1; + } xact.add_to_value(xdata.total, amount_expr); diff --git a/src/xact.cc b/src/xact.cc index 0e287962..b2337329 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -182,6 +182,11 @@ namespace { return xact.amount; } + value_t get_count(xact_t& xact) { + assert(xact.xdata_); + return xact.xdata_->count; + } + value_t get_account(call_scope_t& scope) { xact_t& xact(find_scope(scope)); @@ -231,6 +236,8 @@ expr_t::ptr_op_t xact_t::lookup(const string& name) return WRAP_FUNCTOR(get_wrapper<&get_code>); else if (name == "cost") return WRAP_FUNCTOR(get_wrapper<&get_cost>); + else if (name == "count") + return WRAP_FUNCTOR(get_wrapper<&get_count>); else if (name == "calculated") return WRAP_FUNCTOR(get_wrapper<&get_is_calculated>); break; diff --git a/src/xact.h b/src/xact.h index 11bd289d..b766383b 100644 --- a/src/xact.h +++ b/src/xact.h @@ -140,6 +140,7 @@ public: #define XACT_EXT_MATCHES 0x80 value_t total; + std::size_t count; value_t value; date_t date; account_t * account; @@ -147,12 +148,14 @@ public: std::list sort_values; - xdata_t() : supports_flags<>(), account(NULL), ptr(NULL) { + xdata_t() + : supports_flags<>(), count(0), account(NULL), ptr(NULL) { TRACE_CTOR(xact_t::xdata_t, ""); } xdata_t(const xdata_t& other) : supports_flags<>(other.flags()), total(other.total), + count(other.count), value(other.value), date(other.date), account(other.account),