mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
TDB2::siblings
- TDB2 helper function to locate sibling tasks.
This commit is contained in:
parent
4f0276c062
commit
e127f33e3a
2 changed files with 37 additions and 0 deletions
36
src/TDB2.cpp
36
src/TDB2.cpp
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 ();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue