From 5f8b3cf989b0f55aae8dcc0f1ca88fd1aac6df6e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 23 Apr 2011 23:06:00 -0400 Subject: [PATCH] Code Cleanup - Further attemps at removing 'foreach'. --- src/Cmd.cpp | 15 +++++++++------ src/recur.cpp | 9 ++++++--- src/report.cpp | 37 +++++++++++++++++++++---------------- src/util.cpp | 3 ++- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/Cmd.cpp b/src/Cmd.cpp index ca1fd583d..e9762fd7d 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -185,7 +185,8 @@ void Cmd::load () std::vector all; context.config.all (all); - foreach (i, all) + std::vector ::iterator i; + for (i = all.begin (); i != all.end (); ++i) { if (i->substr (0, 7) == "report.") { @@ -209,8 +210,9 @@ void Cmd::load () } // Now load the aliases. - foreach (i, context.aliases) - commands.push_back (i->first); + std::map ::iterator it; + for (it = context.aliases.begin (); it != context.aliases.end (); ++it) + commands.push_back (it->first); } } @@ -224,9 +226,10 @@ void Cmd::allCustomReports (std::vector & all) const void Cmd::allCommands (std::vector & all) const { all.clear (); - foreach (command, commands) - if (command->substr (0, 1) != "_") - all.push_back (*command); + std::vector ::const_iterator c; + for (c = commands.begin (); c != commands.end (); ++c) + if (c->substr (0, 1) != "_") + all.push_back (*c); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/recur.cpp b/src/recur.cpp index ea872b99d..a81895181 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -59,7 +59,8 @@ void handleRecurrence () std::vector modified; // Look at all tasks and find any recurring ones. - foreach (t, tasks) + std::vector ::iterator t; + for (t = tasks.begin (); t != tasks.end (); ++t) { if (t->getStatus () == Task::recurring) { @@ -87,7 +88,8 @@ void handleRecurrence () // Iterate over the due dates, and check each against the mask. bool changed = false; unsigned int i = 0; - foreach (d, due) + std::vector ::iterator d; + for (d = due.begin (); d != due.end (); ++d) { if (mask.length () <= i) { @@ -453,7 +455,8 @@ bool nag (Task& task) char pri = ' '; // Scan all pending tasks. - foreach (t, tasks) + std::vector ::iterator t; + for (t = tasks.begin (); t != tasks.end (); ++t) { if (t->id == task.id) { diff --git a/src/report.cpp b/src/report.cpp index 4ce693fc7..7b7b4eb2d 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -400,7 +400,8 @@ int handleInfo (std::string& outs) // Find the task. std::stringstream out; - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { Table table; table.setTableWidth (context.getWidth ()); @@ -776,7 +777,8 @@ int handleReportSummary (std::string& outs) // Generate unique list of project names from all pending tasks. std::map allProjects; - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) if (task->getStatus () == Task::pending) allProjects[task->get ("project")] = false; @@ -797,7 +799,7 @@ int handleReportSummary (std::string& outs) } // Count the various tasks. - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { std::string project = task->get ("project"); ++counter[project]; @@ -984,7 +986,8 @@ int handleReportTimesheet (std::string& outs) completed.setColumnJustification (2, Table::right); completed.setColumnJustification (3, Table::left); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { // If task completed within range. if (task->getStatus () == Task::completed) @@ -1042,7 +1045,7 @@ int handleReportTimesheet (std::string& outs) started.setColumnJustification (1, Table::left); started.setColumnJustification (2, Table::right); started.setColumnJustification (3, Table::left); - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { // If task started within range, but not completed withing range. if (task->getStatus () == Task::pending && @@ -1443,7 +1446,8 @@ int handleReportCalendar (std::string& outs) if (getpendingdate == true) { // Find the oldest pending due date. Date oldest (12,31,2037); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->getStatus () == Task::pending) { @@ -1931,7 +1935,8 @@ void gatherNextTasks (std::vector & tasks) int limit = context.config.getInteger ("next"); // due:< 1wk, pri:* - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->has ("due")) { @@ -1950,7 +1955,7 @@ void gatherNextTasks (std::vector & tasks) } // blocking, not blocked - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { if (dependencyIsBlocking (*task) && ! dependencyIsBlocked (*task)) @@ -1966,7 +1971,7 @@ void gatherNextTasks (std::vector & tasks) } // due:*, pri:H - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->has ("due")) { @@ -1985,7 +1990,7 @@ void gatherNextTasks (std::vector & tasks) } // pri:H - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { std::string priority = task->get ("priority"); if (priority == "H") @@ -2001,7 +2006,7 @@ void gatherNextTasks (std::vector & tasks) } // due:*, pri:M - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->has ("due")) { @@ -2020,7 +2025,7 @@ void gatherNextTasks (std::vector & tasks) } // pri:M - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { std::string priority = task->get ("priority"); if (priority == "M") @@ -2036,7 +2041,7 @@ void gatherNextTasks (std::vector & tasks) } // due:*, pri:L - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->has ("due")) { @@ -2055,7 +2060,7 @@ void gatherNextTasks (std::vector & tasks) } // pri:L - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { std::string priority = task->get ("priority"); if (priority == "L") @@ -2071,7 +2076,7 @@ void gatherNextTasks (std::vector & tasks) } // due:, pri: - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { if (task->has ("due")) { @@ -2090,7 +2095,7 @@ void gatherNextTasks (std::vector & tasks) } // Filler. - foreach (task, tasks) + for (task = tasks.begin (); task != tasks.end (); ++task) { std::string project = task->get ("project"); if (countByProject[project] < limit && matching.find (task->id) == matching.end ()) diff --git a/src/util.cpp b/src/util.cpp index 302d17427..dbed968a3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -189,7 +189,8 @@ int autoComplete ( unsigned int length = partial.length (); if (length) { - foreach (item, list) + std::vector ::const_iterator item; + for (item = list.begin (); item != list.end (); ++item) { // An exact match is a special case. Assume there is only one exact match // and return immediately.