summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-15 15:41:24 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-15 15:41:24 -0400
commit03219d910f527b6a4c5f563aab6152145a51e0fa (patch)
tree8ed61d455944fce36caa566de5a9492d749cade0
parent36b96c47ac79fd124d1ba4f53b4721179782985f (diff)
downloadfork-ledger-03219d910f527b6a4c5f563aab6152145a51e0fa.tar.gz
fork-ledger-03219d910f527b6a4c5f563aab6152145a51e0fa.tar.bz2
fork-ledger-03219d910f527b6a4c5f563aab6152145a51e0fa.zip
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.
-rw-r--r--src/filters.cc7
-rw-r--r--src/xact.cc7
-rw-r--r--src/xact.h5
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<xact_t>(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_value_t> 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),