Commands
- Promoted filtering code to the Command base class. - Added filtering short-circuit.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user