Code Cleanup

- Further attemps at removing 'foreach'.
This commit is contained in:
Paul Beckingham 2011-04-23 23:06:00 -04:00
parent 10e3f306dd
commit 5f8b3cf989
4 changed files with 38 additions and 26 deletions

View file

@ -185,7 +185,8 @@ void Cmd::load ()
std::vector <std::string> all;
context.config.all (all);
foreach (i, all)
std::vector <std::string>::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 <std::string, std::string>::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 <std::string>& all) const
void Cmd::allCommands (std::vector <std::string>& all) const
{
all.clear ();
foreach (command, commands)
if (command->substr (0, 1) != "_")
all.push_back (*command);
std::vector <std::string>::const_iterator c;
for (c = commands.begin (); c != commands.end (); ++c)
if (c->substr (0, 1) != "_")
all.push_back (*c);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -59,7 +59,8 @@ void handleRecurrence ()
std::vector <Task> modified;
// Look at all tasks and find any recurring ones.
foreach (t, tasks)
std::vector <Task>::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 <Date>::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 <Task>::iterator t;
for (t = tasks.begin (); t != tasks.end (); ++t)
{
if (t->id == task.id)
{

View file

@ -400,7 +400,8 @@ int handleInfo (std::string& outs)
// Find the task.
std::stringstream out;
foreach (task, tasks)
std::vector <Task>::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 <std::string, bool> allProjects;
foreach (task, tasks)
std::vector <Task>::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 <Task>::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 <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
if (task->getStatus () == Task::pending)
{
@ -1931,7 +1935,8 @@ void gatherNextTasks (std::vector <Task>& tasks)
int limit = context.config.getInteger ("next");
// due:< 1wk, pri:*
foreach (task, tasks)
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
if (task->has ("due"))
{
@ -1950,7 +1955,7 @@ void gatherNextTasks (std::vector <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 <Task>& 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 ())

View file

@ -189,7 +189,8 @@ int autoComplete (
unsigned int length = partial.length ();
if (length)
{
foreach (item, list)
std::vector <std::string>::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.