summaryrefslogtreecommitdiff
path: root/src/post.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-12 22:18:16 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-13 01:03:48 -0400
commit1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd (patch)
tree482c6d0143b56c61b43fadb141384fb89184279e /src/post.cc
parent536e3e73228b6168437704ede89499406b87391d (diff)
downloadfork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.tar.gz
fork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.tar.bz2
fork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.zip
Expression evaluations now have a "type context"
Thus, an expression can know if the context in which it's being evaluated requires a string, and if so, determine it's output accordingly. For example: account ; returns the full name of the posting's account account.total ; here the context is SCOPE, so account is an obj
Diffstat (limited to 'src/post.cc')
-rw-r--r--src/post.cc40
1 files changed, 12 insertions, 28 deletions
diff --git a/src/post.cc b/src/post.cc
index da892062..d4a16122 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -254,20 +254,20 @@ namespace {
return 1L;
}
- value_t account_name(call_scope_t& scope)
+ value_t get_account(call_scope_t& scope)
{
in_context_t<post_t> env(scope, "&v");
-
- string name;
+ account_t& account(*env->reported_account());
+ string name;
if (env.has(0)) {
if (env.value_at(0).is_long()) {
if (env.get<long>(0) > 2)
- name = format_t::truncate(env->reported_account()->fullname(),
+ name = format_t::truncate(account.fullname(),
env.get<long>(0) - 2,
2 /* account_abbrev_length */);
else
- name = env->reported_account()->fullname();
+ name = account.fullname();
} else {
account_t * account = NULL;
account_t * master = env->account;
@@ -294,8 +294,12 @@ namespace {
else
return value_t(static_cast<scope_t *>(account));
}
- } else {
- name = env->reported_account()->fullname();
+ }
+ else if (scope.type_context() == value_t::SCOPE) {
+ return scope_value(&account);
+ }
+ else {
+ name = account.fullname();
}
return string_value(name);
}
@@ -304,7 +308,7 @@ namespace {
{
in_context_t<post_t> env(scope, "&v");
- value_t acct = account_name(scope);
+ value_t acct = get_account(scope);
if (acct.is_string()) {
if (env->has_flags(POST_VIRTUAL)) {
if (env->must_balance())
@@ -316,26 +320,6 @@ namespace {
return acct;
}
- value_t get_account(call_scope_t& scope)
- {
- interactive_t args(scope, "&v");
- account_t& account(*find_scope<post_t>(scope).account);
- if (args.has(0)) {
- account_t * acct = account.parent;
- for (; acct && acct->parent; acct = acct->parent) ;
- if (scope[0].is_string())
- return value_t(static_cast<scope_t *>
- (acct->find_account(args.get<string>(0), false)));
- else if (scope[0].is_mask())
- return value_t(static_cast<scope_t *>
- (acct->find_account_re(args.get<mask_t>(0).str())));
- else
- return NULL_VALUE;
- } else {
- return account_name(scope);
- }
- }
-
value_t get_account_id(post_t& post) {
return static_cast<long>(post.account_id());
}