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:
108
src/TDB2.cpp
108
src/TDB2.cpp
@@ -104,6 +104,46 @@ const std::vector <std::string>& TF2::get_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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
// First load and scan pending.
|
||||
if (! pending._loaded_tasks)
|
||||
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;
|
||||
return pending.get (id, task) ||
|
||||
completed.get (id, task);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Locate task by UUID.
|
||||
// Locate task by UUID, wherever it is.
|
||||
bool TDB2::get (const std::string& uuid, Task& task)
|
||||
{
|
||||
// First load and scan pending.
|
||||
if (! pending._loaded_tasks)
|
||||
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;
|
||||
return pending.get (uuid, task) ||
|
||||
completed.get (uuid, task);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
const std::vector <Task>& get_tasks ();
|
||||
const std::vector <std::string>& get_lines ();
|
||||
|
||||
bool get (int, Task&);
|
||||
bool get (const std::string&, Task&);
|
||||
|
||||
void add_task (const Task&);
|
||||
bool modify_task (const Task&);
|
||||
void add_line (const std::string&);
|
||||
|
||||
Reference in New Issue
Block a user