diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-18 17:37:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-18 17:37:27 -0400 |
commit | 47bfe58ab39aa8d7ed4dc804409f1f78f485a5a6 (patch) | |
tree | 0b76e580880e0cb6f6ed5bec8e8bc053797d3a5b /src/post.cc | |
parent | 017492ef5e80003073c5d053252d4a68a44260ae (diff) | |
download | fork-ledger-47bfe58ab39aa8d7ed4dc804409f1f78f485a5a6.tar.gz fork-ledger-47bfe58ab39aa8d7ed4dc804409f1f78f485a5a6.tar.bz2 fork-ledger-47bfe58ab39aa8d7ed4dc804409f1f78f485a5a6.zip |
Added account_id and xact_id valexpr vars for posts
account_id is the "whicheth" number for that posting within its
account. The xact_id is within its transaction.
Diffstat (limited to 'src/post.cc')
-rw-r--r-- | src/post.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/post.cc b/src/post.cc index 183fb901..fb3281a7 100644 --- a/src/post.cc +++ b/src/post.cc @@ -142,6 +142,10 @@ namespace { return value_t(static_cast<scope_t *>(post.xact)); } + value_t get_xact_id(post_t& post) { + return static_cast<long>(post.xact_id()); + } + value_t get_code(post_t& post) { if (post.xact->code) return string_value(*post.xact->code); @@ -275,6 +279,10 @@ namespace { return string_value(name); } + value_t get_account_id(post_t& post) { + return static_cast<long>(post.account_id()); + } + value_t get_account_base(post_t& post) { return string_value(post.reported_account()->name); } @@ -351,6 +359,8 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, return WRAP_FUNCTOR(get_account); else if (name == "account_base") return WRAP_FUNCTOR(get_wrapper<&get_account_base>); + else if (name == "account_id") + return WRAP_FUNCTOR(get_wrapper<&get_account_id>); else if (name == "any") return WRAP_FUNCTOR(&fn_any); else if (name == "all") @@ -444,6 +454,8 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, case 'x': if (name == "xact") return WRAP_FUNCTOR(get_wrapper<&get_xact>); + else if (name == "xact_id") + return WRAP_FUNCTOR(get_wrapper<&get_xact_id>); break; case 'N': @@ -479,6 +491,30 @@ amount_t post_t::resolve_expr(scope_t& scope, expr_t& expr) } } +std::size_t post_t::xact_id() const +{ + std::size_t id = 1; + foreach (post_t * p, xact->posts) { + if (p == this) + return id; + id++; + } + assert(! "Failed to find posting within its transaction"); + return 0; +} + +std::size_t post_t::account_id() const +{ + std::size_t id = 1; + foreach (post_t * p, account->posts) { + if (p == this) + return id; + id++; + } + assert(! "Failed to find posting within its transaction"); + return 0; +} + bool post_t::valid() const { if (! xact) { |