summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-27 14:10:28 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-27 14:10:28 -0400
commitafe3a899c6a6e2cdd01fcf55c5f8ce62a1ef8b8c (patch)
tree48dd1c78904302c7afaa3c19bb7e60b7f2ad6045
parent0efe0c63ce285cc562933180a4a2b4ecb5a308b7 (diff)
downloadfork-ledger-afe3a899c6a6e2cdd01fcf55c5f8ce62a1ef8b8c.tar.gz
fork-ledger-afe3a899c6a6e2cdd01fcf55c5f8ce62a1ef8b8c.tar.bz2
fork-ledger-afe3a899c6a6e2cdd01fcf55c5f8ce62a1ef8b8c.zip
Fixed the operation of --head and --tail
-rw-r--r--src/filters.cc27
-rw-r--r--src/filters.h17
2 files changed, 28 insertions, 16 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 3071a951..ea3ed99d 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -61,22 +61,22 @@ void truncate_xacts::flush()
if (! posts.size())
return;
- xact_t * last_xact = (*posts.begin())->xact;
+ xact_t * xact = (*posts.begin())->xact;
int l = 0;
foreach (post_t * post, posts)
- if (last_xact != post->xact) {
+ if (xact != post->xact) {
l++;
- last_xact = post->xact;
+ xact = post->xact;
}
l++;
- last_xact = (*posts.begin())->xact;
+ xact = (*posts.begin())->xact;
int i = 0;
foreach (post_t * post, posts) {
- if (last_xact != post->xact) {
- last_xact = post->xact;
+ if (xact != post->xact) {
+ xact = post->xact;
i++;
}
@@ -103,6 +103,21 @@ void truncate_xacts::flush()
item_handler<post_t>::flush();
}
+void truncate_xacts::operator()(post_t& post)
+{
+ if (last_xact != post.xact) {
+ if (last_xact)
+ xacts_seen++;
+ last_xact = post.xact;
+ }
+
+ if (tail_count == 0 && head_count > 0 &&
+ static_cast<int>(xacts_seen) >= head_count)
+ return;
+
+ posts.push_back(&post);
+}
+
void set_account_value::operator()(post_t& post)
{
account_t * acct = post.reported_account();
diff --git a/src/filters.h b/src/filters.h
index bd5f5897..64b688ec 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -159,15 +159,17 @@ class truncate_xacts : public item_handler<post_t>
int head_count;
int tail_count;
- posts_list posts;
+ posts_list posts;
+ std::size_t xacts_seen;
+ xact_t * last_xact;
truncate_xacts();
public:
- truncate_xacts(post_handler_ptr handler,
- int _head_count, int _tail_count)
+ truncate_xacts(post_handler_ptr handler, int _head_count, int _tail_count)
: item_handler<post_t>(handler),
- head_count(_head_count), tail_count(_tail_count) {
+ head_count(_head_count), tail_count(_tail_count),
+ xacts_seen(0), last_xact(NULL) {
TRACE_CTOR(truncate_xacts, "post_handler_ptr, int, int");
}
virtual ~truncate_xacts() {
@@ -175,12 +177,7 @@ public:
}
virtual void flush();
-
- virtual void operator()(post_t& post) {
- if (! (tail_count == 0 && head_count > 0 &&
- static_cast<int>(posts.size()) >= head_count))
- posts.push_back(&post);
- }
+ virtual void operator()(post_t& post);
};
/**