summaryrefslogtreecommitdiff
path: root/src/account.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-04-26 16:39:25 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-04-26 16:39:25 -0500
commit64a9b42381c26baf24e58b40f50f0b253e551811 (patch)
tree5447a29dff64c3a8b7be8100a01bcb4a2d73b0bb /src/account.cc
parent7cc550fc22357e2ded194d3e65287c6b3317f5ae (diff)
parentb4407c10c0071365322b2963747bf42a57fd7304 (diff)
downloadfork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.gz
fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.bz2
fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.zip
Merge branch 'release/v3.0.0-20120426'
Diffstat (limited to 'src/account.cc')
-rw-r--r--src/account.cc66
1 files changed, 59 insertions, 7 deletions
diff --git a/src/account.cc b/src/account.cc
index e201be64..206e2350 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2010, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -89,9 +89,13 @@ account_t * account_t::find_account(const string& acct_name,
if (has_flags(ACCOUNT_GENERATED))
account->add_flags(ACCOUNT_GENERATED);
- std::pair<accounts_map::iterator, bool> result
- = accounts.insert(accounts_map::value_type(first, account));
+#if defined(DEBUG_ON)
+ std::pair<accounts_map::iterator, bool> result =
+#endif
+ accounts.insert(accounts_map::value_type(first, account));
+#if defined(DEBUG_ON)
assert(result.second);
+#endif
} else {
account = (*i).second;
}
@@ -137,7 +141,10 @@ void account_t::add_post(post_t * post)
bool account_t::remove_post(post_t * post)
{
- assert(! posts.empty());
+ // It's possible that 'post' wasn't yet in this account, but try to
+ // remove it anyway. This can happen if there is an error during
+ // parsing, when the posting knows what it's account is, but
+ // xact_t::finalize has not yet added that posting to the account.
posts.remove(post);
post->account = NULL;
return true;
@@ -243,6 +250,10 @@ namespace {
return long(account.depth);
}
+ value_t get_note(account_t& account) {
+ return account.note ? string_value(*account.note) : NULL_VALUE;
+ }
+
value_t ignore(account_t&) {
return false;
}
@@ -279,6 +290,26 @@ namespace {
return account.self_details().latest_cleared_post;
}
+ value_t get_earliest(account_t& account)
+ {
+ return account.self_details().earliest_post;
+ }
+ value_t get_earliest_checkin(account_t& account)
+ {
+ return (! account.self_details().earliest_checkin.is_not_a_date_time() ?
+ value_t(account.self_details().earliest_checkin) : NULL_VALUE);
+ }
+
+ value_t get_latest(account_t& account)
+ {
+ return account.self_details().latest_post;
+ }
+ value_t get_latest_checkout(account_t& account)
+ {
+ return (! account.self_details().latest_checkout.is_not_a_date_time() ?
+ value_t(account.self_details().latest_checkout) : NULL_VALUE);
+ }
+
template <value_t (*Func)(account_t&)>
value_t get_wrapper(call_scope_t& args) {
return (*Func)(args.context<account_t>());
@@ -351,6 +382,13 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
break;
+ case 'e':
+ if (fn_name == "earliest")
+ return WRAP_FUNCTOR(get_wrapper<&get_earliest>);
+ else if (fn_name == "earliest_checkin")
+ return WRAP_FUNCTOR(get_wrapper<&get_earliest_checkin>);
+ break;
+
case 'i':
if (fn_name == "is_account")
return WRAP_FUNCTOR(get_wrapper<&get_true>);
@@ -359,15 +397,21 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
break;
case 'l':
- if (fn_name == "latest_cleared")
- return WRAP_FUNCTOR(get_wrapper<&get_latest_cleared>);
- else if (fn_name[1] == '\0')
+ if (fn_name[1] == '\0')
return WRAP_FUNCTOR(get_wrapper<&get_depth>);
+ else if (fn_name == "latest_cleared")
+ return WRAP_FUNCTOR(get_wrapper<&get_latest_cleared>);
+ else if (fn_name == "latest")
+ return WRAP_FUNCTOR(get_wrapper<&get_latest>);
+ else if (fn_name == "latest_checkout")
+ return WRAP_FUNCTOR(get_wrapper<&get_latest_checkout>);
break;
case 'n':
if (fn_name[1] == '\0')
return WRAP_FUNCTOR(get_wrapper<&get_subcount>);
+ else if (fn_name == "note")
+ return WRAP_FUNCTOR(get_wrapper<&get_note>);
break;
case 'p':
@@ -613,6 +657,14 @@ void account_t::xdata_t::details_t::update(post_t& post,
if (! is_valid(latest_post) || post.date() > latest_post)
latest_post = post.date();
+ if (post.checkin && (earliest_checkin.is_not_a_date_time() ||
+ *post.checkin < earliest_checkin))
+ earliest_checkin = *post.checkin;
+
+ if (post.checkout && (latest_checkout.is_not_a_date_time() ||
+ *post.checkout > latest_checkout))
+ latest_checkout = *post.checkout;
+
if (post.state() == item_t::CLEARED) {
posts_cleared_count++;