From 3a5370ddf16f131267f01f63c3b67b7b3b636cd1 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 14 Jul 2011 00:46:01 -0400 Subject: [PATCH] Filters - Implemented Command::filter_shortcut to detect when a filter begins with "status:pending" and skip the loading/parsing of completed.data. - Removed obsolete att.t.cpp tests. - Removed diagnostics from TDB2::TDB2 that were causing a segfault. I suppose there is no std::cout available during global ctors? --- src/Context.cpp | 3 --- src/TDB2.cpp | 10 ++++++++-- src/commands/Command.cpp | 38 ++++++++++++++++++++++++++++++++++---- src/commands/Command.h | 1 + test/att.t.cpp | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index aa548f558..39c8b691f 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -266,9 +266,6 @@ int Context::dispatch (std::string &out) return c->execute (out); } - // TODO Need to invoke 'information' when a sequence/filter is present, but - // no command is specified. - return commands["help"]->execute (out); } diff --git a/src/TDB2.cpp b/src/TDB2.cpp index efd1ab0d9..28bac036b 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -316,7 +316,6 @@ TDB2::TDB2 () : _location ("") , _id (1) { - std::cout << "# TDB2::TDB2\n"; } //////////////////////////////////////////////////////////////////////////////// @@ -324,7 +323,6 @@ TDB2::TDB2 () // already called, if data is to be preserved. TDB2::~TDB2 () { - std::cout << "# TDB2::~TDB2\n"; } //////////////////////////////////////////////////////////////////////////////// @@ -387,6 +385,10 @@ void TDB2::commit () } //////////////////////////////////////////////////////////////////////////////// +// Scans the pending tasks for any that are completed or deleted, and if so, +// moves them to the completed.data file. Returns a count of tasks moved. +// Now reverts expired waiting tasks to pending. +// Now cleans up dangling dependencies. int TDB2::gc () { std::cout << "# TDB2::gc\n"; @@ -407,6 +409,10 @@ int TDB2::gc () completed.remove pending.add */ + + // TODO Remove dangling dependencies + // TODO Wake up expired waiting tasks + return 0; } diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 788ef95d9..979f79c01 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -297,7 +297,6 @@ void Command::filter (std::vector & output) if (f.size ()) { const std::vector & pending = context.tdb2.pending.get_tasks (); - const std::vector & completed = context.tdb2.completed.get_tasks (); // TODO Optional Expression e (f); @@ -307,9 +306,15 @@ void Command::filter (std::vector & output) if (e.eval (*task)) output.push_back (*task); - for (task = completed.begin (); task != completed.end (); ++task) - if (e.eval (*task)) - output.push_back (*task); + if (! filter_shortcut (f)) + { + const std::vector & completed = context.tdb2.completed.get_tasks (); // TODO Optional + for (task = completed.begin (); task != completed.end (); ++task) + if (e.eval (*task)) + output.push_back (*task); + } + else + context.debug ("Command::filter skipping completed.data"); } else { @@ -325,6 +330,31 @@ void Command::filter (std::vector & output) } } +//////////////////////////////////////////////////////////////////////////////// +// 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 Arguments& filter) +{ +/**/ + if (filter.size () >= 3) + { + std::cout << "# filter[0] " << filter[0]._first << "\n" + << "# filter[1] " << filter[1]._first << "\n" + << "# filter[2] " << filter[2]._first << "\n"; + } +/**/ + + // Postfix: <"pending"> <=> + // 0 1 2 + if (filter.size () >= 3 && + filter[0]._first == "status" && + filter[1]._first.find ("pending") != std::string::npos && + filter[2]._first == "=") + return true; + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // Apply the modifications in arguments to the task. void Command::modify_task_description_replace (Task& task, Arguments& arguments) diff --git a/src/commands/Command.h b/src/commands/Command.h index f54a721b0..a42ff551d 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -55,6 +55,7 @@ public: protected: void filter (std::vector &, std::vector &); void filter (std::vector &); + bool filter_shortcut (const Arguments&); void modify_task_description_replace (Task&, Arguments&); void modify_task_description_prepend (Task&, Arguments&); diff --git a/test/att.t.cpp b/test/att.t.cpp index d92c234e8..6428bd755 100644 --- a/test/att.t.cpp +++ b/test/att.t.cpp @@ -34,7 +34,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (121); + UnitTest t (118); Att a; t.notok (a.valid ("name"), "Att::valid name -> fail");