From 1058f045b01b7db8d44ba1c044d68a891487dd7e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 10 Sep 2014 22:54:17 -0400 Subject: [PATCH] TDB2 - Added ::has methods to determine whether a UUID is known. --- src/TDB2.cpp | 25 ++++++++++++++++++++++--- src/TDB2.h | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index c957e7b72..a1a76e61b 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -134,6 +134,20 @@ bool TF2::get (const std::string& uuid, Task& task) return false; } +//////////////////////////////////////////////////////////////////////////////// +bool TF2::has (const std::string& uuid) +{ + if (! _loaded_tasks) + load_tasks (); + + std::vector ::iterator i; + for (i = _tasks.begin (); i != _tasks.end (); ++i) + if (i->get ("uuid") == uuid) + return true; + + return false; +} + //////////////////////////////////////////////////////////////////////////////// void TF2::add_task (Task& task) { @@ -589,9 +603,6 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */) // Ensure the task is consistent, and provide defaults if necessary. task.validate (false); - // All modified tasks are timestamped. - task.setModified (); - // Find task, overwrite it. Task original; get (task.get ("uuid"), original); @@ -1287,6 +1298,14 @@ bool TDB2::get (const std::string& uuid, Task& task) completed.get (uuid, task); } +//////////////////////////////////////////////////////////////////////////////// +// Locate task by UUID, wherever it is. +bool TDB2::has (const std::string& uuid) +{ + return pending.has (uuid) || + completed.has (uuid); +} + //////////////////////////////////////////////////////////////////////////////// const std::vector TDB2::siblings (Task& task) { diff --git a/src/TDB2.h b/src/TDB2.h index 3071fab72..20ead02f7 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -49,6 +49,7 @@ public: bool get (int, Task&); bool get (const std::string&, Task&); + bool has (const std::string&); void add_task (Task&); bool modify_task (const Task&); @@ -110,6 +111,7 @@ public: const std::vector all_tasks (); bool get (int, Task&); bool get (const std::string&, Task&); + bool has (const std::string&); const std::vector siblings (Task&); const std::vector children (Task&);