summaryrefslogtreecommitdiff
path: root/src/account.cc
diff options
context:
space:
mode:
authorJohn Wiegley <jwiegley@gmail.com>2017-11-02 08:12:02 -0700
committerGitHub <noreply@github.com>2017-11-02 08:12:02 -0700
commitbc8136fa6fbb74febee99735c8bd603b1f12ddef (patch)
tree06ff0632b2b5455dfddce39ae727fa3739d36d70 /src/account.cc
parentd19adce1ff4aae123028584d59acda92905a711c (diff)
parent31ef0ac9360e8d2a2c624892f02325c8a0aef603 (diff)
downloadfork-ledger-bc8136fa6fbb74febee99735c8bd603b1f12ddef.tar.gz
fork-ledger-bc8136fa6fbb74febee99735c8bd603b1f12ddef.tar.bz2
fork-ledger-bc8136fa6fbb74febee99735c8bd603b1f12ddef.zip
Merge pull request #498 from CurrySoftware/next
Allow printing the depth of the first displayed parent
Diffstat (limited to 'src/account.cc')
-rw-r--r--src/account.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/account.cc b/src/account.cc
index da8b0b8e..114c4cc5 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -309,6 +309,20 @@ namespace {
return long(&account);
}
+ value_t get_depth_parent(account_t& account)
+ {
+ std::size_t depth = 0;
+ for (const account_t * acct = account.parent;
+ acct && acct->parent;
+ acct = acct->parent) {
+ std::size_t count = acct->children_with_flags(ACCOUNT_EXT_TO_DISPLAY);
+ assert(count > 0);
+ if (count > 1 || acct->has_xflags(ACCOUNT_EXT_TO_DISPLAY))
+ depth++;
+ }
+ return long(depth);
+ }
+
value_t get_depth_spacer(account_t& account)
{
std::size_t depth = 0;
@@ -425,6 +439,8 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
case 'd':
if (fn_name == "depth")
return WRAP_FUNCTOR(get_wrapper<&get_depth>);
+ else if (fn_name == "depth_parent")
+ return WRAP_FUNCTOR(get_wrapper<&get_depth_parent>);
else if (fn_name == "depth_spacer")
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
break;