Fixed the operation of --head and --tail

This commit is contained in:
John Wiegley 2009-02-27 14:10:28 -04:00
parent 0efe0c63ce
commit afe3a899c6
2 changed files with 28 additions and 16 deletions

View file

@ -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();

View file

@ -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);
};
/**