diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 21:31:55 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-13 01:03:47 -0400 |
commit | 15bf3ed39ed24bc55abc624757a1a943ebabb085 (patch) | |
tree | 5d2cc4212554f22696ae123e9cd7ab195af2ad66 /src/account.cc | |
parent | 9effdb3aa2bfcad9dc391cbe5a15b9f563505b00 (diff) | |
download | fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.tar.gz fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.tar.bz2 fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.zip |
account(NAME) function can lookup account objects
For example, just the word "account" returns the name of the current
posting's account, but account("Expenses:Food") returns the actual
account object, so that it's total may be accessed.
Diffstat (limited to 'src/account.cc')
-rw-r--r-- | src/account.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/account.cc b/src/account.cc index 4170a4d2..710cabe1 100644 --- a/src/account.cc +++ b/src/account.cc @@ -182,8 +182,23 @@ namespace { env.get<bool>(0) : false)); } - value_t get_account(account_t& account) { // this gets the name - return string_value(account.fullname()); + value_t get_account(call_scope_t& scope) { // this gets the name + interactive_t args(scope, "&v"); + account_t& account(find_scope<account_t>(scope)); + 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 string_value(account.fullname()); + } } value_t get_account_base(account_t& account) { @@ -301,7 +316,7 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind, if (name[1] == '\0' || name == "amount") return WRAP_FUNCTOR(get_wrapper<&get_amount>); else if (name == "account") - return WRAP_FUNCTOR(get_wrapper<&get_account>); + return WRAP_FUNCTOR(&get_account); else if (name == "account_base") return WRAP_FUNCTOR(get_wrapper<&get_account_base>); else if (name == "addr") |