make TDB2.pending/completed non-public

References to methods on these fields are replaced with methods on TDB2,
several of which already existed.
This commit is contained in:
Dustin J. Mitchell 2022-04-01 23:20:57 +00:00 committed by Tomas Babej
parent 4ebd0ffb39
commit 271d06cd9c
11 changed files with 43 additions and 33 deletions

View file

@ -98,7 +98,7 @@ void Filter::subset (std::vector <Task>& 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 <Task>& 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 <Task>& 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 ();
}

View file

@ -1133,6 +1133,18 @@ const std::vector <Task> TDB2::all_tasks ()
return all;
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task> TDB2::pending_tasks ()
{
return pending.get_tasks ();
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task> TDB2::completed_tasks ()
{
return completed.get_tasks ();
}
////////////////////////////////////////////////////////////////////////////////
// Locate task by ID, wherever it is.
bool TDB2::get (int id, Task& task)

View file

@ -122,6 +122,8 @@ public:
// Generalized task accessors.
const std::vector <Task> all_tasks ();
const std::vector <Task> pending_tasks ();
const std::vector <Task> 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::string>&, std::vector <std::string>&, const std::string&, const std::string&);
void revert_backlog (std::vector <std::string>&, 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

View file

@ -1211,7 +1211,7 @@ void Task::setAnnotations (const std::map <std::string, std::string>& 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 <int> 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> Task::getDependencyTasks () const
// efficient.
std::vector <Task> 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> Task::getBlockedTasks () const
auto uuid = get ("uuid");
std::vector <Task> 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))

View file

@ -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;

View file

@ -202,7 +202,7 @@ void CmdContext::defineContext (const std::vector <std::string>& words, std::str
// Check if the value is a proper filter by filtering current pending.data
Filter filter;
std::vector <Task> filtered;
auto pending = Context::getContext ().tdb2.pending.get_tasks ();
auto pending = Context::getContext ().tdb2.pending_tasks ();
try
{

View file

@ -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.

View file

@ -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.

View file

@ -40,7 +40,7 @@ void nag (std::vector <Task>& 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;

View file

@ -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?

View file

@ -58,8 +58,8 @@ int main (int, char**)
context.tdb2.set_location (".");
// Try reading an empty database.
std::vector <Task> pending = context.tdb2.pending.get_tasks ();
std::vector <Task> completed = context.tdb2.completed.get_tasks ();
std::vector <Task> pending = context.tdb2.pending_tasks ();
std::vector <Task> 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 ();