TDB2::siblings

- TDB2 helper function to locate sibling tasks.
This commit is contained in:
Paul Beckingham 2011-08-26 01:58:07 -04:00
parent 4f0276c062
commit e127f33e3a
2 changed files with 37 additions and 0 deletions

View file

@ -627,6 +627,42 @@ bool TDB2::get (const std::string& uuid, Task& task)
return false;
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task> TDB2::siblings (Task& task)
{
std::vector <Task> results;
if (task.has ("parent"))
{
std::string parent = task.get ("parent");
// 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)
{
// Do not include self in results.
if (i->id != task.id)
{
// Do not include completed or deleted tasks.
if (i->getStatus () != Task::completed &&
i->getStatus () != Task::deleted)
{
// If task has the same parent, it is a sibling.
if (i->has ("parent") &&
i->get ("parent") == parent)
{
results.push_back (*i);
}
}
}
}
}
return results;
}
////////////////////////////////////////////////////////////////////////////////
bool TDB2::verifyUniqueUUID (const std::string& uuid)
{

View file

@ -102,6 +102,7 @@ public:
// Generalized task accessors.
bool get (int, Task&);
bool get (const std::string&, Task&);
const std::vector <Task> siblings (Task&);
void dump ();