- Promoted filtering code to the Command base class.
- Added filtering short-circuit.
This commit is contained in:
Paul Beckingham 2011-06-19 10:25:53 -04:00
parent db17536266
commit 7762ee2f9e
14 changed files with 79 additions and 173 deletions

View file

@ -27,7 +27,9 @@
#include <iostream>
#include <vector>
#include <Expression.h>
#include <Command.h>
#include <CmdAdd.h>
#include <CmdAnnotate.h>
#include <CmdAppend.h>
@ -249,3 +251,20 @@ bool Command::displays_id () const
}
////////////////////////////////////////////////////////////////////////////////
void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
{
Arguments f = context.args.extract_read_only_filter ();
if (f.size ())
{
Expression e (f);
std::vector <Task>::iterator task;
for (task = input.begin (); task != input.end (); ++task)
if (e.eval (*task))
output.push_back (*task);
}
else
output = input;
}
////////////////////////////////////////////////////////////////////////////////