From e127f33e3af6ce5b93deba251b68dbd0189cc6d2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 26 Aug 2011 01:58:07 -0400 Subject: [PATCH] TDB2::siblings - TDB2 helper function to locate sibling tasks. --- src/TDB2.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/TDB2.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 54be1cf3f..a7bd92b0a 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -627,6 +627,42 @@ bool TDB2::get (const std::string& uuid, Task& task) return false; } +//////////////////////////////////////////////////////////////////////////////// +const std::vector TDB2::siblings (Task& task) +{ + std::vector 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 ::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) { diff --git a/src/TDB2.h b/src/TDB2.h index 34a70d37a..db03dd23c 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -102,6 +102,7 @@ public: // Generalized task accessors. bool get (int, Task&); bool get (const std::string&, Task&); + const std::vector siblings (Task&); void dump ();