mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 16:53:08 +02:00
TDB2
- Pushed task lookup by ID and UUID down a level from TDB2 to TF2. This allows reuse at the low level for things like proper dependency evaluation.
This commit is contained in:
parent
88fcdab515
commit
d59aaa6427
2 changed files with 49 additions and 62 deletions
108
src/TDB2.cpp
108
src/TDB2.cpp
|
@ -104,6 +104,46 @@ const std::vector <std::string>& TF2::get_lines ()
|
||||||
return _lines;
|
return _lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Locate task by id.
|
||||||
|
bool TF2::get (int id, Task& task)
|
||||||
|
{
|
||||||
|
if (! _loaded_tasks)
|
||||||
|
load_tasks ();
|
||||||
|
|
||||||
|
std::vector <Task>::iterator i;
|
||||||
|
for (i = _tasks.begin (); i != _tasks.end (); ++i)
|
||||||
|
{
|
||||||
|
if (i->id == id)
|
||||||
|
{
|
||||||
|
task = *i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Locate task by uuid.
|
||||||
|
bool TF2::get (const std::string& uuid, Task& task)
|
||||||
|
{
|
||||||
|
if (! _loaded_tasks)
|
||||||
|
load_tasks ();
|
||||||
|
|
||||||
|
std::vector <Task>::iterator i;
|
||||||
|
for (i = _tasks.begin (); i != _tasks.end (); ++i)
|
||||||
|
{
|
||||||
|
if (i->get ("uuid") == uuid)
|
||||||
|
{
|
||||||
|
task = *i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TF2::add_task (const Task& task)
|
void TF2::add_task (const Task& task)
|
||||||
{
|
{
|
||||||
|
@ -1632,75 +1672,19 @@ const std::vector <Task> TDB2::all_tasks ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Locate task by ID.
|
// Locate task by ID, wherever it is.
|
||||||
bool TDB2::get (int id, Task& task)
|
bool TDB2::get (int id, Task& task)
|
||||||
{
|
{
|
||||||
// First load and scan pending.
|
return pending.get (id, task) ||
|
||||||
if (! pending._loaded_tasks)
|
completed.get (id, task);
|
||||||
pending.load_tasks ();
|
|
||||||
|
|
||||||
std::vector <Task>::iterator i;
|
|
||||||
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
|
|
||||||
{
|
|
||||||
if (i->id == id)
|
|
||||||
{
|
|
||||||
task = *i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next load and scan completed.
|
|
||||||
// Note that this is harmless, because it is only performed if the above
|
|
||||||
// load and search fails.
|
|
||||||
if (! completed._loaded_tasks)
|
|
||||||
completed.load_tasks ();
|
|
||||||
|
|
||||||
for (i = completed._tasks.begin (); i != completed._tasks.end (); ++i)
|
|
||||||
{
|
|
||||||
if (i->id == id)
|
|
||||||
{
|
|
||||||
task = *i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Locate task by UUID.
|
// Locate task by UUID, wherever it is.
|
||||||
bool TDB2::get (const std::string& uuid, Task& task)
|
bool TDB2::get (const std::string& uuid, Task& task)
|
||||||
{
|
{
|
||||||
// First load and scan pending.
|
return pending.get (uuid, task) ||
|
||||||
if (! pending._loaded_tasks)
|
completed.get (uuid, task);
|
||||||
pending.load_tasks ();
|
|
||||||
|
|
||||||
std::vector <Task>::iterator i;
|
|
||||||
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
|
|
||||||
{
|
|
||||||
if (i->get ("uuid") == uuid)
|
|
||||||
{
|
|
||||||
task = *i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next load and scan completed.
|
|
||||||
// Note that this is harmless, because it is only performed if the above
|
|
||||||
// load and search fails.
|
|
||||||
if (! completed._loaded_tasks)
|
|
||||||
completed.load_tasks ();
|
|
||||||
|
|
||||||
for (i = completed._tasks.begin (); i != completed._tasks.end (); ++i)
|
|
||||||
{
|
|
||||||
if (i->get ("uuid") == uuid)
|
|
||||||
{
|
|
||||||
task = *i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
const std::vector <Task>& get_tasks ();
|
const std::vector <Task>& get_tasks ();
|
||||||
const std::vector <std::string>& get_lines ();
|
const std::vector <std::string>& get_lines ();
|
||||||
|
|
||||||
|
bool get (int, Task&);
|
||||||
|
bool get (const std::string&, Task&);
|
||||||
|
|
||||||
void add_task (const Task&);
|
void add_task (const Task&);
|
||||||
bool modify_task (const Task&);
|
bool modify_task (const Task&);
|
||||||
void add_line (const std::string&);
|
void add_line (const std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue