From 6b53cf40279d638b2ca928d1836c1e2f52434277 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 25 May 2014 00:02:27 -0400 Subject: [PATCH] Command - Removed obsolete ::filter, ::filter_shortcut and ::safety methods. These are now implemented in the Filter object, and use A3t. --- src/commands/Command.cpp | 167 --------------------------------------- src/commands/Command.h | 5 -- 2 files changed, 172 deletions(-) diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 7675029cf..4a800ef57 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -281,152 +281,6 @@ bool Command::displays_id () const return _displays_id; } -//////////////////////////////////////////////////////////////////////////////// -// Filter a specific list of tasks. -void Command::filter (const std::vector & input, std::vector & 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 ::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 & 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 & pending = context.tdb2.pending.get_tasks (); - context.timer_filter.start (); - E9 e (filt); - - output.clear (); - std::vector ::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 & 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 & pending = context.tdb2.pending.get_tasks (); - const std::vector & completed = context.tdb2.completed.get_tasks (); - context.timer_filter.start (); - - std::vector ::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: <"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 ::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. diff --git a/src/commands/Command.h b/src/commands/Command.h index c5e6ff490..bd6ec7a45 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -52,17 +52,12 @@ public: virtual int execute (std::string&) = 0; protected: - void filter (const std::vector &, std::vector &); - void filter (std::vector &); - 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: