diff --git a/src/Filter.cpp b/src/Filter.cpp index 15efac912..4c900e917 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -98,7 +98,7 @@ void Filter::subset (std::vector & output) if (precompiled.size ()) { Timer timer_pending; - auto pending = Context::getContext ().tdb2.pending.get_tasks (); + auto pending = Context::getContext ().tdb2.pending_tasks (); Context::getContext ().time_filter_us -= timer_pending.total_us (); _startCount = (int) pending.size (); @@ -126,7 +126,7 @@ void Filter::subset (std::vector & output) if (! shortcut) { Timer timer_completed; - auto completed = Context::getContext ().tdb2.completed.get_tasks (); + auto completed = Context::getContext ().tdb2.completed_tasks (); Context::getContext ().time_filter_us -= timer_completed.total_us (); _startCount += (int) completed.size (); @@ -149,11 +149,7 @@ void Filter::subset (std::vector & output) safety (); Timer pending_completed; - for (auto& task : Context::getContext ().tdb2.pending.get_tasks ()) - output.push_back (task); - - for (auto& task : Context::getContext ().tdb2.completed.get_tasks ()) - output.push_back (task); + output = Context::getContext ().tdb2.all_tasks (); Context::getContext ().time_filter_us -= pending_completed.total_us (); } diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 5f7378d57..9cb1f0d77 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -1133,6 +1133,18 @@ const std::vector TDB2::all_tasks () return all; } +//////////////////////////////////////////////////////////////////////////////// +const std::vector TDB2::pending_tasks () +{ + return pending.get_tasks (); +} + +//////////////////////////////////////////////////////////////////////////////// +const std::vector TDB2::completed_tasks () +{ + return completed.get_tasks (); +} + //////////////////////////////////////////////////////////////////////////////// // Locate task by ID, wherever it is. bool TDB2::get (int id, Task& task) diff --git a/src/TDB2.h b/src/TDB2.h index 58ba6866a..df61acd39 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -122,6 +122,8 @@ public: // Generalized task accessors. const std::vector all_tasks (); + const std::vector pending_tasks (); + const std::vector completed_tasks (); bool get (int, Task&); bool get (const std::string&, Task&); bool has (const std::string&); @@ -152,11 +154,11 @@ private: void revert_completed (std::vector &, std::vector &, const std::string&, const std::string&); void revert_backlog (std::vector &, const std::string&, const std::string&, const std::string&); -public: +protected: + friend class TF2; // TF2 reaches into TDB2 internals for gc TF2 pending; TF2 completed; -protected: friend class CmdSync; // CmdSync accesses the backlog directly TF2 backlog; friend class CmdInfo; // CmdInfo uses undo data to give history diff --git a/src/Task.cpp b/src/Task.cpp index c867d0f9f..560984b40 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1211,7 +1211,7 @@ void Task::setAnnotations (const std::map & annotation void Task::addDependency (int depid) { // Check that id is resolvable. - std::string uuid = Context::getContext ().tdb2.pending.uuid (depid); + std::string uuid = Context::getContext ().tdb2.uuid (depid); if (uuid == "") throw format ("Could not create a dependency on task {1} - not found.", depid); @@ -1259,7 +1259,7 @@ void Task::addDependency (const std::string& uuid) //////////////////////////////////////////////////////////////////////////////// void Task::removeDependency (int id) { - std::string uuid = Context::getContext ().tdb2.pending.uuid (id); + std::string uuid = Context::getContext ().tdb2.uuid (id); // The removeDependency(std::string&) method will check this too, but here we // can give a more natural error message containing the id provided by the user @@ -1296,7 +1296,7 @@ std::vector Task::getDependencyIDs () const if (!isDepAttr (attr)) continue; auto dep = attr2Dep (attr); - ids.push_back (Context::getContext ().tdb2.pending.id (dep)); + ids.push_back (Context::getContext ().tdb2.id (dep)); } return ids; @@ -1326,7 +1326,7 @@ std::vector Task::getDependencyTasks () const // efficient. std::vector blocking; if (uuids.size() > 0) - for (auto& it : Context::getContext ().tdb2.pending.get_tasks ()) + for (auto& it : Context::getContext ().tdb2.pending_tasks ()) if (it.getStatus () != Task::completed && it.getStatus () != Task::deleted && std::find (uuids.begin (), uuids.end (), it.get ("uuid")) != uuids.end ()) @@ -1341,7 +1341,7 @@ std::vector Task::getBlockedTasks () const auto uuid = get ("uuid"); std::vector blocked; - for (auto& it : Context::getContext ().tdb2.pending.get_tasks ()) + for (auto& it : Context::getContext ().tdb2.pending_tasks ()) if (it.getStatus () != Task::completed && it.getStatus () != Task::deleted && it.hasDependency (uuid)) diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index 8bef9a2bd..c656cc05f 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -81,7 +81,7 @@ int CmdCalendar::execute (std::string& output) // Load the pending tasks. handleUntil (); handleRecurrence (); - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); Datetime today; auto getPendingDate = false; diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index 26d51825e..f8e6c3e2d 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -202,7 +202,7 @@ void CmdContext::defineContext (const std::vector & words, std::str // Check if the value is a proper filter by filtering current pending.data Filter filter; std::vector filtered; - auto pending = Context::getContext ().tdb2.pending.get_tasks (); + auto pending = Context::getContext ().tdb2.pending_tasks (); try { diff --git a/src/commands/CmdProjects.cpp b/src/commands/CmdProjects.cpp index 2eff136e6..2c5dea7d4 100644 --- a/src/commands/CmdProjects.cpp +++ b/src/commands/CmdProjects.cpp @@ -60,10 +60,10 @@ int CmdProjects::execute (std::string& output) // Get all the tasks. handleUntil (); handleRecurrence (); - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); if (Context::getContext ().config.getBoolean ("list.all.projects")) - for (auto& task : Context::getContext ().tdb2.completed.get_tasks ()) + for (auto& task : Context::getContext ().tdb2.completed_tasks ()) tasks.push_back (task); // Apply the filter. @@ -172,10 +172,10 @@ int CmdCompletionProjects::execute (std::string& output) // Get all the tasks. handleUntil (); handleRecurrence (); - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); if (Context::getContext ().config.getBoolean ("list.all.projects")) - for (auto& task : Context::getContext ().tdb2.completed.get_tasks ()) + for (auto& task : Context::getContext ().tdb2.completed_tasks ()) tasks.push_back (task); // Apply the filter. diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index adf298900..fcf58b631 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -58,10 +58,10 @@ int CmdTags::execute (std::string& output) std::stringstream out; // Get all the tasks. - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); if (Context::getContext ().config.getBoolean ("list.all.tags")) - for (auto& task : Context::getContext ().tdb2.completed.get_tasks ()) + for (auto& task : Context::getContext ().tdb2.completed_tasks ()) tasks.push_back (task); int quantity = tasks.size (); @@ -157,10 +157,10 @@ CmdCompletionTags::CmdCompletionTags () int CmdCompletionTags::execute (std::string& output) { // Get all the tasks. - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); if (Context::getContext ().config.getBoolean ("complete.all.tags")) - for (auto& task : Context::getContext ().tdb2.completed.get_tasks ()) + for (auto& task : Context::getContext ().tdb2.completed_tasks ()) tasks.push_back (task); // Apply filter. diff --git a/src/nag.cpp b/src/nag.cpp index de36ce3cd..f95c5201b 100644 --- a/src/nag.cpp +++ b/src/nag.cpp @@ -40,7 +40,7 @@ void nag (std::vector & tasks) if (msg == "") return; - auto pending = Context::getContext ().tdb2.pending.get_tasks (); + auto pending = Context::getContext ().tdb2.pending_tasks (); for (auto& t1 : tasks) { if (t1.hasTag ("nonag")) continue; diff --git a/src/recur.cpp b/src/recur.cpp index 02bed4580..7ace0367b 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -56,7 +56,7 @@ void handleRecurrence () if (! Context::getContext ().config.getBoolean ("recurrence")) return; - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); Datetime now; // Look at all tasks and find any recurring ones. @@ -411,7 +411,7 @@ void updateRecurrenceMask (Task& task) void handleUntil () { Datetime now; - auto tasks = Context::getContext ().tdb2.pending.get_tasks (); + auto tasks = Context::getContext ().tdb2.pending_tasks (); for (auto& t : tasks) { // TODO What about expiring template tasks? diff --git a/test/tdb2.t.cpp b/test/tdb2.t.cpp index 4e0b83e7f..1d1accfdc 100644 --- a/test/tdb2.t.cpp +++ b/test/tdb2.t.cpp @@ -58,8 +58,8 @@ int main (int, char**) context.tdb2.set_location ("."); // Try reading an empty database. - std::vector pending = context.tdb2.pending.get_tasks (); - std::vector completed = context.tdb2.completed.get_tasks (); + std::vector pending = context.tdb2.pending_tasks (); + std::vector completed = context.tdb2.completed_tasks (); int num_reverts_possible = context.tdb2.num_reverts_possible (); int num_local_changes = context.tdb2.num_local_changes (); @@ -72,8 +72,8 @@ int main (int, char**) Task task (R"([description:"description" name:"value"])"); context.tdb2.add (task); - pending = context.tdb2.pending.get_tasks (); - completed = context.tdb2.completed.get_tasks (); + pending = context.tdb2.pending_tasks (); + completed = context.tdb2.completed_tasks (); num_reverts_possible = context.tdb2.num_reverts_possible (); num_local_changes = context.tdb2.num_local_changes (); @@ -85,8 +85,8 @@ int main (int, char**) task.set ("description", "This is a test"); context.tdb2.modify (task); - pending = context.tdb2.pending.get_tasks (); - completed = context.tdb2.completed.get_tasks (); + pending = context.tdb2.pending_tasks (); + completed = context.tdb2.completed_tasks (); num_reverts_possible = context.tdb2.num_reverts_possible (); num_local_changes = context.tdb2.num_local_changes ();