diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:27:46 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:47:35 -0600 |
commit | e86a4767bc93664893faa4d0f03619f57302c7d1 (patch) | |
tree | 8b315443d946558a0fd1909fb2f853dc6724acd0 /src/filters.cc | |
parent | f491979d5547742aae70b3f6dd5b4aa0eac36605 (diff) | |
download | fork-ledger-e86a4767bc93664893faa4d0f03619f57302c7d1.tar.gz fork-ledger-e86a4767bc93664893faa4d0f03619f57302c7d1.tar.bz2 fork-ledger-e86a4767bc93664893faa4d0f03619f57302c7d1.zip |
Added new post_splitter posting handler
Diffstat (limited to 'src/filters.cc')
-rw-r--r-- | src/filters.cc | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/filters.cc b/src/filters.cc index 57c95cd3..6915144d 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -39,8 +39,49 @@ namespace ledger { +void post_splitter::print_title(const value_t& val) +{ + if (! report.HANDLED(no_titles)) { + std::ostringstream buf; + val.print(buf); + post_chain->title(buf.str()); + } +} + +void post_splitter::flush() +{ + foreach (value_to_posts_map::value_type pair, posts_map) { + preflush_func(pair.first); + + foreach (post_t * post, pair.second) + (*post_chain)(*post); + + post_chain->flush(); + post_chain->clear(); + + if (postflush_func) + (*postflush_func)(pair.first); + } +} + +void post_splitter::operator()(post_t& post) +{ + bind_scope_t bound_scope(report, post); + value_t result(group_by_expr.calc(bound_scope)); + + value_to_posts_map::iterator i = posts_map.find(result); + if (i != posts_map.end()) { + (*i).second.push_back(&post); + } else { + std::pair<value_to_posts_map::iterator, bool> inserted + = posts_map.insert(value_to_posts_map::value_type(result, posts_list())); + assert(inserted.second); + (*inserted.first).second.push_back(&post); + } +} + pass_down_posts::pass_down_posts(post_handler_ptr handler, - posts_iterator& iter) + posts_iterator& iter) : item_handler<post_t>(handler) { TRACE_CTOR(pass_down_posts, "post_handler_ptr, posts_iterator"); |