summaryrefslogtreecommitdiff
path: root/src/account.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-06 00:26:30 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-06 00:27:29 -0400
commit2728e4d55e1c9e84ee5aae4ee8e9c380198d1c99 (patch)
tree5b5e8207db2a37684b2527acad7bccdd770fc1a4 /src/account.h
parentdd23edd5cee8e712e13a3b5eefffcc3c57bf9e10 (diff)
downloadfork-ledger-2728e4d55e1c9e84ee5aae4ee8e9c380198d1c99.tar.gz
fork-ledger-2728e4d55e1c9e84ee5aae4ee8e9c380198d1c99.tar.bz2
fork-ledger-2728e4d55e1c9e84ee5aae4ee8e9c380198d1c99.zip
Changed the way that account balances are computed
Diffstat (limited to 'src/account.h')
-rw-r--r--src/account.h79
1 files changed, 70 insertions, 9 deletions
diff --git a/src/account.h b/src/account.h
index dd7ac3d6..f161a11f 100644
--- a/src/account.h
+++ b/src/account.h
@@ -50,9 +50,12 @@
namespace ledger {
-class account_t;
class session_t;
+class account_t;
+class xact_t;
+class post_t;
+typedef std::deque<post_t *> posts_deque;
typedef std::map<const string, account_t *> accounts_map;
/**
@@ -68,14 +71,15 @@ class account_t : public scope_t
optional<string> note;
unsigned short depth;
accounts_map accounts;
+ posts_deque posts;
bool known;
mutable void * data;
mutable string _fullname;
- account_t(account_t * _parent = NULL,
- const string& _name = "",
- const optional<string>& _note = none)
+ account_t(account_t * _parent = NULL,
+ const string& _name = "",
+ const optional<string>& _note = none)
: scope_t(), parent(_parent), name(_name), note(_note),
depth(static_cast<unsigned short>(parent ? parent->depth + 1 : 0)),
known(false), data(NULL) {
@@ -112,6 +116,10 @@ class account_t : public scope_t
account_t * find_account(const string& name, bool auto_create = true);
account_t * find_account_re(const string& regexp);
+ void add_post(post_t * post) {
+ posts.push_back(post);
+ }
+
virtual expr_t::ptr_op_t lookup(const string& name);
bool valid() const;
@@ -130,14 +138,61 @@ class account_t : public scope_t
struct details_t
{
- value_t total;
+ value_t total;
+ bool calculated;
+ bool gathered;
+
+ // The following are only calculated if --totals is enabled
+ std::size_t xacts_count;
+
+ std::size_t posts_count;
+ std::size_t posts_virtuals_count;
+ std::size_t posts_cleared_count;
+ std::size_t posts_last_7_count;
+ std::size_t posts_last_30_count;
+ std::size_t posts_this_month_count;
+
+ date_t earliest_post;
+ date_t earliest_cleared_post;
+ date_t latest_post;
+ date_t latest_cleared_post;
+
+ xact_t * last_xact;
+ post_t * last_post;
+
+ std::size_t last_size;
- std::size_t posts_count;
- std::size_t posts_virtuals_count;
+ // The following are only calculated if --gather is enabled
+ std::set<path> filenames;
+ std::set<string> accounts_referenced;
+ std::set<string> payees_referenced;
details_t()
- : posts_count(0),
- posts_virtuals_count(0) {}
+ : calculated(false),
+ gathered(false),
+
+ xacts_count(0),
+
+ posts_count(0),
+ posts_virtuals_count(0),
+ posts_cleared_count(0),
+ posts_last_7_count(0),
+ posts_last_30_count(0),
+ posts_this_month_count(0),
+
+ earliest_post(0),
+ earliest_cleared_post(0),
+ latest_post(0),
+ latest_cleared_post(0),
+
+ last_xact(NULL),
+ last_post(NULL),
+
+ last_size(0) {}
+
+ details_t& operator+=(const details_t& other);
+
+ void update(post_t& post, bool gather_all = false);
};
details_t self_details;
@@ -185,6 +240,12 @@ class account_t : public scope_t
return *xdata_;
}
+ value_t self_total(const optional<expr_t&>& expr = none) const;
+ value_t family_total(const optional<expr_t&>& expr = none) const;
+
+ const xdata_t::details_t& self_details(bool gather_all = true) const;
+ const xdata_t::details_t& family_details(bool gather_all = true) const;
+
bool has_flags(xdata_t::flags_t flags) const {
return xdata_ && xdata_->has_flags(flags);
}