From 56bc5cf7553e0cc2dd6b7fd438f31577d14241be Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 11 Jun 2011 15:15:47 -0400 Subject: [PATCH] Code Cleanup - Removed the last uses of 'foreach'. What remains is only code that is being obsoleted, and therefore there is no need to clean that up. - The definition of 'foreach' in util.h must remain until last. --- src/TDB2.cpp | 1 + src/dependency.cpp | 25 ++++++++++++++++--------- src/feedback.cpp | 32 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 03830bfea..f8b8f2f89 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -442,6 +442,7 @@ void TDB::lock (bool lockFile /* = true */) mCompleted.clear (); mModified.clear (); + foreach (location, mLocations) { location->pending = openAndLock (location->path + "/pending.data"); diff --git a/src/dependency.cpp b/src/dependency.cpp index bba1d74e6..5d8f95810 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -134,7 +134,8 @@ static bool followUpstream ( { std::vector blocking; dependencyGetBlocking (task, blocking); - foreach (b, blocking) + std::vector ::iterator b; + for (b = blocking.begin (); b != blocking.end (); ++b) { std::string link = task.get ("uuid") + " -> " + b->get ("uuid"); @@ -200,7 +201,8 @@ void dependencyChainOnComplete (Task& task) if (context.config.getBoolean ("dependency.reminder")) { std::cout << "Task " << task.id << " is blocked by:\n"; - foreach (b, blocking) + std::vector ::iterator b; + for (b = blocking.begin (); b != blocking.end (); ++b) std::cout << " " << b->id << " " << b->get ("description") << "\n"; } @@ -210,7 +212,8 @@ void dependencyChainOnComplete (Task& task) if (context.config.getBoolean ("dependency.reminder")) { std::cout << "and is blocking:\n"; - foreach (b, blocked) + std::vector ::iterator b; + for (b = blocked.begin (); b != blocked.end (); ++b) std::cout << " " << b->id << " " << b->get ("description") << "\n"; } @@ -219,19 +222,21 @@ void dependencyChainOnComplete (Task& task) { // Repair the chain - everything in blocked should now depend on // everything in blocking, instead of task.id. - foreach (left, blocked) + std::vector ::iterator left; + std::vector ::iterator right; + for (left = blocked.begin (); left != blocked.end (); ++left) { left->removeDependency (task.id); - foreach (right, blocking) + for (right = blocking.begin (); right != blocking.end (); ++right) left->addDependency (right->id); } // Now update TDB, now that the updates have all occurred. - foreach (left, blocked) + for (left = blocked.begin (); left != blocked.end (); ++left) context.tdb.update (*left); - foreach (right, blocking) + for (right = blocking.begin (); right != blocking.end (); ++right) context.tdb.update (*right); } } @@ -251,7 +256,8 @@ void dependencyChainOnStart (Task& task) if (blocking.size ()) { std::cout << "Task " << task.id << " is blocked by:\n"; - foreach (b, blocking) + std::vector ::iterator b; + for (b = blocking.begin (); b != blocking.end (); ++b) std::cout << " " << b->id << " " << b->get ("description") << "\n"; } } @@ -293,7 +299,8 @@ void dependencyChainOnModify (Task& before, Task& after) std::vector blocked; dependencyGetBlocked (after, blocked); - foreach (b, blocked) + std::vector ::iterator b; + for (b = blocked.begin (); b != blocked.end (); ++b) { std::cout << "# dependencyChainOnModify\n"; } diff --git a/src/feedback.cpp b/src/feedback.cpp index 572ec257c..4a320d7b8 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -45,11 +45,12 @@ bool taskDiff (const Task& before, const Task& after) // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - foreach (att, before) + std::map ::const_iterator att; + for (att = before.begin (); att != before.end (); ++att) beforeAtts.push_back (att->first); std::vector afterAtts; - foreach (att, after) + for (att = after.begin (); att != after.end (); ++att) afterAtts.push_back (att->first); std::vector beforeOnly; @@ -60,7 +61,8 @@ bool taskDiff (const Task& before, const Task& after) afterOnly.size ()) return true; - foreach (name, beforeAtts) + std::vector ::iterator name; + for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) if (*name != "uuid" && before.get (*name) != after.get (*name)) return true; @@ -74,11 +76,12 @@ std::string taskDifferences (const Task& before, const Task& after) // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - foreach (att, before) + std::map ::const_iterator att; + for (att = before.begin (); att != before.end (); ++att) beforeAtts.push_back (att->first); std::vector afterAtts; - foreach (att, after) + for (att = after.begin (); att != after.end (); ++att) afterAtts.push_back (att->first); std::vector beforeOnly; @@ -87,12 +90,13 @@ std::string taskDifferences (const Task& before, const Task& after) // Now start generating a description of the differences. std::stringstream out; - foreach (name, beforeOnly) + std::vector ::iterator name; + for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name) out << " - " << ucFirst(*name) << " will be deleted.\n"; - foreach (name, afterOnly) + for (name = afterOnly.begin (); name != afterOnly.end (); ++name) { if (*name == "depends") { @@ -115,7 +119,7 @@ std::string taskDifferences (const Task& before, const Task& after) << "'.\n"; } - foreach (name, beforeAtts) + for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) if (*name != "uuid" && before.get (*name) != after.get (*name)) { @@ -162,11 +166,12 @@ std::string taskInfoDifferences (const Task& before, const Task& after) // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - foreach (att, before) + std::map ::const_iterator att; + for (att = before.begin (); att != before.end (); ++att) beforeAtts.push_back (att->first); std::vector afterAtts; - foreach (att, after) + for (att = after.begin (); att != after.end (); ++att) afterAtts.push_back (att->first); std::vector beforeOnly; @@ -175,7 +180,8 @@ std::string taskInfoDifferences (const Task& before, const Task& after) // Now start generating a description of the differences. std::stringstream out; - foreach (name, beforeOnly) + std::vector ::iterator name; + for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name) { if (*name == "depends") { @@ -201,7 +207,7 @@ std::string taskInfoDifferences (const Task& before, const Task& after) } } - foreach (name, afterOnly) + for (name = afterOnly.begin (); name != afterOnly.end (); ++name) { if (*name == "depends") { @@ -228,7 +234,7 @@ std::string taskInfoDifferences (const Task& before, const Task& after) << "'.\n"; } - foreach (name, beforeAtts) + for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) if (*name != "uuid" && before.get (*name) != after.get (*name) && before.get (*name) != "" && after.get (*name) != "")