diff --git a/src/TDB2.cpp b/src/TDB2.cpp index ac7ab591d..a979d23e9 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -254,6 +254,15 @@ void TF2::load_tasks () // TODO Find a way to number pending tasks, but not others. // task.id = _id++; _tasks.push_back (task); + + // Maintain mapping for ease of link/dependency resolution. + // Note that this mapping is not restricted by the filter, and is + // therefore a complete set. + if (task.id) + { + _I2U[task.id] = task.get ("uuid"); + _U2I[task.get ("uuid")] = task.id; + } } _loaded_tasks = true; @@ -306,6 +315,32 @@ void TF2::load_contents () } //////////////////////////////////////////////////////////////////////////////// +std::string TF2::uuid (int id) +{ + if (! _loaded_tasks) + load_tasks (); + + std::map ::const_iterator i; + if ((i = _I2U.find (id)) != _I2U.end ()) + return i->second; + + return ""; +} + +//////////////////////////////////////////////////////////////////////////////// +int TF2::id (const std::string& uuid) +{ + if (! _loaded_tasks) + load_tasks (); + + std::map ::const_iterator i; + if ((i = _U2I.find (uuid)) != _U2I.end ()) + return i->second; + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/TDB2.h b/src/TDB2.h index 332e16501..6fc1e9eae 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -59,6 +59,9 @@ public: void load_lines (); void load_contents (); + std::string uuid (int); + int id (const std::string&); + public: bool _read_only; bool _dirty; @@ -72,6 +75,10 @@ public: std::vector _added_lines; std::string _contents; File _file; + +private: + std::map _I2U; // ID -> UUID map + std::map _U2I; // UUID -> ID map }; // TDB2 Class represents all the files in the task database. diff --git a/src/Task.cpp b/src/Task.cpp index e30c4ce4d..40f33b90b 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -794,7 +794,7 @@ void Task::addDependency (int id) throw std::string (STRING_TASK_DEPEND_ITSELF); // Check for extant dependency. - std::string uuid = context.tdb.uuid (id); + std::string uuid = context.tdb2.pending.uuid (id); if (uuid == "") throw format (STRING_TASK_DEPEND_MISSING, id); @@ -839,7 +839,7 @@ void Task::removeDependency (const std::string& uuid) //////////////////////////////////////////////////////////////////////////////// void Task::removeDependency (int id) { - std::string uuid = context.tdb.uuid (id); + std::string uuid = context.tdb2.pending.uuid (id); if (uuid != "") removeDependency (uuid); else @@ -858,7 +858,7 @@ void Task::getDependencies (std::vector & all) const std::vector ::iterator i; for (i = deps.begin (); i != deps.end (); ++i) - all.push_back (context.tdb.id (*i)); + all.push_back (context.tdb2.pending.id (*i)); } ////////////////////////////////////////////////////////////////////////////////