From 1687e8533534cf4dbbdea0e1efcb50273e8c4898 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 4 Aug 2010 00:55:08 -0400 Subject: [PATCH] Dependencies - Implemented/stubbed some of the dependency helper functions. --- src/dependency.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++--- src/main.h | 5 +++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/dependency.cpp b/src/dependency.cpp index b19ea7a9d..532a01b33 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -29,14 +29,55 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// -// bool dependencyCheckCircular (); // void dependencyCheckDangling (); -// bool dependencyIsBlocked (); -// bool dependencyIsBlocking (); // bool dependencyRepairNeeded (); // void dependencyRepairChain (); // bool dependencyRepairConfirm (); // void dependencyNag (); //////////////////////////////////////////////////////////////////////////////// +// All it takes to be blocked is to depend on another task. +bool dependencyIsBlocked (Task& task) +{ + return task.has ("depends"); +} +//////////////////////////////////////////////////////////////////////////////// +// To be a blocking task, there must be at least one other task that depends on +// this task, that is either pending or waiting. +bool dependencyIsBlocking (Task& task) +{ + std::string uuid = task.get ("uuid"); + + const std::vector & all = context.tdb.getAllPending (); + std::vector ::const_iterator it; + for (it = all.begin (); it != all.end (); ++it) + if ((it->getStatus () == Task::pending || + it->getStatus () == Task::waiting) && + it->has ("depends") && + it->get ("depends").find (uuid) != std::string::npos) + return true; + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// Follow each of the given task's dependencies to the end of the chain, and if +// any duplicates show up, or the chain length exceeds N, stop. +bool dependencyCheckCircular (Task& task) +{ + int maximum = 100; + std::vector all; + + // Must include self if checking for circular. + all.push_back (task.get ("uuid")); + + // TODO foreach dependency + // TODO is uuid in all? + // TODO y: circular! + // TODO n: add uuid to all. + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index bd5b89aab..b594afdb5 100644 --- a/src/main.h +++ b/src/main.h @@ -130,6 +130,11 @@ int handleExportCSV (std::string &); int handleExportiCal (std::string &); int handleExportYAML (std::string &); +// dependency.cpp +bool dependencyIsBlocked (Task&); +bool dependencyIsBlocking (Task&); +bool dependencyCheckCircular (Task&); + // list template /////////////////////////////////////////////////////////////////////////////// template bool listDiff (const T& left, const T& right)