- Removed obsolete ::filter, ::filter_shortcut and ::safety methods.
  These are now implemented in the Filter object, and use A3t.
This commit is contained in:
Paul Beckingham 2014-05-25 00:02:27 -04:00
parent 4ba2761aa6
commit 6b53cf4027
2 changed files with 0 additions and 172 deletions

View file

@ -281,152 +281,6 @@ bool Command::displays_id () const
return _displays_id;
}
////////////////////////////////////////////////////////////////////////////////
// Filter a specific list of tasks.
void Command::filter (const std::vector <Task>& input, std::vector <Task>& output)
{
context.debug ("OBSOLETE Command::filter");
context.timer_filter.start ();
A3 filt = context.a3.extract_filter ();
filt.dump ("extract_filter");
if (context.config.getBoolean ("debug"))
{
Tree* t = context.a3t.tree ();
if (t)
context.debug (t->dump ());
}
std::string filterExpr = context.a3t.getFilterExpression ();
context.debug ("\033[1;37;42mFILTER\033[0m " + filterExpr);
if (filt.size ())
{
E9 e (filt);
std::vector <Task>::const_iterator task;
for (task = input.begin (); task != input.end (); ++task)
if (e.evalFilter (*task))
output.push_back (*task);
}
else
output = input;
context.timer_filter.stop ();
}
////////////////////////////////////////////////////////////////////////////////
// Filter all tasks.
void Command::filter (std::vector <Task>& output)
{
context.debug ("OBSOLETE Command::filter");
context.timer_filter.start ();
A3 filt = context.a3.extract_filter ();
filt.dump ("extract_filter");
if (context.config.getBoolean ("debug"))
{
Tree* t = context.a3t.tree ();
if (t)
context.debug (t->dump ());
}
std::string filterExpr = context.a3t.getFilterExpression ();
context.debug ("\033[1;37;42mFILTER\033[0m " + filterExpr);
if (filt.size ())
{
context.timer_filter.stop ();
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
context.timer_filter.start ();
E9 e (filt);
output.clear ();
std::vector <Task>::const_iterator task;
for (task = pending.begin (); task != pending.end (); ++task)
if (e.evalFilter (*task))
output.push_back (*task);
if (! filter_shortcut (filt))
{
context.timer_filter.stop ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
context.timer_filter.start ();
for (task = completed.begin (); task != completed.end (); ++task)
if (e.evalFilter (*task))
output.push_back (*task);
}
}
else
{
safety ();
context.timer_filter.stop ();
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks ();
context.timer_filter.start ();
std::vector <Task>::const_iterator task;
for (task = pending.begin (); task != pending.end (); ++task)
output.push_back (*task);
for (task = completed.begin (); task != completed.end (); ++task)
output.push_back (*task);
}
context.timer_filter.stop ();
}
////////////////////////////////////////////////////////////////////////////////
// If the filter contains the restriction "status:pending", as the first filter
// term, then completed.data does not need to be loaded.
bool Command::filter_shortcut (const A3& filter)
{
context.debug ("OBSOLETE Command::filter_shortcut");
// Postfix: <status> <"pending"> <=>
// 0 1 2
if (filter.size () >= 3 &&
filter[0]._raw == "status" &&
filter[1]._raw.find ("pending") != std::string::npos &&
filter[2]._raw == "=")
{
context.debug ("Command::filter skipping completed.data (status:pending only)");
return true;
}
// Shortcut: If the filter contains no 'or' or 'xor' operators, IDs and no UUIDs.
int countId = 0;
int countUUID = 0;
int countOr = 0;
int countXor = 0;
std::vector <Arg>::const_iterator i;
for (i = filter.begin (); i != filter.end (); ++i)
{
if (i->_category == Arg::cat_op)
{
if (i->_raw == "or") ++countOr;
if (i->_raw == "xor") ++countXor;
}
else if (i->_category == Arg::cat_id) ++countId;
else if (i->_category == Arg::cat_uuid) ++countUUID;
}
if (countOr == 0 &&
countXor == 0 &&
countUUID == 0 &&
countId > 0)
{
context.debug ("Command::filter skipping completed.data (IDs, no OR, no XOR, no UUID)");
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Apply the modifications in arguments to the task.
void Command::modify_task_description_replace (Task& task, const A3& arguments)
@ -482,27 +336,6 @@ void Command::modify_task (
task.modify (arguments, description);
}
////////////////////////////////////////////////////////////////////////////////
// Disaster avoidance mechanism.
void Command::safety ()
{
context.debug ("OBSOLETE Command::safety");
if (! _read_only)
{
A3 write_filter = context.a3.extract_filter ();
if (!write_filter.size ()) // Potential disaster.
{
// If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE))
return;
// No.
throw std::string (STRING_TASK_SAFETY_FAIL);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Returns true or false indicating whether to proceed with a write command, on
// a per-task basis, after (potentially) asking for permission.

View file

@ -52,17 +52,12 @@ public:
virtual int execute (std::string&) = 0;
protected:
void filter (const std::vector <Task>&, std::vector <Task>&);
void filter (std::vector <Task>&);
bool filter_shortcut (const A3&);
void modify_task_description_replace (Task&, const A3&);
void modify_task_description_prepend (Task&, const A3&);
void modify_task_description_append (Task&, const A3&);
void modify_task_annotate (Task&, const A3&);
void modify_task (Task&, const A3&, std::string&);
void safety ();
bool permission (const Task&, const std::string&, unsigned int);
protected: