From 1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Jun 2010 22:18:16 -0400 Subject: 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 --- src/post.cc | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'src/post.cc') 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 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(0) > 2) - name = format_t::truncate(env->reported_account()->fullname(), + name = format_t::truncate(account.fullname(), env.get(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(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 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(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 - (acct->find_account(args.get(0), false))); - else if (scope[0].is_mask()) - return value_t(static_cast - (acct->find_account_re(args.get(0).str()))); - else - return NULL_VALUE; - } else { - return account_name(scope); - } - } - value_t get_account_id(post_t& post) { return static_cast(post.account_id()); } -- cgit v1.2.3