From d59aaa642785915c426378f98dca4af405d6cdef Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 8 Jul 2012 16:04:34 -0400 Subject: [PATCH] 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. --- src/TDB2.cpp | 108 ++++++++++++++++++++++----------------------------- src/TDB2.h | 3 ++ 2 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 240ab088a..6311a2617 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -104,6 +104,46 @@ const std::vector & TF2::get_lines () return _lines; } +//////////////////////////////////////////////////////////////////////////////// +// Locate task by id. +bool TF2::get (int id, Task& task) +{ + if (! _loaded_tasks) + load_tasks (); + + std::vector ::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 ::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 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 ::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 ::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); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/TDB2.h b/src/TDB2.h index cf965eae9..e94beef74 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -49,6 +49,9 @@ public: const std::vector & get_tasks (); const std::vector & 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&);