summaryrefslogtreecommitdiff
path: root/src/account.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-04 19:55:27 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-04 19:55:27 -0400
commit2d941730b1c60342be5b108d2d654723b3b7c2cb (patch)
tree6a3f4b7305857e85d2684670492007bafc3668d0 /src/account.cc
parent73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe (diff)
downloadfork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.gz
fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.bz2
fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.zip
Largely removed all of Ledger's use of global variables, for the REPL's sake.
Diffstat (limited to 'src/account.cc')
-rw-r--r--src/account.cc36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/account.cc b/src/account.cc
index 9d7bf1e5..376097f2 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -30,7 +30,6 @@
*/
#include "account.h"
-#include "report.h"
namespace ledger {
@@ -87,6 +86,25 @@ account_t * account_t::find_account(const string& name,
return account;
}
+namespace {
+ account_t * find_account_re_(account_t * account, const mask_t& regexp)
+ {
+ if (regexp.match(account->fullname()))
+ return account;
+
+ foreach (accounts_map::value_type& pair, account->accounts)
+ if (account_t * a = find_account_re_(pair.second, regexp))
+ return a;
+
+ return NULL;
+ }
+}
+
+account_t * account_t::find_account_re(const string& regexp)
+{
+ return find_account_re_(this, mask_t(regexp));
+}
+
string account_t::fullname() const
{
if (! _fullname.empty()) {
@@ -114,7 +132,8 @@ std::ostream& operator<<(std::ostream& out, const account_t& account)
}
namespace {
- value_t get_partial_name(account_t& account) {
+ value_t get_partial_name(account_t& account)
+ {
string name;
for (account_t * acct = &account;
@@ -152,7 +171,8 @@ namespace {
return long(account.depth);
}
- value_t get_depth_spacer(account_t& account) {
+ value_t get_depth_spacer(account_t& account)
+ {
std::ostringstream out;
for (account_t * acct = &account;
acct;
@@ -197,7 +217,7 @@ expr_t::ptr_op_t account_t::lookup(const string& name)
break;
}
- return session_t::current->global_scope->lookup(name);
+ return expr_t::ptr_op_t();
}
bool account_t::valid() const
@@ -222,12 +242,13 @@ bool account_t::valid() const
return true;
}
-void account_t::calculate_sums(expr_t& amount_expr)
+void account_t::calculate_sums(expr_t& amount_expr,
+ scope_t& scope)
{
xdata_t& xd(xdata());
foreach (accounts_map::value_type& pair, accounts) {
- (*pair.second).calculate_sums(amount_expr);
+ (*pair.second).calculate_sums(amount_expr, scope);
xdata_t& child_xd((*pair.second).xdata());
if (! child_xd.total.is_null()) {
@@ -239,7 +260,8 @@ void account_t::calculate_sums(expr_t& amount_expr)
}
}
- call_scope_t args(*this);
+ bind_scope_t bound_scope(scope, *this);
+ call_scope_t args(bound_scope);
value_t amount(amount_expr.calc(args));
if (! amount.is_null()) {
add_or_set_value(xd.total, amount);